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


PHP ClassReflection::hasMethod方法代码示例

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


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

示例1: _processSpecialties

 /**
  * _processSpecialties() - Break out the specialty names for this provider
  *
  */
 protected function _processSpecialties()
 {
     $specialties = array();
     if ($this->_providerReflection->hasMethod('getSpecialties')) {
         $specialties = $this->_provider->getSpecialties();
         if (!is_array($specialties)) {
             throw new Exception\RuntimeException('Provider ' . get_class($this->_provider) . ' must return an array for method getSpecialties().');
         }
     } else {
         $defaultProperties = $this->_providerReflection->getDefaultProperties();
         $specialties = isset($defaultProperties['_specialties']) ? $defaultProperties['_specialties'] : array();
         if (!is_array($specialties)) {
             throw new Exception\RuntimeException('Provider ' . get_class($this->_provider) . '\'s property $_specialties must be an array.');
         }
     }
     $this->_specialties = array_merge(array('_Global'), $specialties);
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:21,代码来源:Signature.php

示例2: processClass

 protected function processClass($class)
 {
     $strategy = $this->introspectionStrategy;
     // localize for readability
     try {
         $rClass = new Reflection\ClassReflection($class);
     } catch (\ReflectionException $e) {
         if (!$this->allowReflectionExceptions) {
             throw $e;
         }
         return;
     }
     $className = $rClass->getName();
     $matches = null;
     // used for regex below
     // setup the key in classes
     $this->classes[$className] = array('supertypes' => array(), 'instantiator' => null, 'methods' => array(), 'parameters' => array());
     $def =& $this->classes[$className];
     // localize for brevity
     // class annotations?
     if ($strategy->getUseAnnotations() == true) {
         $annotations = $rClass->getAnnotations($strategy->getAnnotationManager());
         if ($annotations instanceof AnnotationCollection && $annotations->hasAnnotation('Zend\\Di\\Definition\\Annotation\\Instantiator')) {
             // @todo Instnatiator support in annotations
         }
     }
     $rTarget = $rClass;
     $supertypes = array();
     do {
         $supertypes = array_merge($supertypes, $rTarget->getInterfaceNames());
         if (!($rTargetParent = $rTarget->getParentClass())) {
             break;
         }
         $supertypes[] = $rTargetParent->getName();
         $rTarget = $rTargetParent;
     } while (true);
     $def['supertypes'] = $supertypes;
     if ($def['instantiator'] == null) {
         if ($rClass->isInstantiable()) {
             $def['instantiator'] = '__construct';
         }
     }
     if ($rClass->hasMethod('__construct')) {
         $def['methods']['__construct'] = true;
         // required
         try {
             $this->processParams($def, $rClass, $rClass->getMethod('__construct'));
         } catch (\ReflectionException $e) {
             if (!$this->allowReflectionExceptions) {
                 throw $e;
             }
             return;
         }
     }
     foreach ($rClass->getMethods(Reflection\MethodReflection::IS_PUBLIC) as $rMethod) {
         $methodName = $rMethod->getName();
         if ($rMethod->getName() === '__construct') {
             continue;
         }
         if ($strategy->getUseAnnotations() == true) {
             $annotations = $rMethod->getAnnotations($strategy->getAnnotationManager());
             if ($annotations instanceof AnnotationCollection && $annotations->hasAnnotation('Zend\\Di\\Definition\\Annotation\\Inject')) {
                 $def['methods'][$methodName] = true;
                 $this->processParams($def, $rClass, $rMethod);
                 continue;
             }
         }
         $methodPatterns = $this->introspectionStrategy->getMethodNameInclusionPatterns();
         // matches a method injection pattern?
         foreach ($methodPatterns as $methodInjectorPattern) {
             preg_match($methodInjectorPattern, $methodName, $matches);
             if ($matches) {
                 $def['methods'][$methodName] = false;
                 // check ot see if this is required?
                 $this->processParams($def, $rClass, $rMethod);
                 continue 2;
             }
         }
         // method
         // by annotation
         // by setter pattern,
         // by interface
     }
     $interfaceInjectorPatterns = $this->introspectionStrategy->getInterfaceInjectionInclusionPatterns();
     // matches the interface injection pattern
     /** @var $rIface \ReflectionClass */
     foreach ($rClass->getInterfaces() as $rIface) {
         foreach ($interfaceInjectorPatterns as $interfaceInjectorPattern) {
             preg_match($interfaceInjectorPattern, $rIface->getName(), $matches);
             if ($matches) {
                 foreach ($rIface->getMethods() as $rMethod) {
                     if ($rMethod->getName() === '__construct') {
                         // ctor not allowed in ifaces
                         continue;
                     }
                     $def['methods'][$rMethod->getName()] = true;
                     $this->processParams($def, $rClass, $rMethod);
                 }
                 continue 2;
             }
//.........这里部分代码省略.........
开发者ID:navassouza,项目名称:zf2,代码行数:101,代码来源:CompilerDefinition.php

示例3: processClass

 /**
  * @param string $class
  * @param bool $forceLoad
  */
 protected function processClass($class, $forceLoad = false)
 {
     if (!$forceLoad && $this->hasProcessedClass($class)) {
         return;
     }
     $strategy = $this->introspectionStrategy;
     // localize for readability
     /** @var $rClass \Zend\Code\Reflection\ClassReflection */
     $rClass = new Reflection\ClassReflection($class);
     $className = $rClass->getName();
     $matches = null;
     // used for regex below
     // setup the key in classes
     $this->classes[$className] = array('supertypes' => array(), 'instantiator' => null, 'methods' => array(), 'parameters' => array());
     $def =& $this->classes[$className];
     // localize for brevity
     // class annotations?
     if ($strategy->getUseAnnotations() == true) {
         $annotations = $rClass->getAnnotations($strategy->getAnnotationManager());
         if ($annotations instanceof AnnotationCollection && $annotations->hasAnnotation('Zend\\Di\\Definition\\Annotation\\Instantiator')) {
             // @todo Instantiator support in annotations
         }
     }
     $rTarget = $rClass;
     $supertypes = array();
     do {
         $supertypes = array_merge($supertypes, $rTarget->getInterfaceNames());
         if (!($rTargetParent = $rTarget->getParentClass())) {
             break;
         }
         $supertypes[] = $rTargetParent->getName();
         $rTarget = $rTargetParent;
     } while (true);
     $def['supertypes'] = $supertypes;
     if ($def['instantiator'] == null) {
         if ($rClass->isInstantiable()) {
             $def['instantiator'] = '__construct';
         }
     }
     if ($rClass->hasMethod('__construct')) {
         $def['methods']['__construct'] = Di::METHOD_IS_CONSTRUCTOR;
         // required
         $this->processParams($def, $rClass, $rClass->getMethod('__construct'));
     }
     foreach ($rClass->getMethods(Reflection\MethodReflection::IS_PUBLIC) as $rMethod) {
         $methodName = $rMethod->getName();
         if ($rMethod->getName() === '__construct' || $rMethod->isStatic()) {
             continue;
         }
         if ($strategy->getUseAnnotations() == true) {
             $annotations = $rMethod->getAnnotations($strategy->getAnnotationManager());
             if ($annotations instanceof AnnotationCollection && $annotations->hasAnnotation('Zend\\Di\\Definition\\Annotation\\Inject')) {
                 // use '@inject' and search for parameters
                 $def['methods'][$methodName] = Di::METHOD_IS_EAGER;
                 $this->processParams($def, $rClass, $rMethod);
                 continue;
             }
         }
         $methodPatterns = $this->introspectionStrategy->getMethodNameInclusionPatterns();
         // matches a method injection pattern?
         foreach ($methodPatterns as $methodInjectorPattern) {
             preg_match($methodInjectorPattern, $methodName, $matches);
             if ($matches) {
                 $def['methods'][$methodName] = Di::METHOD_IS_OPTIONAL;
                 // check ot see if this is required?
                 $this->processParams($def, $rClass, $rMethod);
                 continue 2;
             }
         }
         // method
         // by annotation
         // by setter pattern,
         // by interface
     }
     $interfaceInjectorPatterns = $this->introspectionStrategy->getInterfaceInjectionInclusionPatterns();
     // matches the interface injection pattern
     /** @var $rIface \ReflectionClass */
     foreach ($rClass->getInterfaces() as $rIface) {
         foreach ($interfaceInjectorPatterns as $interfaceInjectorPattern) {
             preg_match($interfaceInjectorPattern, $rIface->getName(), $matches);
             if ($matches) {
                 foreach ($rIface->getMethods() as $rMethod) {
                     if ($rMethod->getName() === '__construct' || !count($rMethod->getParameters())) {
                         // constructor not allowed in interfaces
                         // Don't call interface methods without a parameter (Some aware interfaces define setters in ZF2)
                         continue;
                     }
                     $def['methods'][$rMethod->getName()] = Di::METHOD_IS_AWARE;
                     $this->processParams($def, $rClass, $rMethod);
                 }
                 continue 2;
             }
         }
     }
 }
开发者ID:ErR163,项目名称:torrentpier,代码行数:99,代码来源:RuntimeDefinition.php

示例4: _processGetterMethod

 /**
  * Find the getter method for a given property in the Data Object class
  *
  * @param ClassReflection $class
  * @param string $camelCaseProperty
  * @return string processed method name
  * @throws \Exception If $camelCaseProperty has no corresponding getter method
  */
 protected function _processGetterMethod(ClassReflection $class, $camelCaseProperty)
 {
     $getterName = 'get' . $camelCaseProperty;
     $boolGetterName = 'is' . $camelCaseProperty;
     if ($class->hasMethod($getterName)) {
         $methodName = $getterName;
     } elseif ($class->hasMethod($boolGetterName)) {
         $methodName = $boolGetterName;
     } else {
         throw new \Exception(sprintf('Property :"%s" does not exist in the Data Object class: "%s".', $camelCaseProperty, $class->getName()));
     }
     return $methodName;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:ServiceArgsSerializer.php

示例5: 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

示例6: findSetterMethodName

 /**
  * Find the setter method name for a property from the given class
  *
  * @param ClassReflection $class
  * @param string $camelCaseProperty
  * @return string processed method name
  * @throws \Exception If $camelCaseProperty has no corresponding setter method
  */
 public function findSetterMethodName(ClassReflection $class, $camelCaseProperty)
 {
     $setterName = 'set' . $camelCaseProperty;
     $boolSetterName = 'setIs' . $camelCaseProperty;
     if ($class->hasMethod($setterName)) {
         $methodName = $setterName;
     } elseif ($class->hasMethod($boolSetterName)) {
         $methodName = $boolSetterName;
     } else {
         throw new \Exception(sprintf('Property :"%s" does not exist in the provided class: "%s".', $camelCaseProperty, $class->getName()));
     }
     return $methodName;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:21,代码来源:TypeProcessor.php

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