예제 #1
0
파일: Method.php 프로젝트: theolymp/diem
 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;
 }
예제 #2
0
 /**
  * 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());
     return $method;
 }
예제 #3
0
 /**
  * @dataProvider dataFromReflection_Generate
  * @param string $methodName
  * @param string $expectedCode
  */
 public function testFromReflection_Generate($methodName, $expectedCode)
 {
     $reflParam = $this->getFirstReflectionParameter($methodName);
     $codeGenParam = Zend_CodeGenerator_Php_Parameter::fromReflection($reflParam);
     $this->assertEquals($expectedCode, $codeGenParam->generate());
 }