当前位置: 首页>>代码示例>>PHP>>正文


PHP Reflection\ClassReflection类代码示例

本文整理汇总了PHP中Zend\Code\Reflection\ClassReflection的典型用法代码示例。如果您正苦于以下问题:PHP ClassReflection类的具体用法?PHP ClassReflection怎么用?PHP ClassReflection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClassReflection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testToString

 public function testToString()
 {
     $classReflection = new ClassReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass5');
     $classDocBlock = $classReflection->getDocBlock();
     $expectedString = 'DocBlock [ /* DocBlock */ ] {' . PHP_EOL . PHP_EOL . '  - Tags [3] {' . PHP_EOL . '    DocBlock Tag [ * @author ]' . PHP_EOL . '    DocBlock Tag [ * @method ]' . PHP_EOL . '    DocBlock Tag [ * @property ]' . PHP_EOL . '  }' . PHP_EOL . '}' . PHP_EOL;
     $this->assertEquals($expectedString, (string) $classDocBlock);
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:7,代码来源:DocBlockReflectionTest.php

示例2: fromReflection

 /**
  * Build a Code Generation Php Object from a Class Reflection
  *
  * @param  ClassReflection $classReflection
  * @return InterfaceGenerator
  */
 public static function fromReflection(ClassReflection $classReflection)
 {
     if (!$classReflection->isInterface()) {
         throw new Exception\InvalidArgumentException(sprintf('Class %s is not a interface', $classReflection->getName()));
     }
     // class generator
     $cg = new static($classReflection->getName());
     $methods = [];
     $cg->setSourceContent($cg->getSourceContent());
     $cg->setSourceDirty(false);
     if ($classReflection->getDocComment() != '') {
         $cg->setDocBlock(DocBlockGenerator::fromReflection($classReflection->getDocBlock()));
     }
     // set the namespace
     if ($classReflection->inNamespace()) {
         $cg->setNamespaceName($classReflection->getNamespaceName());
     }
     foreach ($classReflection->getMethods() as $reflectionMethod) {
         $className = $cg->getNamespaceName() ? $cg->getNamespaceName() . '\\' . $cg->getName() : $cg->getName();
         if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
             $methods[] = MethodGenerator::fromReflection($reflectionMethod);
         }
     }
     foreach ($classReflection->getConstants() as $name => $value) {
         $cg->addConstant($name, $value);
     }
     $cg->addMethods($methods);
     return $cg;
 }
开发者ID:basuritas-php,项目名称:zend-code,代码行数:35,代码来源:InterfaceGenerator.php

示例3: testAllowsMultipleParsingStrategies

 public function testAllowsMultipleParsingStrategies()
 {
     $genericParser = new Annotation\Parser\GenericAnnotationParser();
     $genericParser->registerAnnotation(__NAMESPACE__ . '\\TestAsset\\Foo');
     $doctrineParser = new Annotation\Parser\DoctrineAnnotationParser();
     $doctrineParser->registerAnnotation(__NAMESPACE__ . '\\TestAsset\\DoctrineAnnotation');
     $this->manager->attach($genericParser);
     $this->manager->attach($doctrineParser);
     $reflection = new Reflection\ClassReflection(__NAMESPACE__ . '\\TestAsset\\EntityWithMixedAnnotations');
     $prop = $reflection->getProperty('test');
     $annotations = $prop->getAnnotations($this->manager);
     $this->assertTrue($annotations->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\Foo'));
     $this->assertTrue($annotations->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\DoctrineAnnotation'));
     $this->assertFalse($annotations->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\Bar'));
     foreach ($annotations as $annotation) {
         switch (get_class($annotation)) {
             case __NAMESPACE__ . '\\TestAsset\\Foo':
                 $this->assertEquals('first', $annotation->content);
                 break;
             case __NAMESPACE__ . '\\TestAsset\\DoctrineAnnotation':
                 $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $annotation->value);
                 break;
             default:
                 $this->fail('Received unexpected annotation "' . get_class($annotation) . '"');
         }
     }
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:27,代码来源:AnnotationManagerTest.php

示例4: addContent

 /**
  * Generate view content
  *
  * @param string          $moduleName
  * @param ClassReflection $loadedEntity
  */
 protected function addContent($moduleName, ClassReflection $loadedEntity)
 {
     // prepare some params
     $moduleIdentifier = $this->filterCamelCaseToUnderscore($moduleName);
     $entityName = $loadedEntity->getShortName();
     $entityParam = lcfirst($entityName);
     $formParam = lcfirst(str_replace('Entity', '', $loadedEntity->getShortName())) . 'DataForm';
     $moduleRoute = $this->filterCamelCaseToDash($moduleName);
     // set action body
     $body = [];
     $body[] = 'use ' . $loadedEntity->getName() . ';';
     $body[] = '';
     $body[] = '/** @var ' . $entityName . ' $' . $entityParam . ' */';
     $body[] = '$' . $entityParam . ' = $this->' . $entityParam . ';';
     $body[] = '';
     $body[] = '$this->h1(\'' . $moduleIdentifier . '_title_update\');';
     $body[] = '';
     $body[] = '$this->' . $formParam . '->setAttribute(\'action\', $this->url(\'' . $moduleRoute . '/update\', [\'id\' => $' . $entityParam . '->getIdentifier()]));';
     $body[] = '';
     $body[] = 'echo $this->bootstrapForm($this->' . $formParam . ');';
     $body[] = '?>';
     $body[] = '<p>';
     $body[] = '    <a class="btn btn-primary" href="<?php echo $this->url(\'' . $moduleRoute . '\'); ?>">';
     $body[] = '        <i class="fa fa-table"></i>';
     $body[] = '        <?php echo $this->translate(\'' . $moduleIdentifier . '_action_index\'); ?>';
     $body[] = '    </a>';
     $body[] = '</p>';
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // add method
     $this->setContent($body);
 }
开发者ID:zfrapid,项目名称:zf2rapid,代码行数:37,代码来源:UpdateActionViewGenerator.php

示例5: getCacheCode

 /**
  * Generate code to cache from class reflection.
  *
  * @todo maybe move some of this into Zend\Code
  *
  * @param  ClassReflection $classReflection
  * @return string
  */
 public function getCacheCode(ClassReflection $classReflection)
 {
     $useString = $this->fileReflectionService->getUseString($classReflection->getDeclaringFile());
     $declaration = $this->classDeclarationService->getClassDeclaration($classReflection);
     $classContents = $classReflection->getContents(false);
     $classFileDir = dirname($classReflection->getFileName());
     $classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents));
     $return = "\nnamespace " . $classReflection->getNamespaceName() . " {\n" . $useString . $declaration . "\n" . $classContents . "\n}\n";
     return $return;
 }
开发者ID:berturion,项目名称:EdpSuperluminal,代码行数:18,代码来源:CacheCodeGenerator.php

示例6: getAnnotations

 /**
  * @return AnnotationCollection
  */
 public function getAnnotations()
 {
     $reflection = new ClassReflection($this->getObject());
     try {
         $reflectionMethod = $reflection->getMethod($this->getMethod());
         return $reflectionMethod->getAnnotations($this->getAnnotationManager());
     } catch (\ReflectionException $e) {
         return false;
     }
 }
开发者ID:gontero,项目名称:gontero-acl,代码行数:13,代码来源:Annotation.php

示例7: isSatisfiedBy

 /**
  * @param ClassReflection $class
  * @return bool
  */
 public function isSatisfiedBy(ClassReflection $class)
 {
     $docBlock = $class->getDocBlock();
     if ($docBlock) {
         if ($docBlock->getTags('Annotation')) {
             return true;
         }
     }
     return false;
 }
开发者ID:simon-barton,项目名称:EdpSuperluminal,代码行数:14,代码来源:IsAnAnnotatedClass.php

示例8: fromReflection

 /**
  * Build a Code Generation Php Object from a Class Reflection
  *
  * @param  ClassReflection $classReflection
  * @return TraitGenerator
  */
 public static function fromReflection(ClassReflection $classReflection)
 {
     // class generator
     $cg = new static($classReflection->getName());
     $cg->setSourceContent($cg->getSourceContent());
     $cg->setSourceDirty(false);
     if ($classReflection->getDocComment() != '') {
         $cg->setDocBlock(DocBlockGenerator::fromReflection($classReflection->getDocBlock()));
     }
     // set the namespace
     if ($classReflection->inNamespace()) {
         $cg->setNamespaceName($classReflection->getNamespaceName());
     }
     $properties = array();
     foreach ($classReflection->getProperties() as $reflectionProperty) {
         if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
             $properties[] = PropertyGenerator::fromReflection($reflectionProperty);
         }
     }
     $cg->addProperties($properties);
     $methods = array();
     foreach ($classReflection->getMethods() as $reflectionMethod) {
         $className = $cg->getNamespaceName() ? $cg->getNamespaceName() . '\\' . $cg->getName() : $cg->getName();
         if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
             $methods[] = MethodGenerator::fromReflection($reflectionMethod);
         }
     }
     $cg->addMethods($methods);
     return $cg;
 }
