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


PHP ClassReflection::getMethod方法代码示例

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


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

示例1: testDocblockTags

 public function testDocblockTags()
 {
     $classReflection = new ClassReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass5');
     $this->assertEquals(1, count($classReflection->getDocblock()->getTags()));
     $this->assertEquals(1, count($classReflection->getDocblock()->getTags('author')));
     $this->assertFalse($classReflection->getDocblock()->getTag('version'));
     $this->assertTrue($classReflection->getMethod('doSomething')->getDocblock()->hasTag('return'));
     $returnTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('return');
     $this->assertInstanceOf('Zend\\Code\\Reflection\\DocBlock\\Tag', $returnTag);
     $this->assertEquals('mixed', $returnTag->getType());
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:11,代码来源:DocBlockReflectionTest.php

示例2: getInputData

 /**
  * Converts the provided input array from key-value format to a list of parameters suitable for the specified
  * class / method.
  *
  * The input array should have the field name as the key, and the value will either be a primitive or another
  * key-value array.  The top level of this array needs keys that match the names of the parameters on the
  * service method.
  *
  * Mismatched types are caught by the PHP runtime, not explicitly checked for by this code.
  *
  * @param string $serviceClassName name of the service class that we are trying to call
  * @param string $serviceMethodName name of the method that we are trying to call
  * @param array $inputArray data to send to method in key-value format
  * @return array list of parameters that can be used to call the service method
  */
 public function getInputData($serviceClassName, $serviceMethodName, array $inputArray)
 {
     /** TODO: Reflection causes performance degradation when used in runtime. Should be optimized via caching */
     $serviceClass = new ClassReflection($serviceClassName);
     /** @var MethodReflection $serviceMethod */
     $serviceMethod = $serviceClass->getMethod($serviceMethodName);
     /** @var ParameterReflection[] $params */
     $params = $serviceMethod->getParameters();
     $inputData = [];
     foreach ($params as $param) {
         $paramName = $param->getName();
         $snakeCaseParamName = strtolower(preg_replace("/(?<=\\w)(?=[A-Z])/", "_\$1", $paramName));
         if (isset($inputArray[$paramName]) || isset($inputArray[$snakeCaseParamName])) {
             $paramValue = isset($inputArray[$paramName]) ? $inputArray[$paramName] : $inputArray[$snakeCaseParamName];
             if ($this->_isArrayParam($param)) {
                 $paramType = "{$param->getType()}[]";
             } else {
                 $paramType = $param->getType();
             }
             $inputData[] = $this->_convertValue($paramValue, $paramType);
         } else {
             $inputData[] = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
         }
     }
     return $inputData;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:41,代码来源:ServiceArgsSerializer.php

示例3: testMethodReturns

 public function testMethodReturns()
 {
     $reflectionClass = new ClassReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass2');
     $methodByName = $reflectionClass->getMethod('getProp1');
     $this->assertEquals('Zend\\Code\\Reflection\\MethodReflection', get_class($methodByName));
     $methodsAll = $reflectionClass->getMethods();
     $this->assertEquals(3, count($methodsAll));
     $firstMethod = array_shift($methodsAll);
     $this->assertEquals('getProp1', $firstMethod->getName());
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:10,代码来源:ClassReflectionTest.php

示例4: getAnnotations

 /**
  * @return AnnotationCollection
  */
 public function getAnnotations()
 {
     $reflection = new ClassReflection($this->getObject());
     try {
         $reflectionMethod = $reflection->getMethod($this->getMethod());
         return $reflectionMethod->getAnnotations($this->getAnnotationManager());
     } catch (\ReflectionException $e) {
         return false;
     }
 }
开发者ID:gontero,项目名称:gontero-acl,代码行数:13,代码来源:Annotation.php

示例5: loadPluginsForModule

 /**
  * Get forms for a module
  *
  * @param $moduleObject
  *
  * @return array
  */
 protected function loadPluginsForModule($moduleObject)
 {
     // initialize plugins
     $plugins = array();
     // check for configuration
     if (!method_exists($moduleObject, 'getConfig')) {
         return $plugins;
     }
     // get module configuration
     $moduleConfig = $moduleObject->getConfig();
     // check for no configured plugins
     if (!isset($moduleConfig['controller_plugins'])) {
         return $plugins;
     }
     // loop through plugins
     foreach ($moduleConfig['controller_plugins'] as $type => $loadedPlugins) {
         // skip if not invokable nor factory
         if (!in_array($type, array('invokables', 'factories'))) {
             continue;
         }
         // initialize plugin type
         $plugins[$type] = array();
         // loop through plugin list
         foreach ($loadedPlugins as $pluginKey => $pluginClass) {
             // check if plugin class or factory does not exist
             if (!class_exists($pluginClass)) {
                 continue;
             }
             // check for factory
             if (in_array('Zend\\ServiceManager\\FactoryInterface', class_implements($pluginClass))) {
                 // start class reflection
                 $classReflection = new ClassReflection($pluginClass);
                 // get create method and doc block
                 $method = $classReflection->getMethod('createService');
                 $docBlock = $method->getDocBlock();
                 // check doc block for return tag and use class
                 if ($docBlock) {
                     // loop through all doc blocks
                     foreach ($docBlock->getTags() as $tag) {
                         /** @var $tag ReturnTag */
                         if ($tag->getName() != 'return') {
                             continue;
                         }
                         $pluginClass = $classReflection->getNamespaceName() . '\\' . $tag->getTypes()[0];
                     }
                 } else {
                     // try to read plugin instantiation from method
                     preg_match_all('^\\$plugin\\s*=\\s*new\\s*([a-zA-z0-9]+)\\(\\)\\;^', $method->getContents(), $matches);
                     $pluginClass = $classReflection->getNamespaceName() . '\\' . $matches[1][0];
                 }
             }
             // check for class existence
             if (!class_exists($pluginClass)) {
                 break;
             }
             // add plugin class for type
             $plugins[$type][$pluginKey] = $pluginClass;
         }
     }
     // loop through plugins
     foreach ($plugins as $type => $pluginList) {
         // check if any plugin exists for type
         if (empty($pluginList)) {
             unset($plugins[$type]);
             // otherwise sort plugins
         } else {
             ksort($plugins[$type]);
         }
     }
     return $plugins;
 }
开发者ID:nomaanp,项目名称:zf2rapid,代码行数:78,代码来源:LoadForms.php

示例6: classHasMethod

 /**
  * Checks if method is defined
  *
  * Case sensitivity of the method is taken into account.
  *
  * @param ClassReflection $class
  * @param string $methodName
  * @return bool
  */
 protected function classHasMethod(ClassReflection $class, $methodName)
 {
     return $class->hasMethod($methodName) && $class->getMethod($methodName)->getName() == $methodName;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:TypeProcessor.php

示例7: testGetParameterDescription

 public function testGetParameterDescription()
 {
     $class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
     $methodReflection = $class->getMethod('setName');
     $paramsReflection = $methodReflection->getParameters();
     $this->assertEquals('Name of the attribute', $this->_typeProcessor->getParamDescription($paramsReflection[0]));
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:7,代码来源:TypeProcessorTest.php

示例8: getMethodParams

 /**
  * Retrieve requested service method params metadata.
  *
  * @param string $serviceClassName
  * @param string $serviceMethodName
  * @return array
  */
 protected function getMethodParams($serviceClassName, $serviceMethodName)
 {
     $cacheId = self::CACHE_ID_PREFIX . hash('md5', $serviceClassName . $serviceMethodName);
     $params = $this->cache->load($cacheId);
     if ($params !== false) {
         return unserialize($params);
     }
     $serviceClass = new ClassReflection($serviceClassName);
     /** @var MethodReflection $serviceMethod */
     $serviceMethod = $serviceClass->getMethod($serviceMethodName);
     $params = [];
     /** @var ParameterReflection $paramReflection */
     foreach ($serviceMethod->getParameters() as $paramReflection) {
         $isDefaultValueAvailable = $paramReflection->isDefaultValueAvailable();
         $params[] = [
             'name' => $paramReflection->getName(),
             'type' => $this->typeProcessor->getParamType($paramReflection),
             'isDefaultValueAvailable' => $isDefaultValueAvailable,
             'defaultValue' => $isDefaultValueAvailable ? $paramReflection->getDefaultValue() : null
         ];
     }
     $this->cache->save(serialize($params), $cacheId, [WebapiCache::CACHE_TAG]);
     return $params;
 }
开发者ID:nja78,项目名称:magento2,代码行数:31,代码来源:ServiceInputProcessor.php

示例9: testAutodetectAction

 public function testAutodetectAction()
 {
     $configBuilder = new RouteConfigBuilder();
     /* @var $parser ControllerAnnotationParser */
     $parser = $this->serviceManager->get('parser');
     $classReflection = new ClassReflection(new NoBaseController());
     $method = $classReflection->getMethod('noActionAction');
     $annotations = $parser->getMethodAnnotations($method);
     /* @var $route Route */
     $route = $annotations[0];
     $parser->autodetectMissingFields($route, $method, 'controllerkey');
     $configBuilder->addPart($route);
     $routeArray = array('no-action' => array('type' => 'literal', 'options' => array('route' => '/no-action', 'defaults' => array('controller' => 'controllerkey', 'action' => 'no-action'), 'constraints' => null), 'may_terminate' => true));
     $this->assertEquals($routeArray, $configBuilder->toArray());
 }
开发者ID:alex-oleshkevich,项目名称:zf2-annotated-router,代码行数:15,代码来源:SimpleRouteAnnotationTest.php

示例10: getMethodParams

 /**
  * Retrieve requested service method params metadata.
  *
  * @param string $serviceClassName
  * @param string $serviceMethodName
  * @return array
  */
 public function getMethodParams($serviceClassName, $serviceMethodName)
 {
     $cacheId = self::SERVICE_METHOD_PARAMS_CACHE_PREFIX . hash('md5', $serviceClassName . $serviceMethodName);
     $params = $this->cache->load($cacheId);
     if ($params !== false) {
         return unserialize($params);
     }
     $serviceClass = new ClassReflection($serviceClassName);
     /** @var MethodReflection $serviceMethod */
     $serviceMethod = $serviceClass->getMethod($serviceMethodName);
     $params = [];
     /** @var ParameterReflection $paramReflection */
     foreach ($serviceMethod->getParameters() as $paramReflection) {
         $isDefaultValueAvailable = $paramReflection->isDefaultValueAvailable();
         $params[] = [self::METHOD_META_NAME => $paramReflection->getName(), self::METHOD_META_TYPE => $this->typeProcessor->getParamType($paramReflection), self::METHOD_META_HAS_DEFAULT_VALUE => $isDefaultValueAvailable, self::METHOD_META_DEFAULT_VALUE => $isDefaultValueAvailable ? $paramReflection->getDefaultValue() : null];
     }
     $this->cache->save(serialize($params), $cacheId, [ReflectionCache::CACHE_TAG]);
     return $params;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:26,代码来源:MethodsMap.php

示例11: cloneFactory

 /**
  * Create a new subclass and factory to override a factory-generated
  * service.
  *
  * @param mixed  $factory Factory configuration for class to extend
  * @param string $module  Module in which to create the new factory
  *
  * @return string
  * @throws \Exception
  */
 protected function cloneFactory($factory, $module)
 {
     // Make sure we can figure out how to handle the factory; it should
     // either be a [controller, method] array or a "controller::method"
     // string; anything else will cause a problem.
     $parts = is_string($factory) ? explode('::', $factory) : $factory;
     if (!is_array($parts) || count($parts) != 2 || !class_exists($parts[0]) || !method_exists($parts[0], $parts[1])) {
         throw new \Exception('Unexpected factory configuration format.');
     }
     list($factoryClass, $factoryMethod) = $parts;
     $newFactoryClass = $this->generateLocalClassName($factoryClass, $module);
     if (!class_exists($newFactoryClass)) {
         $this->createClassInModule($newFactoryClass, $module);
         $skipBackup = true;
     } else {
         $skipBackup = false;
     }
     if (method_exists($newFactoryClass, $factoryMethod)) {
         throw new \Exception("{$newFactoryClass}::{$factoryMethod} already exists.");
     }
     $oldReflection = new ClassReflection($factoryClass);
     $newReflection = new ClassReflection($newFactoryClass);
     $generator = ClassGenerator::fromReflection($newReflection);
     $method = MethodGenerator::fromReflection($oldReflection->getMethod($factoryMethod));
     $this->createServiceClassAndUpdateFactory($method, $oldReflection->getNamespaceName(), $module);
     $generator->addMethodFromGenerator($method);
     $this->writeClass($generator, $module, true, $skipBackup);
     return $newFactoryClass . '::' . $factoryMethod;
 }
开发者ID:bbeckman,项目名称:NDL-VuFind2,代码行数:39,代码来源:GenerateController.php

示例12: hasMethod

 /**
  * Checks if method is defined
  *
  * Case sensitivity of the method is taken into account.
  *
  * @param ClassReflection $class
  * @param string $methodName
  * @return bool
  */
 public function hasMethod(ClassReflection $class, $methodName)
 {
     return $class->hasMethod($methodName) && $class->getMethod($methodName)->getName() == $methodName;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:NameFinder.php


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