当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionObject::getMethods方法代码示例

本文整理汇总了PHP中ReflectionObject::getMethods方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject::getMethods方法的具体用法?PHP ReflectionObject::getMethods怎么用?PHP ReflectionObject::getMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionObject的用法示例。


在下文中一共展示了ReflectionObject::getMethods方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isEmpty

 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;
 }
开发者ID:nurirahmat,项目名称:Yii-Extensions,代码行数:29,代码来源:ActiveRecord.php

示例2: normalize

 /**
  * {@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;
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:29,代码来源:GetSetMethodNormalizer.php

示例3: __call

 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);
     }
 }
开发者ID:anddorua,项目名称:boardroom,代码行数:32,代码来源:DependencyInjection.php

示例4: __construct

 /**
  * 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;
 }
开发者ID:tur-nr,项目名称:chainnn,代码行数:36,代码来源:Chain.php

示例5: getControllerResources

 /**
  * @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();
 }
开发者ID:noikiy,项目名称:amatteur,代码行数:31,代码来源:Modules.php

示例6: normalize

 /**
  * {@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;
 }
开发者ID:mcolabs,项目名称:normalizer,代码行数:40,代码来源:Normalizer.php

示例7: run

 /**
  * 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.");
     }
 }
开发者ID:xnovk,项目名称:test,代码行数:29,代码来源:TestCase.php

示例8: normalize

    /**
     * {@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;
    }
开发者ID:Gregwar,项目名称:symfony,代码行数:28,代码来源:GetSetMethodNormalizer.php

示例9: checkAPI

 /**
  * 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);
     }
 }
开发者ID:xxdf,项目名称:showtimes,代码行数:41,代码来源:OldPHPAPI.php

示例10: run

 /**
  * 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.");
     }
 }
开发者ID:jave007,项目名称:test,代码行数:33,代码来源:TestCase.php

示例11: normalize

    /**
     * {@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;
    }
开发者ID:n3b,项目名称:symfony,代码行数:31,代码来源:GetSetMethodNormalizer.php

示例12: getFormatters

 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;
 }
开发者ID:ruudk,项目名称:Faker,代码行数:34,代码来源:Documentor.php

示例13: extract

 /**
  * @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;
 }
开发者ID:vegas-cmf,项目名称:common,代码行数:21,代码来源:Method.php

示例14: getActionMethods

 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());
     }));
 }
开发者ID:eddmann,项目名称:rootr,代码行数:9,代码来源:Controller.php

示例15: normalize

 /**
  * 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;
 }
开发者ID:thomasbeaujean,项目名称:getsetmethodforeignnormalizer,代码行数:66,代码来源:GetSetPrimaryMethodNormalizer.php


注:本文中的ReflectionObject::getMethods方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。