-
-
Save tiffany-taylor/5ed553c1efd7c4cdf3ca19a8ddbf18cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// something I wrote a month or so ago to test something with guzzle... | |
// I forget exactly what I was testing, but I was told to use Reflection... | |
$reflection = new ReflectionObject($sdk); | |
$baseUriProperty = $reflection->getConstant('BASE_URI'); | |
$guzzle = clone $reflection->getProperty('httpClient')->getValue($sdk); | |
$guzzleReflection = new ReflectionObject($guzzle); | |
$guzzleConfig = $guzzleReflection->getProperty('config')->getValue($guzzle); | |
$baseUriReflection = new ReflectionObject($guzzleConfig['base_uri']); | |
$guzzleBaseUri = $baseUriReflection->getProperty('scheme')->getValue($guzzleConfig['base_uri']) . '://' | |
. $baseUriReflection->getProperty('userInfo')->getValue($guzzleConfig['base_uri']) | |
. $baseUriReflection->getProperty('host')->getValue($guzzleConfig['base_uri']) | |
. $baseUriReflection->getProperty('port')->getValue($guzzleConfig['base_uri']) | |
. $baseUriReflection->getProperty('path')->getValue($guzzleConfig['base_uri']) | |
; | |
var_dump(assert($baseUriProperty === $guzzleBaseUri)); // bool(true) | |
// then tried doing something like this ... | |
$properties = array_map( | |
function (ReflectionProperty $property) use ($baseUriReflection, $guzzleConfig) { | |
$array = []; | |
$array[$property->getName()] = $baseUriReflection->getProperty($property->getName())->getValue($guzzleConfig['base_uri']); | |
return $array; | |
}, $baseUriReflection->getProperties()); | |
foreach ($properties as $property) { | |
var_dump($property); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment