Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public function testGetBodyReturnsCorrectBody()
 {
     $body = '        //we need a multi-line method body.
     $assigned = 1;
     $alsoAssigined = 2;
     return \'mixedValue\';';
     $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass6', 'doSomething');
     $this->assertEquals($body, $reflectionMethod->getBody());
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * @group ZF-10870
  */
 public function testGetBodyReturnsCorrectBodyWhenMethodSignatureAndBodyAreOnSameLine()
 {
     $body = 'return true;';
     $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass7', 'testInlineMethod');
     $this->assertEquals($body, $reflectionMethod->getBody());
 }