當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassReflection::getContents方法代碼示例

本文整理匯總了PHP中Zend\Code\Reflection\ClassReflection::getContents方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassReflection::getContents方法的具體用法?PHP ClassReflection::getContents怎麽用?PHP ClassReflection::getContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Code\Reflection\ClassReflection的用法示例。


在下文中一共展示了ClassReflection::getContents方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: dumpClass

 /**
  * Returns class' code inside namespace
  *
  * @param ClassReflection $class
  */
 private function dumpClass(ClassReflection $class)
 {
     if (array_search($class->getName(), $this->cachedClasses) !== false) {
         return;
     }
     if ($class->isInternal()) {
         return;
     }
     if ($class->getParentClass()) {
         $this->dumpClass($class->getParentClass());
     }
     foreach ($class->getInterfaces() as $interface) {
         $this->dumpClass($interface);
     }
     if ($class->getTraits()) {
         foreach ($class->getTraits() as $trait) {
             $this->dumpClass($trait);
         }
     }
     $classContents = $class->getContents(false);
     $classFileDir = dirname($class->getFileName());
     $classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents));
     $uses = implode("\n", $this->codeGenerator->getUseLines($class));
     $this->cache[] = "namespace " . $class->getNamespaceName() . " {\n" . ($uses ? $uses . "\n" : '') . $this->codeGenerator->getDeclarationLine($class) . "\n" . $classContents . "\n}\n";
     $this->cachedClasses[] = $class->getName();
 }
開發者ID:mtymek,項目名稱:class-dumper,代碼行數:31,代碼來源:ClassDumper.php

示例2: getCacheCode

 /**
  * Generate code to cache from class reflection.
  * This is a total mess, I know. Just wanted to flesh out the logic.
  *
  * @todo Refactor into a class, clean up logic, DRY it up, maybe move
  *       some of this into Zend\Code
  * @param  ClassReflection $r
  * @return string
  */
 protected static function getCacheCode(ClassReflection $r)
 {
     $useString = '';
     $usesNames = array();
     if (count($uses = $r->getDeclaringFile()->getUses())) {
         foreach ($uses as $use) {
             $usesNames[$use['use']] = $use['as'];
             $useString .= "use {$use['use']}";
             if ($use['as']) {
                 $useString .= " as {$use['as']}";
             }
             $useString .= ";\n";
         }
     }
     $declaration = '';
     if ($r->isAbstract() && !$r->isInterface()) {
         $declaration .= 'abstract ';
     }
     if ($r->isFinal()) {
         $declaration .= 'final ';
     }
     if ($r->isInterface()) {
         $declaration .= 'interface ';
     }
     if (!$r->isInterface()) {
         $declaration .= 'class ';
     }
     $declaration .= $r->getShortName();
     $parentName = false;
     if (($parent = $r->getParentClass()) && $r->getNamespaceName()) {
         $parentName = array_key_exists($parent->getName(), $usesNames) ? $usesNames[$parent->getName()] ?: $parent->getShortName() : (0 === strpos($parent->getName(), $r->getNamespaceName()) ? substr($parent->getName(), strlen($r->getNamespaceName()) + 1) : '\\' . $parent->getName());
     } else {
         if ($parent && !$r->getNamespaceName()) {
             $parentName = '\\' . $parent->getName();
         }
     }
     if ($parentName) {
         $declaration .= " extends {$parentName}";
     }
     $interfaces = array_diff($r->getInterfaceNames(), $parent ? $parent->getInterfaceNames() : array());
     if (count($interfaces)) {
         foreach ($interfaces as $interface) {
             $iReflection = new ClassReflection($interface);
             $interfaces = array_diff($interfaces, $iReflection->getInterfaceNames());
         }
         $declaration .= $r->isInterface() ? ' extends ' : ' implements ';
         $declaration .= implode(', ', array_map(function ($interface) use($usesNames, $r) {
             $iReflection = new ClassReflection($interface);
             return array_key_exists($iReflection->getName(), $usesNames) ? $usesNames[$iReflection->getName()] ?: $iReflection->getShortName() : (0 === strpos($iReflection->getName(), $r->getNamespaceName()) ? substr($iReflection->getName(), strlen($r->getNamespaceName()) + 1) : '\\' . $iReflection->getName());
         }, $interfaces));
     }
     $classContents = $r->getContents(false);
     $classFileDir = dirname($r->getFileName());
     $classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents));
     $return = "\nnamespace " . $r->getNamespaceName() . " {\n" . $useString . $declaration . "\n" . $classContents . "\n}\n";
     return $return;
 }
開發者ID:andreas-serlo,項目名稱:athene2,代碼行數:66,代碼來源:Module.php

示例3: buildContent

 /**
  * Build the content of the class
  * It replace the __DIR__ constant with the class directoryname
  *
  * @param Reflection\ClassReflection $class
  * @return string
  */
 protected function buildContent(Reflection\ClassReflection $class)
 {
     $code = $class->getContents(false);
     $classDir = dirname($class->getFileName());
     $code = str_replace('__DIR__', "'{$classDir}'", $code);
     return $code;
 }
開發者ID:jdolieslager,項目名稱:celeritas,代碼行數:14,代碼來源:Cacher.php

示例4: testGetContentsReturnsContents

    public function testGetContentsReturnsContents()
    {
        $reflectionClass = new ClassReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass2');
        $target = <<<EOS
{

    protected \$_prop1 = null;
    protected \$_prop2 = null;

    public function getProp1()
    {
        return \$this->_prop1;
    }

    public function getProp2(\$param1, TestSampleClass \$param2)
    {
        return \$this->_prop2;
    }

    public function getIterator()
    {
        return array();
    }

}
EOS;
        $this->assertEquals($target, $reflectionClass->getContents());
    }
開發者ID:bradley-holt,項目名稱:zf2,代碼行數:28,代碼來源:ClassReflectionTest.php

示例5: testGetContentsReturnsContentsWithImplementsOnSeparateLine

    public function testGetContentsReturnsContentsWithImplementsOnSeparateLine()
    {
        $reflectionClass = new ClassReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass9');
        $target = <<<EOS
{
    protected \$_prop1 = null;

    /**
     * @Sample({"foo":"bar"})
     */
    protected \$_prop2 = null;

    public function getProp1()
    {
        return \$this->_prop1;
    }

    public function getProp2(\$param1, TestSampleClass \$param2)
    {
        return \$this->_prop2;
    }

    public function getIterator()
    {
        return array();
    }

}
EOS;
        $contents = $reflectionClass->getContents();
        $this->assertEquals(trim($target), trim($contents));
    }
開發者ID:haoyanfei,項目名稱:zf2,代碼行數:32,代碼來源:ClassReflectionTest.php

示例6: testGetContentsReturnsEmptyContentsOnInternalCode

 public function testGetContentsReturnsEmptyContentsOnInternalCode()
 {
     $reflectionClass = new ClassReflection('ReflectionClass');
     $this->assertSame('', $reflectionClass->getContents());
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:5,代碼來源:ClassReflectionTest.php


注:本文中的Zend\Code\Reflection\ClassReflection::getContents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。