public function isEmpty() { //testing attributes, the easier place to find something foreach ($this->attributes as $attr) { if (!empty($attr)) { return false; } } //if didn't returned, let's try custom properties $obj = new ReflectionObject($this); foreach ($obj->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { if ($property->getDeclaringClass()->name == $obj->name) { $value = $property->getValue($this); if (!empty($value)) { return false; } } } //nothing? so, trying getters foreach ($obj->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($method->getDeclaringClass()->name == $obj->name && strpos($method->name, 'get') === 0 && $method->getNumberOfRequiredParameters() == 0) { $value = $method->invoke($this); if (!empty($value)) { return false; } } } return true; }
/** * {@inheritdoc} */ public function normalize($object, $format = null, array $context = array()) { $reflectionObject = new \ReflectionObject($object); $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); $attributes = array(); foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { $attributeName = lcfirst(substr($method->name, 3)); if (in_array($attributeName, $this->ignoredAttributes)) { continue; } $attributeValue = $method->invoke($object); if (array_key_exists($attributeName, $this->callbacks)) { $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { if (!$this->serializer instanceof NormalizerInterface) { throw new \LogicException(sprintf('Cannot normalize attribute "%s" because injected serializer is not a normalizer', $attributeName)); } $attributeValue = $this->serializer->normalize($attributeValue, $format); } $attributes[$attributeName] = $attributeValue; } } return $attributes; }
public function __call($name, $arguments) { $prefix = DependencyInjectionStorage::getInstance()->getPrefix(); if (substr($name, 0, strlen($prefix)) == $prefix) { $originalMethodName = substr($name, strlen($prefix)); $r = new \ReflectionObject($this); $methods = $r->getMethods(\ReflectionMethod::IS_PUBLIC); for ($i = 0; $i < count($methods); $i++) { if ($methods[$i]->name == $originalMethodName) { break; } } if ($i < count($methods)) { $pars = $methods[$i]->getParameters(); $call_parameters = $arguments; for ($i = count($arguments); $i < count($pars); $i++) { if ($par_class = $pars[$i]->getClass()) { if (is_null($call_parameters[$i] = DependencyInjectionStorage::getInstance()->getRegisteredInstance($par_class->name))) { throw new EDINoInstanceInjected('No registered class ' . $par_class->name . ' in call to ' . $name); } } else { throw new EDINoTypeHint('Unable to provide ' . $i . 'th parameter in call to ' . $name . ', it`s type hint undefined'); } } return call_user_func_array(array($this, $originalMethodName), $call_parameters); } else { throw new EDINoOriginalMethod('Can`t find original method ' . $originalMethodName . ' in call to ' . $name); } } else { throw new \Exception('Call to undefined method ' . $name); } }
/** * Constructor * * @param \Chainnn\Chainable|object $object * @param \Chainnn\ChainOfCommand|array $chainOfCommand * * @throws \Chainnn\Exception\RuntimeException */ public function __construct($object, $chainOfCommand = null) { if (!is_object($object)) { throw new RuntimeException('Requires type object, got' . gettype($object)); } $this->object = $object; $this->methodList = array(); $reflection = new \ReflectionObject($object); foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { $isMagic = preg_match('/^_{2}/', $method->getName()); $chainableMethod = $method->getName() == 'getChainOfCommand'; if (!$isMagic && !$chainableMethod) { $this->methodList[$method->getName()] = $method; } } if (null === $chainOfCommand) { if ($this->object instanceof Chainable) { $chainOfCommand = $this->object->getChainOfCommand(); } } if (is_array($chainOfCommand)) { $chainOfCommand = ChainOfCommand::createFromArrayMap($chainOfCommand); } if (!$chainOfCommand instanceof ChainOfCommand) { throw new RuntimeException('Could not set a chain of command.'); } $this->chainOfCommand = $chainOfCommand; }
/** * @param string|object $object * @return multitype: */ public static function getControllerResources($controller) { $front = JO_Front::getInstance(); $controller_name = $front->formatControllerName($controller); if ($front->isDispatchable($controller)) { JO_Loader::setIncludePaths(array($front->getDispatchDirectory())); JO_Loader::loadFile($front->classToFilename($controller_name), null, true); if (version_compare(PHP_VERSION, '5.2.6') === -1) { $class = new ReflectionObject(new $controller_name()); $classMethods = $class->getMethods(); $methodNames = array(); foreach ($classMethods as $method) { $methodNames[] = $method->getName(); } } else { $methodNames = get_class_methods(new $controller_name()); } $_classResources = array(); foreach ($methodNames as $method) { if (6 < strlen($method) && 'Action' === substr($method, -6)) { $_classResources[substr($method, 0, -6)] = substr($method, 0, -6); } } return $_classResources; } return array(); }
/** * {@inheritdoc} * * @throws LogicException * @throws CircularReferenceException */ public function normalize($object, $format = null, array $context = array()) { if ($this->isCircularReference($object, $context)) { return $this->handleCircularReference($object); } $reflectionObject = new \ReflectionObject($object); $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); $allowedAttributes = $this->getAllowedAttributes($object, $context, true); $attributes = array(); foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { $attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3)); if (in_array($attributeName, $this->ignoredAttributes)) { continue; } if (false !== $allowedAttributes && !in_array($attributeName, $allowedAttributes)) { continue; } $attributeValue = $method->invoke($object); if (isset($this->callbacks[$attributeName])) { $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue); } if (is_object($attributeValue)) { $class = get_class($attributeValue); $this->normalize($attributeName, $format, $context); } if (null !== $attributeValue && !is_scalar($attributeValue)) { $attributeValue = $this->serializer->normalize($attributeValue, $format, $context); } $attributes[$attributeName] = $attributeValue; } } return $attributes; }
/** * Runs the test case. * @return void */ public function run($method = NULL) { $r = new \ReflectionObject($this); $methods = array_values(preg_grep(self::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm) { return $rm->getName(); }, $r->getMethods()))); if (($method === NULL || $method === self::LIST_METHODS) && isset($_SERVER['argv'][1])) { if ($_SERVER['argv'][1] === self::LIST_METHODS) { Environment::$checkAssertions = FALSE; header('Content-Type: application/json'); echo json_encode($methods); return; } $method = $_SERVER['argv'][1]; } if ($method === NULL) { foreach ($methods as $method) { $this->runMethod($method); } } elseif (in_array($method, $methods)) { $this->runMethod($method); } else { throw new TestCaseException("Method '{$method}' does not exist or it is not a testing method."); } }
/** * {@inheritdoc} */ public function normalize($object, $format, $properties = null) { $propertyMap = (null === $properties) ? null : array_flip(array_map('strtolower', $properties)); $reflectionObject = new \ReflectionObject($object); $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); $attributes = array(); foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { $attributeName = strtolower(substr($method->getName(), 3)); if (null === $propertyMap || isset($propertyMap[$attributeName])) { $attributeValue = $method->invoke($object); if ($this->serializer->isStructuredType($attributeValue)) { $attributeValue = $this->serializer->normalize($attributeValue, $format); } $attributes[$attributeName] = $attributeValue; } } } return $attributes; }
/** * Defines all required functions and constants * * @see _define() * @return void */ public function checkAPI() { // The constants are defined. $this->_define('T_NAMESPACE'); $this->_define('T_NS_SEPARATOR'); $this->_define('E_USER_DEPRECATED', E_USER_WARNING); /* * Every static public method with an @implement annotation defines * a function. */ $reflectionObject = new ReflectionObject($this); $methods = $reflectionObject->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { // The method comment is parsed for the @implement annotation $isAnnotated = preg_match('/\\s*\\*\\s*@implement\\s+(\\S+)/', $method->getDocComment(), $matches); if (!$isAnnotated) { continue; } $function = $matches[1]; // A function might already exist. if (function_exists($function)) { continue; } // The parameters are build. $parametersArray = array(); for ($i = 0; $i < $method->getNumberOfParameters(); $i++) { $parametersArray[] = '$parameter' . $i; } $parameters = implode(', ', $parametersArray); // The function is defined. $apiClass = get_class($this); $definition = "function {$function}({$parameters})\n {\n \$parameters = func_get_args();\n return call_user_func_array(\n array('{$apiClass}', '{$method->getName()}'),\n \$parameters\n );\n }\n "; eval($definition); } }
/** * Runs the test case. * @return void */ public function run($method = NULL) { $r = new \ReflectionObject($this); $methods = array_values(preg_grep(self::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm) { return $rm->getName(); }, $r->getMethods()))); if (substr($method, 0, 2) === '--') { // back compatibility $method = NULL; } if ($method === NULL && isset($_SERVER['argv']) && ($tmp = preg_filter('#(--method=)?([\\w-]+)$#Ai', '$2', $_SERVER['argv']))) { $method = reset($tmp); if ($method === self::LIST_METHODS) { Environment::$checkAssertions = FALSE; header('Content-Type: text/plain'); echo '[' . implode(',', $methods) . ']'; return; } } if ($method === NULL) { foreach ($methods as $method) { $this->runMethod($method); } } elseif (in_array($method, $methods, TRUE)) { $this->runMethod($method); } else { throw new TestCaseException("Method '{$method}' does not exist or it is not a testing method."); } }
/** * {@inheritdoc} */ public function normalize($object, $format = null) { $reflectionObject = new \ReflectionObject($object); $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); $attributes = array(); foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { $attributeName = lcfirst(substr($method->name, 3)); if (in_array($attributeName, $this->ignoredAttributes)) { continue; } $attributeValue = $method->invoke($object); if (array_key_exists($attributeName, $this->callbacks)) { $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { $attributeValue = $this->serializer->normalize($attributeValue, $format); } $attributes[$attributeName] = $attributeValue; } } return $attributes; }
public function getFormatters() { $formatters = array(); foreach ($this->generator->getProviders() as $provider) { $providerClass = get_class($provider); $formatters[$providerClass] = array(); $refl = new \ReflectionObject($provider); foreach ($refl->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflmethod) { $methodName = $reflmethod->name; if ($methodName == '__construct') { continue; } $parameters = array(); foreach ($reflmethod->getParameters() as $reflparameter) { $parameter = '$' . $reflparameter->getName(); if ($reflparameter->isDefaultValueAvailable()) { $parameter .= ' = ' . var_export($reflparameter->getDefaultValue(), true); } $parameters[] = $parameter; } $parameters = $parameters ? '(' . join(', ', $parameters) . ')' : ''; $example = $this->generator->format($methodName); if (is_array($example)) { $example = "array('" . join("', '", $example) . "')"; } elseif ($example instanceof \DateTime) { $example = "DateTime('" . $example->format('Y-m-d H:i:s') . "')"; } elseif (is_string($example)) { $example = var_export($example, true); } $formatters[$providerClass][$methodName . $parameters] = $example; } } return $formatters; }
/** * @param $object * @return array */ public function extract($object) { $reflection = new \ReflectionObject($object); $values = []; // filters static methods $staticMethods = array_map(function ($method) { return $method->getName(); }, $reflection->getMethods(\ReflectionMethod::IS_STATIC)); foreach ($reflection->getMethods() as $method) { if (strpos($method->getName(), self::METHOD_GETTER) === 0 && !in_array($method->getName(), $staticMethods)) { $name = lcfirst(preg_replace('/' . self::METHOD_GETTER . '/', '', $method->getName(), 1)); $name = $this->namingStrategy ? $this->namingStrategy->convert($name) : $name; $values[$name] = $method->invoke($object); } } return $values; }
protected function getActionMethods() { $self = new \ReflectionObject($this); return array_map(function ($method) { return $method->getName(); }, array_filter($self->getMethods(), function ($method) { return preg_match('/Action$/', $method->getName()); })); }
/** * Convert an object using the getter of this one, and if it has some foreign relationship, we use also the id of the foreign objects * * @param unknown $object The object to convert * @param string $format Not used here, keeped for compatibility * @param array $context Not used here, keeped for compatibility * * @return multitype:multitype:multitype:mixed */ public function normalize($object, $format = null, array $context = array()) { $reflectionObject = new \ReflectionObject($object); $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); $attributes = array(); foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { $attributeName = lcfirst(substr($method->name, 3)); //we sub the set or get if (in_array($attributeName, $this->ignoredAttributes)) { continue; } $attributeValue = $method->invoke($object); if (array_key_exists($attributeName, $this->callbacks)) { $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { if (get_class($attributeValue) == 'Doctrine\\ORM\\PersistentCollection') { //memorize the list of persistent collections $attributeValues = $attributeValue; $attributeValue = array(); foreach ($attributeValues as $obj) { $attributeReflectionObject = new \ReflectionObject($obj); $identifiers = $this->doctrine->getManager()->getMetadataFactory()->getMetadataFor($attributeReflectionObject->getName())->getIdentifier(); //the ids to add $tempAttribute = array(); foreach ($identifiers as $identifier) { $attribute = call_user_func(array($obj, 'get' . ucfirst($identifier))); //the attribute is itself an object if (is_object($attribute)) { //we look for the ids $attributeIdentifierReflectionObject = new \ReflectionObject($attribute); $attributeIdentifiers = $this->doctrine->getManager()->getMetadataFactory()->getMetadataFor($attributeIdentifierReflectionObject->getName())->getIdentifier(); foreach ($attributeIdentifiers as $index => $attributeIdentifier) { $attributeIdentifierAttribute = call_user_func(array($attribute, 'get' . ucfirst($attributeIdentifier))); //@todo use reflection to know the identifier //we add each of the ids $tempAttribute[$identifier] = $attributeIdentifierAttribute; } } else { //we memorise the array of ids $tempAttribute[$identifier] = $attribute; } } //we add the id to the array of the attribute $attributeValue[] = $tempAttribute; } } else { $attributeValue = $attributeValue->getId(); //@todo use reflection to know the identifier } } $attributes[$attributeName] = $attributeValue; } } return $attributes; }
/** * This is the XML-RPC server routine * * @access public * @return void */ public function run() { Yii::import('application.helpers.remotecontrol.*'); $oHandler = new remotecontrol_handle($this->controller); $RPCType = Yii::app()->getConfig("RPCInterface"); if (Yii::app()->getRequest()->isPostRequest) { if ($RPCType == 'xml') { $cur_path = get_include_path(); set_include_path($cur_path . PATH_SEPARATOR . APPPATH . 'helpers'); // Yii::import was causing problems for some odd reason require_once 'Zend/XmlRpc/Server.php'; require_once 'Zend/XmlRpc/Server/Exception.php'; require_once 'Zend/XmlRpc/Value/Exception.php'; $this->xmlrpc = new Zend_XmlRpc_Server(); $this->xmlrpc->sendArgumentsToAllMethods(false); Yii::import('application.libraries.LSZend_XmlRpc_Response_Http'); $this->xmlrpc->setResponseClass('LSZend_XmlRpc_Response_Http'); $this->xmlrpc->setClass($oHandler); $result = $this->xmlrpc->handle(); if ($result instanceof LSZend_XmlRpc_Response_Http) { $result->printXml(); } else { // a Zend_XmlRpc_Server_Fault with exception message from XMLRPC echo $result; } } elseif ($RPCType == 'json') { Yii::app()->loadLibrary('LSjsonRPCServer'); if (!isset($_SERVER['CONTENT_TYPE'])) { $serverContentType = explode(';', $_SERVER['HTTP_CONTENT_TYPE']); $_SERVER['CONTENT_TYPE'] = reset($serverContentType); } LSjsonRPCServer::handle($oHandler); } foreach (App()->log->routes as $route) { $route->enabled = $route->enabled && !$route instanceof CWebLogRoute; } exit; } else { // Disabled output of API methods for now if (Yii::app()->getConfig("rpc_publish_api") == true && in_array($RPCType, array('xml', 'json'))) { $reflector = new ReflectionObject($oHandler); foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { /* @var $method ReflectionMethod */ if (substr($method->getName(), 0, 1) !== '_') { $list[$method->getName()] = array('description' => str_replace(array("\r", "\r\n", "\n"), "<br/>", $method->getDocComment()), 'parameters' => $method->getParameters()); } } ksort($list); $aData['method'] = $RPCType; $aData['list'] = $list; $aData['display']['menu_bars'] = false; // Hide normal menu bar $this->_renderWrappedTemplate('remotecontrol', array('index_view'), $aData); } } }
/** * Processes an incoming request, executes it and builds a response. * * @since 5.1 * @param ModuleServerRequest $request Incoming request. * @param ModuleServerResponse $response Outcoming response. * @return void */ public function process(ModuleServerRequest $request, ModuleServerResponse $response) { $command = explode(' ', $request->getCommand()); $module_location = $command[1]; if (!strlen($module_location)) { $response->sendWarning(ModuleServerResponse::SC_NOT_FOUND, 'Module location not defined.', ModuleServerRsponse::ERROR_CLASSNAME_MISSING); return; } try { $locator = new ModuleLocator('module://' . $request->getHeader('User') . ':' . $request->getHeader('Password') . '@/' . $module_location); $sessionId = $request->getHeader('Session'); if ($sessionId) { $this->module = ModuleFactory::getSessionModule($locator, $sessionId); } else { $this->module = ModuleFactory::getModule($locator); } } catch (ModuleException $e) { $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, $e->__toString()); return; } catch (\Exception $e) { $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, $e->__toString()); return; } if (!($xmlrpc_server = xmlrpc_server_create())) { $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, 'Internal error: Could not create an XML-RPC server.', ModuleServerResponse::ERROR_XMLRPC_ERROR); return; } $theClass = new \ReflectionObject($this->module); $methods = $theClass->getMethods(); foreach ($methods as $method) { // Ignore private methods $theMethod = new \ReflectionMethod($theClass->getName(), $method->getName()); if (!$theMethod->isPublic()) { continue; } // Expose only methods beginning with "module" prefix if (!(substr($method->getName(), 0, 6) == 'module')) { continue; } xmlrpc_server_register_method($xmlrpc_server, strtolower($method->getName()), array($this, 'xmlrpcGateway')); } xmlrpc_server_register_introspection_callback($xmlrpc_server, array($this, 'introspectionGateway')); try { $buffer = xmlrpc_server_call_method($xmlrpc_server, $request->getPayload(), '', array('output_type' => 'xml')); $response->addHeader('Module/1.0 ' . ModuleServerResponse::SC_OK); $response->setBuffer($buffer); } catch (\Exception $e) { $response->addHeader('Module/1.0 ' . ModuleServerResponse::SC_INTERNAL_ERROR); $response->setBuffer($buffer); } xmlrpc_server_destroy($xmlrpc_server); $context = new ModuleContext($module_location); $session = new \Innomatic\Module\Session\ModuleSession($context, $sessionId); $session->save($this->module); $response->addHeader('Session: ' . $session->getId()); }
/** * Loads definitions and translations from provided context. * * @param ContextInterface $context */ public function load(ContextInterface $context) { $reflection = new \ReflectionObject($context); foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodRefl) { foreach ($this->readMethodAnnotations($reflection->getName(), $methodRefl) as $annotation) { if ($annotation instanceof HookInterface) { $this->hookDispatcher->addHook($annotation); } } } }
protected static function objectListensToEvents(MF_Events_Listener $obj) { $reflectionObj = new ReflectionObject($obj); $methods = $reflectionObj->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { if (substr($method->name, 0, 8) == 'listenTo') { $event = lcfirst(substr($method->name, 8)); self::$listeners[$event][] = array('type' => MF_Events_Manager::TYPE_OBJECT, 'obj' => $obj, 'method' => $method->name); } } }
protected function runTestSet($testSetName) { parent::runTestSet($testSetName); $assertionFile = "{$testSetName}_assertions.php"; if (file_exists($assertionFile)) { $assertionObject = (include $assertionFile); $assertionReflection = new ReflectionObject($assertionObject); foreach ($assertionReflection->getMethods() as $assertionMethod) { $assertionMethod->invoke($assertionObject, $this->backend); } } }
public static function getProcedures($object) { $reflect = new ReflectionObject($object); $methods = $reflect->getMethods(); $procedures = array(); foreach ($methods as $method) { if (!$method->isConstructor() && !$method->isStatic()) { array_push($procedures, self::getProcedure($object, $method)); } } return $procedures; }
protected function generateCfg($type) { $ReflectionObject = new \ReflectionObject($this); $result = []; foreach ($ReflectionObject->getMethods() as $k => $method) { $methodName = $method->getName(); if (preg_match("/^{$type}([A-Z][a-z]+)+\$/", $methodName)) { $result[] = str_replace($type, '', $methodName); } } return $result; }
public function generateCode($newClassName, $obj) { $result = $this->inner->generateCode($newClassName, $obj) . "\n"; $ref = new \ReflectionObject($obj); foreach ($ref->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { if (in_array($method->getName(), $this->notOverride)) { break; } $result .= "public function {$method->getName()}(){\n\treturn call_user_func_array(array(\n\t\t\t\$this->getAnnotatedObject(),\n\t\t\t'{$method->getName()}'\n\t\t),\n\t\tfunc_get_args()\n\t);\n}"; } return $result; }
public function assertCustomAssertions(ezcWebdavClientTest $test) { $assertions = $this->getCustomAssertions($this->testSetId); if ($assertions !== null) { $refObj = new ReflectionObject($assertions); foreach ($refObj->getMethods() as $refMethod) { if ($refMethod->isPublic()) { $refMethod->invoke($assertions, $test->backend); } } } }
/** * @return array */ protected function getMethods() { $reflection = new \ReflectionObject($this); $methods = array(); foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { $name = $method->getName(); if (substr($name, -6) === 'Method') { $methods[substr($name, 0, -6)] = $name; } } return $methods; }
/** * Retrieve the trait methods * * @return void */ private function _retrieveMethods() { $exclude = array_merge(array('__construct', 'getMethods'), $this->_excludeMethods); $ro = new ReflectionObject($this); foreach ($ro->getMethods() as $method) { if ($method->isPublic()) { $name = $method->getName(); if (!in_array($name, $exclude)) { $this->_addMethod($name); } } } }
public function getMethods($filter = null) { $methods = array(); if ($filter === null) { $methods = parent::getMethods(); } else { $methods = parent::getMethods($filter); } foreach ($methods as $id => $method) { $methods[$id] = $this->getMethod($method->GetName()); } return $methods; }
/** * @param $object * @return array */ public function extract($object) { $reflection = new \ReflectionObject($object); $values = []; foreach ($reflection->getMethods() as $method) { if (strpos($method->getName(), self::METHOD_GETTER) === 0) { $name = lcfirst(str_replace(self::METHOD_GETTER, '', $method->getName())); $name = $this->namingStrategy ? $this->namingStrategy->convert($name) : $name; $values[$name] = $method->invoke($object); } } return $values; }
public function addDecorator($obj) { $this->decorators['objs'][] = $obj; $refObj = new ReflectionObject($obj); $methods = $refObj->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { $this->decorators['methods'][$method->name] = $obj; } $properties = $refObj->getProperties(ReflectionProperty::IS_PUBLIC); foreach ($properties as $property) { $this->decorators['properties'][$property->name] = $obj; } }
function main() { $a = new stdClass(); $ro = new ReflectionObject($a); var_dump($ro->getMethods()); $rc = new ReflectionClass(get_class($a)); try { $ro = new ReflectionObject(get_class($a)); } catch (Exception $e) { // Throwing an exception is different from PHP5, which allows for the // ReflectionObject to be created but then fatal hard. echo get_class($e), ': ', $e->getMessage(), "\n"; } }