Skip to content

Instantly share code, notes, and snippets.

@tiffany-taylor
Created May 18, 2022 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiffany-taylor/5ed553c1efd7c4cdf3ca19a8ddbf18cd to your computer and use it in GitHub Desktop.
Save tiffany-taylor/5ed553c1efd7c4cdf3ca19a8ddbf18cd to your computer and use it in GitHub Desktop.
<?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