开发者ID:Flesh192,项目名称:magento,代码行数:36,代码来源:TraitGenerator.php

示例9: addContent

 /**
  * Generate view content
  *
  * @param string          $moduleName
  * @param ClassReflection $loadedEntity
  */
 protected function addContent($moduleName, ClassReflection $loadedEntity)
 {
     // prepare some params
     $moduleIdentifier = $this->filterCamelCaseToUnderscore($moduleName);
     $entityName = $loadedEntity->getShortName();
     $entityParam = lcfirst($entityName);
     $listParam = lcfirst(str_replace('Entity', '', $entityName)) . 'List';
     $moduleRoute = $this->filterCamelCaseToDash($moduleName);
     // set action body
     $body = [];
     $body[] = 'use ' . $loadedEntity->getName() . ';';
     $body[] = '';
     $body[] = '$this->h1(\'' . $moduleIdentifier . '_title_index\');';
     $body[] = '?>';
     $body[] = '<table class="table table-bordered table-striped">';
     $body[] = '    <thead>';
     $body[] = '    <tr>';
     foreach ($loadedEntity->getProperties() as $property) {
         $body[] = '        <th><?php echo $this->translate(\'' . $moduleIdentifier . '_label_' . $this->filterCamelCaseToUnderscore($property->getName()) . '\'); ?></th>';
     }
     $body[] = '        <th width="95">';
     $body[] = '            <a class="btn btn-default btn-xs" href="<?php echo $this->url(\'' . $moduleRoute . '/create\'); ?>" title="<?php echo $this->translate(\'' . $moduleIdentifier . '_action_create\'); ?>">';
     $body[] = '                <i class="fa fa-plus"></i>';
     $body[] = '            </a>';
     $body[] = '        </th>';
     $body[] = '    </tr>';
     $body[] = '    </thead>';
     $body[] = '    <tbody>';
     $body[] = '    <?php /** @var ' . $entityName . ' $' . $entityParam . ' */ ?>';
     $body[] = '    <?php foreach ($this->' . $listParam . ' as $' . $entityParam . '): ?>';
     $body[] = '        <tr>';
     foreach ($loadedEntity->getProperties() as $property) {
         $methodName = 'get' . ucfirst($property->getName());
         $body[] = '            <td><?php echo $' . $entityParam . '->' . $methodName . '() ?></td>';
     }
     $body[] = '            <td>';
     $body[] = '                <a class="btn btn-default btn-xs" href="<?php echo $this->url(\'' . $moduleRoute . '/show\', [\'id\' => $' . $entityParam . '->getIdentifier()]); ?>" title="<?php echo $this->translate(\'' . $moduleIdentifier . '_action_show\'); ?>">';
     $body[] = '                    <i class="fa fa-search"></i>';
     $body[] = '                </a>';
     $body[] = '                <a class="btn btn-default btn-xs" href="<?php echo $this->url(\'' . $moduleRoute . '/update\', [\'id\' => $' . $entityParam . '->getIdentifier()]); ?>" title="<?php echo $this->translate(\'' . $moduleIdentifier . '_action_update\'); ?>">';
     $body[] = '                    <i class="fa fa-pencil"></i>';
     $body[] = '                </a>';
     $body[] = '                <a class="btn btn-default btn-xs" href="<?php echo $this->url(\'' . $moduleRoute . '/delete\', [\'id\' => $' . $entityParam . '->getIdentifier()]); ?>" title="<?php echo $this->translate(\'' . $moduleIdentifier . '_action_delete\'); ?>">';
     $body[] = '                    <i class="fa fa-trash"></i>';
     $body[] = '                </a>';
     $body[] = '            </td>';
     $body[] = '        </tr>';
     $body[] = '    <?php endforeach; ?>';
     $body[] = '    </tbody>';
     $body[] = '</table>';
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // add method
     $this->setContent($body);
 }
