public function testParemeterReturn() { $method = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass2', 'getProp2'); $parameters = $method->getParameters(); $this->assertEquals(count($parameters), 2); $this->assertEquals(get_class(array_shift($parameters)), 'Zend_Reflection_Parameter'); }
/** * MethodMd constructor. * @param $className * @param $methodName */ public function __construct($className, $methodName) { try { $method2 = new \Zend_Reflection_Method($className, $methodName); $this->name = $method2->getName(); $docBlock = $method2->getDocblock(); $shortDesc = str_replace(PHP_EOL, ' ', $docBlock->getShortDescription()); $this->description = str_replace(PHP_EOL, ' ', $shortDesc); } catch (\Exception $e) { // Unable to parse PHPDoc Block... Skip it :( } }
/** * fromReflection() * * @param Zend_Reflection_Method $reflectionMethod * @return Zend_CodeGenerator_Php_Method */ public static function fromReflection(Zend_Reflection_Method $reflectionMethod) { $method = new self(); $method->setSourceContent($reflectionMethod->getContents(false)); $method->setSourceDirty(false); if ($reflectionMethod->getDocComment() != '') { $method->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($reflectionMethod->getDocblock())); } $method->setFinal($reflectionMethod->isFinal()); if ($reflectionMethod->isPrivate()) { $method->setVisibility(self::VISIBILITY_PRIVATE); } elseif ($reflectionMethod->isProtected()) { $method->setVisibility(self::VISIBILITY_PROTECTED); } else { $method->setVisibility(self::VISIBILITY_PUBLIC); } $method->setStatic($reflectionMethod->isStatic()); $method->setName($reflectionMethod->getName()); foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $method->setParameter(Zend_CodeGenerator_Php_Parameter::fromReflection($reflectionParameter)); } $method->setBody($reflectionMethod->getBody()); $method->_reflection = true; return $method; }
/** * @group ZF-10870 */ public function testGetBodyReturnsCorrectBodyWhenMethodSignatureAndBodyAreOnSameLine() { $body = 'return true;'; $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass7', 'testInlineMethod'); $this->assertEquals($body, $reflectionMethod->getBody()); }
public function testGetContentsReturnsCorrectContent() { $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass5', 'doSomething'); $this->assertEquals(" {\n\n return 'mixedValue';\n\n }\n", $reflectionMethod->getContents(false)); }
public static function fromReflection(Zend_Reflection_Method $reflectionMethod) { $method = new self(); $method->setSourceContent($reflectionMethod->getContents(false)); $method->setSourceDirty(false); if ($reflectionMethod->getDocComment() != '') { $method->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($reflectionMethod->getDocblock())); } $method->setFinal($reflectionMethod->isFinal()); if ($reflectionMethod->isPrivate()) { $method->setVisibility(self::VISIBILITY_PRIVATE); } elseif ($reflectionMethod->isProtected()) { $method->setVisibility(self::VISIBILITY_PROTECTED); } else { $method->setVisibility(self::VISIBILITY_PUBLIC); } $method->setStatic($reflectionMethod->isStatic()); $method->setName($reflectionMethod->getName()); foreach ($reflectionMethod->getParameters() as $reflectionParameter) { $method->setParameter(Zend_CodeGenerator_Php_Parameter::fromReflection($reflectionParameter)); } $body = $reflectionMethod->getBody(); $body2 = str_replace("\n\n", "\n", $body); $body2 = preg_replace("|^\n\\s{4}|muU", "\n", $body2); $body2 = preg_replace("|^\\s{4}|muU", "", $body2); // $body2 = str_replace(' ', '.', $body2); //dmDebug::kill($body, "\n".$body2); $method->setBody($body2); return $method; }
public function testModel() { return; /// Load Models $ModelsDir = new Directory('../freebox/api/v3/models/'); $ModelFiles = $ModelsDir->getFilesByExtension('php', true); foreach ($ModelFiles as $modelFile) { require_once $modelFile; } /// Get Model subClasses $LoadedClasses = get_declared_classes(); $ModelClasses = []; foreach ($LoadedClasses as $loadedClass) { if (is_subclass_of($loadedClass, Model::class)) { $ModelClasses[] = $loadedClass; } } /// Test classes foreach ($ModelClasses as $modelClass) { $ModelReflect = new \ReflectionClass($modelClass); $ClassArgs = []; $properties = $ModelReflect->getProperties(); foreach ($properties as $property) { $ClassArgs[$property->getName()] = ''; } $Model = new $modelClass($ClassArgs); $methods = $ModelReflect->getMethods(); foreach ($methods as $method) { $method = new \Zend_Reflection_Method($Model, $method->getName()); $docBlock = $method->getDocblock(); echo "--" . PHP_EOL; echo "{$modelClass} " . $method->getName() . PHP_EOL; if (!$method->isPublic()) { continue; } $args = []; if ($docBlock->hasTag('param')) { /** @var \Zend_Reflection_Docblock_Tag_Param[] $tagParams */ $tagParams = $docBlock->getTags('param'); // $tagReturn is an instance of Zend_Reflection_Docblock_Tag_Return foreach ($tagParams as $tagParam) { echo "Param Type : " . $tagParam->getType() . PHP_EOL; switch ($tagParam->getType()) { case 'string': $args[] = $tagParam->getName(); break; case 'bool': case 'boolean': $args[] = true; break; case 'array': $args[] = []; break; default: print_r($tagParam); return; } } } $a = $method->invokeArgs($Model, $args); if ($docBlock->hasTag('return')) { /** @var \Zend_Reflection_Docblock_Tag_Return $tagReturn */ $tagReturn = $docBlock->getTag('return'); echo "Returns a: " . $tagReturn->getType() . PHP_EOL; $this->assertInternalType($tagReturn->getType(), $a); /* switch( $tagReturn->getType()){ case 'string' : $this->assertInternalType( string); break; case 'bool': case 'boolean': $args[] = true; break; case 'array' : $args[] = []; break; default : print_r( $tagParam); return; } */ } } } }