示例#1
0
 /**
  * Retrieve parsed methods for this class
  * 
  * @return array Array of ClassMethod objects
  */
 public function getMethods()
 {
     if (null !== $this->methods) {
         return $this->methods;
     }
     $rMethods = $this->reflection->getMethods(ReflectionMethod::IS_PUBLIC);
     $methods = array();
     foreach ($rMethods as $method) {
         $methods[] = new ClassMethod($method);
     }
     $this->methods = $methods;
     return $this->methods;
 }
示例#2
0
 public function testMethodReturns()
 {
     $reflectionClass = new Reflection\ReflectionClass('\\ZendTest\\Reflection\\TestAsset\\TestSampleClass2');
     $methodByName = $reflectionClass->getMethod('getProp1');
     $this->assertEquals('Zend\\Reflection\\ReflectionMethod', get_class($methodByName));
     $methodsAll = $reflectionClass->getMethods();
     $this->assertEquals(3, count($methodsAll));
     $firstMethod = array_shift($methodsAll);
     $this->assertEquals('getProp1', $firstMethod->getName());
 }
示例#3
0
    /**
     * fromReflection() - build a Code Generation Php Object from a Class Reflection
     *
     * @param \Zend\Reflection\ReflectionClass $reflectionClass
     * @return \Zend\CodeGenerator\Php\PhpClass
     */
    public static function fromReflection(\Zend\Reflection\ReflectionClass $reflectionClass)
    {
        $class = new self();

        $class->setSourceContent($class->getSourceContent());
        $class->setSourceDirty(false);

        if ($reflectionClass->getDocComment() != '') {
            $class->setDocblock(PhpDocblock::fromReflection($reflectionClass->getDocblock()));
        }

        $class->setAbstract($reflectionClass->isAbstract());
        
        // set the namespace
        if ($reflectionClass->inNamespace()) {
            $class->setNamespaceName($reflectionClass->getNamespaceName());
        }

        $class->setName($reflectionClass->getName());
        
        if ($parentClass = $reflectionClass->getParentClass()) {
            $class->setExtendedClass($parentClass->getName());
            $interfaces = array_diff($reflectionClass->getInterfaces(), $parentClass->getInterfaces());
        } else {
            $interfaces = $reflectionClass->getInterfaces();
        }

        $interfaceNames = array();
        foreach($interfaces AS $interface) {
            $interfaceNames[] = $interface->getName();
        }

        $class->setImplementedInterfaces($interfaceNames);

        $properties = array();
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) {
                $properties[] = PhpProperty::fromReflection($reflectionProperty);
            }
        }
        $class->setProperties($properties);

        $methods = array();
        foreach ($reflectionClass->getMethods() as $reflectionMethod) {
            if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) {
                $methods[] = PhpMethod::fromReflection($reflectionMethod);
            }
        }
        $class->setMethods($methods);

        return $class;
    }
示例#4
0
    /**
     * _processActionableMethods() - process all methods that can be called on this provider.
     *
     */
    protected function _processActionableMethods()
    {

        $specialtyRegex = '#(.*)(' . implode('|', $this->_specialties) . ')$#i';


        $methods = $this->_providerReflection->getMethods();

        $actionableMethods = array();
        foreach ($methods as $method) {

            $methodName = $method->getName();

            /**
             * the following will determine what methods are actually actionable
             * public, non-static, non-underscore prefixed, classes that dont
             * contain the name "
             */
            if (!$method->getDeclaringClass()->isInstantiable()
                || !$method->isPublic()
                || $methodName[0] == '_'
                || $method->isStatic()
                || in_array($methodName, array('getContextClasses', 'getName')) // other protected public methods will nee to go here
                ) {
                continue;
            }

            /**
             * check to see if the method was a required method by a Zend_Tool_* interface
             */
            foreach ($method->getDeclaringClass()->getInterfaces() as $methodDeclaringClassInterface) {
                if (strpos($methodDeclaringClassInterface->getName(), 'Zend_Tool_') === 0
                    && $methodDeclaringClassInterface->hasMethod($methodName)) {
                    continue 2;
                }
            }

            $actionableName = ucfirst($methodName);

            if (substr($actionableName, -6) == 'Action') {
                $actionableName = substr($actionableName, 0, -6);
            }

            $actionableMethods[$methodName]['methodName'] = $methodName;

            $matches = null;
            if (preg_match($specialtyRegex, $actionableName, $matches)) {
                $actionableMethods[$methodName]['actionName'] = $matches[1];
                $actionableMethods[$methodName]['specialty'] = $matches[2];
            } else {
                $actionableMethods[$methodName]['actionName'] = $actionableName;
                $actionableMethods[$methodName]['specialty'] = '_Global';
            }

            // get the action, and create non-existent actions when they dont exist (the true part below)
            $action = $this->_registry->getActionRepository()->getAction($actionableMethods[$methodName]['actionName']);
            if ($action == null) {
                $action = new \Zend\Tool\Framework\Action\Base($actionableMethods[$methodName]['actionName']);
                $this->_registry->getActionRepository()->addAction($action);
            }
            $actionableMethods[$methodName]['action'] = $action;

            if (!in_array($actionableMethods[$methodName]['action'], $this->_actions)) {
                $this->_actions[] = $actionableMethods[$methodName]['action'];
            }

            $parameterInfo = array();
            $position = 1;
            foreach ($method->getParameters() as $parameter) {
                $currentParam = $parameter->getName();
                $parameterInfo[$currentParam]['position']    = $position++;
                $parameterInfo[$currentParam]['optional']    = $parameter->isOptional();
                $parameterInfo[$currentParam]['default']     = ($parameter->isOptional()) ? $parameter->getDefaultValue() : null;
                $parameterInfo[$currentParam]['name']        = $currentParam;
                $parameterInfo[$currentParam]['type']        = 'string';
                $parameterInfo[$currentParam]['description'] = null;
            }

            $matches = null;
            if (($docComment = $method->getDocComment()) != '' &&
                (preg_match_all('/@param\s+(\w+)+\s+(\$\S+)\s+(.*?)(?=(?:\*\s*@)|(?:\*\/))/s', $docComment, $matches)))
            {
                for ($i=0; $i <= count($matches[0])-1; $i++) {
                    $currentParam = ltrim($matches[2][$i], '$');

                    if ($currentParam != '' && isset($parameterInfo[$currentParam])) {

                        $parameterInfo[$currentParam]['type'] = $matches[1][$i];

                        $descriptionSource = $matches[3][$i];

                        if ($descriptionSource != '') {
                            $parameterInfo[$currentParam]['description'] = trim($descriptionSource);
                        }

                    }

                }

            }

            $actionableMethods[$methodName]['parameterInfo'] = $parameterInfo;

        }

        $this->_actionableMethods = $actionableMethods;
    }