开发者ID:zfrapid,项目名称:zf2rapid,代码行数:60,代码来源:IndexActionViewGenerator.php

示例10: shouldSkip

 private function shouldSkip(ClassReflection $class)
 {
     if ($class->isInternal()) {
         return true;
     }
     foreach ($this->skip as $prefix) {
         if (strpos($class->getName(), $prefix) === 0) {
             return true;
         }
     }
     return false;
 }
开发者ID:mtymek,项目名称:class-dumper,代码行数:12,代码来源:ConfigGenerator.php

示例11: getParentName

 private function getParentName(ClassReflection $classReflection)
 {
     $parentName = false;
     if (($parent = $classReflection->getParentClass()) && $classReflection->getNamespaceName()) {
         $parentName = $this->classUseNameService->getClassUseName($classReflection, $parent);
     } else {
         if ($parent && !$classReflection->getNamespaceName()) {
             $parentName = '\\' . $parent->getName();
         }
     }
     return $parentName;
 }
开发者ID:simon-barton,项目名称:EdpSuperluminal,代码行数:12,代码来源:ExtendsStatementService.php

示例12: processCommandTask

 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // initialize action list
     $loadedActions = [];
     // loop through controllers by module
     foreach ($this->params->loadedControllers as $moduleKey => $controllerTypes) {
         $loadedActions[$moduleKey] = [];
         $moduleViewPath = $this->filterCamelCaseToDash($moduleKey);
         // loop through controllers by controller type
         foreach ($controllerTypes as $controllerList) {
             // loop through controllers
             foreach ($controllerList as $controllerKey => $controllerClass) {
                 $loadedActions[$moduleKey][$controllerKey] = [];
                 // start class reflection
                 $classReflection = new ClassReflection($controllerClass);
                 // convert method name to get dashed action
                 $controllerName = substr($classReflection->getShortName(), 0, -10);
                 $controllerName = $this->filterCamelCaseToDash($controllerName);
                 // get public methods
                 $methods = $classReflection->getMethods(ReflectionMethod::IS_PUBLIC);
                 // loop through methods
                 foreach ($methods as $method) {
                     // get class and method name
                     $methodClass = $method->getDeclaringClass()->getName();
                     $methodName = $method->name;
                     // continue for methods from extended class
                     if ($methodClass != $controllerClass) {
                         continue;
                     }
                     // continue for no-action methods
                     if (substr($methodName, -6) != 'Action') {
                         continue;
                     }
                     // convert method name to get dashed action
                     $actionName = substr($methodName, 0, -6);
                     $actionName = $this->filterCamelCaseToDash($actionName);
                     // build action file
                     $actionFile = '/module/' . $moduleKey . '/view/' . $moduleViewPath . '/' . $controllerName . '/' . $actionName . '.phtml';
                     // check action file exists
                     if (!file_exists($this->params->workingPath . $actionFile)) {
                         $actionFile = false;
                     }
                     // add action to list
                     $loadedActions[$moduleKey][$controllerKey][$actionName] = $actionFile;
                 }
             }
         }
     }
     // set loaded modules
     $this->params->loadedActions = $loadedActions;
     return 0;
 }
开发者ID:pgiacometto,项目名称:zf2rapid,代码行数:57,代码来源:LoadActions.php

示例13: __invoke

 /**
  * @inheritDoc
  */
 public function __invoke($fcqn, $namespace, $commandName)
 {
     $commandName = ucfirst($commandName);
     $reflectionClass = new ClassReflection($fcqn);
     $fileGenerator = FileGenerator::fromReflectedFileName($reflectionClass->getFileName());
     $fileGenerator->setFilename($reflectionClass->getFileName());
     $fileGenerator->setUse(ltrim($namespace, '\\') . '\\' . $commandName);
     $classGenerator = $fileGenerator->getClass();
     // workaround for import namespace
     if ($classToExtend = $classGenerator->getExtendedClass()) {
         $classGenerator->setExtendedClass(substr($classToExtend, strrpos($classToExtend, '\\') + 1));
     }
     $classGenerator->addMethodFromGenerator($this->methodWhenEvent($commandName));
     return $fileGenerator;
 }
