b0y-101 Mini Shell


Current Path : E:/www/b-group.old/spfin/mainpay/guzzle/tests/
File Upload :
Current File : E:/www/b-group.old/spfin/mainpay/guzzle/tests/Helpers.php

<?php

namespace GuzzleHttp\Tests;

class Helpers
{
    public static function readObjectAttribute(object $object, string $attributeName)
    {
        $reflector = new \ReflectionObject($object);

        do {
            try {
                $attribute = $reflector->getProperty($attributeName);

                if (!$attribute || $attribute->isPublic()) {
                    return $object->$attributeName;
                }

                $attribute->setAccessible(true);

                try {
                    return $attribute->getValue($object);
                } finally {
                    $attribute->setAccessible(false);
                }
            } catch (\ReflectionException $e) {
                // do nothing
            }
        } while ($reflector = $reflector->getParentClass());

        throw new \Exception(
            sprintf('Attribute "%s" not found in object.', $attributeName)
        );
    }
}

Copyright © 2019 by b0y-101