Zend\Code\Scanner\ClassScanner::getMethods PHP Method

getMethods() public method

Return a list of methods
public getMethods ( ) : Zend\Code\Scanner\MethodScanner[]
return Zend\Code\Scanner\MethodScanner[]
    public function getMethods()
    {
        $this->scan();
        if (!empty($this->methods)) {
            return $this->methods;
        }
        foreach ($this->infos as $info) {
            if ($info['type'] !== 'method' && $info['type'] !== 'use') {
                continue;
            }
            // Merge in trait methods
            if ($info['type'] === "use") {
                $traitMethods = [];
                $traits = $this->getTraits();
                $insteadof = $this->getBlockedTraitMethods();
                $aliases = $this->getTraitAliases();
                foreach ($traits as $trait) {
                    $tempMethods = $trait->getMethods();
                    foreach ($tempMethods as $tempMethod) {
                        $methodFullName = $trait->getName() . '::' . $tempMethod->getName();
                        $methodAlias = array_search($methodFullName, $aliases);
                        if (false !== $methodAlias) {
                            // trait::method is aliased
                            // clone the tempMethod as we need to change
                            // the name and possibly the visibility of the
                            // scanned method.
                            //
                            // @todo setName and setVisibility were added to
                            // MethodScanner to accomplish this, may not be the
                            // best option, could use ReflectionClass instead?
                            $newMethod = clone $tempMethod;
                            $newMethod->setName($methodAlias);
                            // if visibility exists, change it on the MethodScanner
                            $visibility = $this->getVisibilityForAlias($methodAlias);
                            if (null !== $visibility) {
                                $newMethod->setVisibility($visibility);
                            }
                            $traitMethods[$methodAlias] = $newMethod;
                        } elseif (in_array($methodFullName, $insteadof)) {
                            // ignore overridden methods
                            continue;
                        } else {
                            if (array_key_exists($tempMethod->getName(), $traitMethods)) {
                                throw new Exception\RuntimeException(sprintf('Trait method %s has not been applied because there are' . ' collisions with other trait methods see: (insteadof OR as)', $tempMethod->getName()));
                            }
                            $traitMethods[$tempMethod->getName()] = $tempMethod;
                        }
                    }
                }
                $this->methods = array_merge($this->methods, array_values($traitMethods));
                continue;
            }
            $m = new MethodScanner(array_slice($this->tokens, $info['tokenStart'], $info['tokenEnd'] - $info['tokenStart'] + 1), $this->nameInformation);
            $m->setClass($this->name);
            $m->setScannerClass($this);
            $this->methods[] = $m;
        }
        return $this->methods;
    }

Usage Example

Example #1
0
 public function compileScannerInjectionMethods(ClassScanner $scannerClass)
 {
     $data      = array();
     $className = $scannerClass->getName();
     foreach ($scannerClass->getMethods(true) as $scannerMethod) {
         $methodName = $scannerMethod->getName();
         
         // determine initiator & constructor dependencies
         if ($methodName === '__construct' && $scannerMethod->isPublic()) {
             $params = $scannerMethod->getParameters(true);
             if ($params) {
                 $data[$methodName] = array();
                 foreach ($params as $param) {
                     $data[$methodName][$param->getName()] = $param->getClass();
                 }
             }
         }
         
         // scan for setter injection
         if (preg_match('#^set[A-Z]#', $methodName)) {
             $data[$methodName] = $scannerMethod->getParameters();
             $params = $scannerMethod->getParameters(true);
             $data[$methodName] = array();
             foreach ($params as $param) {
                 $data[$methodName][$param->getName()] = $param->getClass();
             }
         }
     }
     return $data;
 }
All Usage Examples Of Zend\Code\Scanner\ClassScanner::getMethods