开发者ID:sandrokeil,项目名称:prooph-cli,代码行数:18,代码来源:AddEventToAggregate.php

示例14: addContent

 /**
  * Generate view content
  *
  * @param string          $moduleName
  * @param ClassReflection $loadedEntity
  */
 protected function addContent($moduleName, ClassReflection $loadedEntity)
 {
     // prepare some params
     $moduleIdentifier = $this->filterCamelCaseToUnderscore($moduleName);
     $entityName = $loadedEntity->getShortName();
     $entityParam = lcfirst($entityName);
     $formParam = lcfirst(str_replace('Entity', '', $loadedEntity->getShortName())) . 'DeleteForm';
     $moduleRoute = $this->filterCamelCaseToDash($moduleName);
     $deleteMessage = $moduleRoute . '_message_' . $moduleRoute . '_deleting_possible';
     // set action body
     $body = [];
     $body[] = 'use ' . $loadedEntity->getName() . ';';
     $body[] = '';
     $body[] = '/** @var ' . $entityName . ' $' . $entityParam . ' */';
     $body[] = '$' . $entityParam . ' = $this->' . $entityParam . ';';
     $body[] = '';
     $body[] = '$this->h1(\'' . $moduleIdentifier . '_title_delete\');';
     $body[] = '';
     $body[] = '$this->' . $formParam . '->setAttribute(\'action\', $this->url(\'' . $moduleRoute . '/delete\', [\'id\' => $' . $entityParam . '->getIdentifier()]));';
     $body[] = '';
     $body[] = '?>';
     $body[] = '<div class="well">';
     $body[] = '    <table class="table">';
     $body[] = '        <tbody>';
     foreach ($loadedEntity->getProperties() as $property) {
         $methodName = 'get' . ucfirst($property->getName());
         $body[] = '            <tr>';
         $body[] = '                <th class="col-sm-2 text-right"><?php echo $this->translate(\'' . $moduleIdentifier . '_label_' . $this->filterCamelCaseToUnderscore($property->getName()) . '\'); ?></th>';
         $body[] = '                <td class="col-sm-10"><?php echo $' . $entityParam . '->' . $methodName . '() ?></td>';
         $body[] = '            </tr>';
     }
     $body[] = '            <tr>';
     $body[] = '                <th class="col-sm-2 text-right">&nbsp;</th>';
     $body[] = '                <td class="col-sm-10"><?php echo $this->form($this->' . $formParam . '); ?></td>';
     $body[] = '            </tr>';
     $body[] = '        </tbody>';
     $body[] = '    </table>';
     $body[] = '</div>';
     $body[] = '<p>';
     $body[] = '    <a class="btn btn-primary" href="<?php echo $this->url(\'' . $moduleRoute . '\'); ?>">';
     $body[] = '        <i class="fa fa-table"></i>';
     $body[] = '        <?php echo $this->translate(\'' . $moduleIdentifier . '_action_index\'); ?>';
     $body[] = '    </a>';
     $body[] = '</p>';
     $body = implode(AbstractGenerator::LINE_FEED, $body);
     // add method
     $this->setContent($body);
 }
开发者ID:zfrapid,项目名称:zf2rapid,代码行数:54,代码来源:DeleteActionViewGenerator.php

示例15: getClassUseName

 public function getClassUseName(ClassReflection $currentClass, ClassReflection $useClass)
 {
     $useNames = $this->fileReflectionUseStatementService->getUseNames($currentClass->getDeclaringFile());
     $fullUseClassName = $useClass->getName();
     $classUseName = null;
     if (array_key_exists($fullUseClassName, $useNames)) {
         $classUseName = $useNames[$fullUseClassName] ?: $useClass->getShortName();
     } else {
         if (0 === strpos($fullUseClassName, $currentClass->getNamespaceName())) {
             $classUseName = substr($fullUseClassName, strlen($currentClass->getNamespaceName()) + 1);
         } else {
             $classUseName = '\\' . $fullUseClassName;
         }
     }
     return $classUseName;
 }
开发者ID:simon-barton,项目名称:EdpSuperluminal,代码行数:16,代码来源:ClassUseNameService.php


注:本文中的Zend\Code\Reflection\ClassReflection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。