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


PHP ReflectionClass::isTrait方法代码示例

本文整理汇总了PHP中ReflectionClass::isTrait方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::isTrait方法的具体用法?PHP ReflectionClass::isTrait怎么用?PHP ReflectionClass::isTrait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionClass的用法示例。


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

示例1: exportCode

 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $code_lines = array();
     $code_lines[] = '<?php';
     // Export the namespace
     if ($this->_reflection_class->getNamespaceName()) {
         $code_lines[] = '';
         $code_lines[] = 'namespace ' . $this->_reflection_class->getNamespaceName() . ';';
         $code_lines[] = '';
     }
     // Export the class' signature
     $code_lines[] = sprintf('%s%s%s %s%s%s', $this->_reflection_class->isAbstract() ? 'abstract ' : '', $this->_reflection_class->isFinal() ? 'final ' : '', $this->_reflection_class->isInterface() ? 'interface' : ($this->_reflection_class->isTrait() ? 'trait' : 'class'), $this->getClassName(), $this->_getParentClassName() ? " extends {$this->_getParentClassName()}" : '', $this->_getInterfaceNames() ? " implements " . join(', ', $this->_getInterfaceNames()) : '');
     $code_lines[] = '{';
     $code_lines[] = '';
     // Export constants
     foreach ($this->_reflection_class->getConstants() as $name => $value) {
         $reflection_constant = new ReflectionConstant($name, $value);
         $code_lines[] = "\t" . $reflection_constant->exportCode();
         $code_lines[] = '';
     }
     // Export properties
     foreach ($this->_reflection_class->getProperties() as $property) {
         $reflection_property = new ReflectionProperty($property);
         $code_lines[] = "\t" . $reflection_property->exportCode();
         $code_lines[] = '';
     }
     // Export methods
     foreach ($this->_reflection_class->getMethods() as $method) {
         $reflection_method = new ReflectionMethod($method);
         $code_lines[] = "\t" . $reflection_method->exportCode();
         $code_lines[] = '';
     }
     $code_lines[] = '}';
     return join("\n", $code_lines);
 }
开发者ID:michalkoslab,项目名称:Helpers,代码行数:40,代码来源:ReflectionClass.php

示例2: getType

 /**
  * Get current object type
  * @return string  - class/trait/interface
  */
 public function getType()
 {
     if ($this->reflectionClass->isInterface()) {
         return 'interface';
     }
     if (method_exists($this->reflectionClass, 'isTrait') && $this->reflectionClass->isTrait()) {
         return 'trait';
     }
     return 'class';
 }
开发者ID:vgrish,项目名称:dvelum,代码行数:14,代码来源:Analyzer.php

示例3: testClassIndex

 /**
  * @param \Donquixote\HastyReflectionCommon\Canvas\ClassIndex\ClassIndexInterface $classIndex
  * @param string $class
  *
  * @dataProvider provideClassIndexArgs()
  */
 function testClassIndex(ClassIndexInterface $classIndex, $class)
 {
     $classReflection = $classIndex->classGetReflection($class);
     $reflectionClass = new \ReflectionClass($class);
     // Test identity.
     $this->assertTrue($classReflection === $classIndex->classGetReflection($class));
     // Test class type/info.
     $expectedIsClass = !$reflectionClass->isInterface() && !$reflectionClass->isTrait();
     $this->assertEquals($reflectionClass->getName(), $classReflection->getName());
     $this->assertEquals($reflectionClass->getShortName(), $classReflection->getShortName());
     $this->assertEquals($reflectionClass->getDocComment(), $classReflection->getDocComment());
     $this->assertEquals($reflectionClass->isInterface(), $classReflection->isInterface());
     $this->assertEquals($reflectionClass->isTrait(), $classReflection->isTrait());
     $this->assertEquals($expectedIsClass, $classReflection->isClass());
     $this->assertEquals($reflectionClass->isAbstract() && $expectedIsClass, $classReflection->isAbstractClass());
     // Test context.
     $this->assertEquals($reflectionClass->getNamespaceName(), $classReflection->getNamespaceUseContext()->getNamespaceName());
     // Test interfaces
     foreach ($classReflection->getOwnInterfaces() as $interfaceName => $interfaceReflection) {
         $this->assertTrue($reflectionClass->implementsInterface($interfaceName));
     }
     foreach ($reflectionClass->getInterfaceNames() as $interfaceName) {
         $this->assertTrue($classReflection->extendsOrImplementsInterface($interfaceName, FALSE));
     }
     $expectedAllInterfaceNames = $expectedAllAndSelfInterfaceNames = $reflectionClass->getInterfaceNames();
     if ($reflectionClass->isInterface()) {
         array_unshift($expectedAllAndSelfInterfaceNames, $class);
     }
     $this->assertEqualSorted($expectedAllAndSelfInterfaceNames, array_keys($classReflection->getAllInterfaces(TRUE)));
     $this->assertEqualSorted($expectedAllInterfaceNames, array_keys($classReflection->getAllInterfaces(FALSE)));
     $expectedMethodNames = array();
     $expectedOwnMethodNames = array();
     foreach ($reflectionClass->getMethods() as $method) {
         $expectedMethodNames[] = $method->getName();
         if ($method->getDeclaringClass()->getName() === $reflectionClass->getName()) {
             $expectedOwnMethodNames[] = $method->getName();
         }
     }
     $this->assertEquals($expectedOwnMethodNames, array_keys($classReflection->getOwnMethods()));
     $this->assertEqualSorted($expectedMethodNames, array_keys($classReflection->getMethods()));
     $methodReflections = $classReflection->getMethods();
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         $methodReflection = $methodReflections[$reflectionMethod->getShortName()];
         $this->assertEqualMethods($reflectionMethod, $methodReflection);
     }
     // isAbstract() is a beast, so we test it least.
     $this->assertEquals($reflectionClass->isAbstract(), $classReflection->isAbstract());
 }
开发者ID:donquixote,项目名称:hasty-reflection-common,代码行数:54,代码来源:ClassIndexTest.php

示例4: run

 /**
  * Check if all classes given by the cli are instantiable.
  */
 public function run()
 {
     $classNames = array_keys($this->_args);
     //No classes given
     if (!$classNames) {
         exit(1);
     }
     //Perform single checks for the classes
     foreach ($classNames as $className) {
         $reflectionClass = new ReflectionClass($className);
         //Is an interface?
         if ($reflectionClass->isInterface()) {
             echo "Interface";
             exit(1);
         }
         //Is an abstract class?
         if ($reflectionClass->isAbstract()) {
             echo "Abstract";
             exit(1);
         }
         //Is a trait?
         if ($reflectionClass->isTrait()) {
             echo "Trait";
             exit(1);
         }
         //Can create the class with new?
         if (!$reflectionClass->isInstantiable()) {
             echo "Not instantiable";
             exit(1);
         }
     }
     echo 'Done';
 }
开发者ID:Wohlie,项目名称:phpstorm-magento-mapper,代码行数:36,代码来源:instantiableTester.php

示例5: testUsesZfListenerAggregateTrait

 /**
  * @testdox Uses the ListenerAggregateTrait from the Zend Framework
  */
 public function testUsesZfListenerAggregateTrait()
 {
     $reflection = new \ReflectionClass('\\Core\\EventManager\\ListenerAggregateTrait');
     $traits = $reflection->getTraitNames();
     $this->assertTrue($reflection->isTrait());
     $this->assertEquals(['Zend\\EventManager\\ListenerAggregateTrait'], $traits);
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:10,代码来源:ListenerAggregateTraitTest.php

示例6: __construct

 public function __construct(\ReflectionClass $interface)
 {
     if (!$interface->isInterface() || $interface->isTrait()) {
         throw new \InvalidArgumentException('Only interfaces supported');
     }
     parent::__construct($interface);
 }
开发者ID:mfn,项目名称:php-analyzer,代码行数:7,代码来源:ReflectedInterface.php

示例7: from

 /**
  * @param  \ReflectionClass|string
  * @return self
  */
 public static function from($from)
 {
     $from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from);
     if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
         $class = new static('anonymous');
     } else {
         $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
     }
     $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
     $class->final = $from->isFinal() && $class->type === 'class';
     $class->abstract = $from->isAbstract() && $class->type === 'class';
     $class->implements = $from->getInterfaceNames();
     $class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
     if ($from->getParentClass()) {
         $class->extends = $from->getParentClass()->getName();
         $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
     }
     foreach ($from->getProperties() as $prop) {
         if ($prop->getDeclaringClass()->getName() === $from->getName()) {
             $class->properties[$prop->getName()] = Property::from($prop);
         }
     }
     foreach ($from->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() === $from->getName()) {
             $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
         }
     }
     return $class;
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:33,代码来源:ClassType.php

示例8: addTrait

 protected function addTrait($fqcn)
 {
     $added = new \ReflectionClass($fqcn);
     if (!$added->isTrait()) {
         throw new \LogicException("{$fqcn} is not a trait");
     }
     $this->traitList[] = $added;
 }
开发者ID:trismegiste,项目名称:php-is-magic,代码行数:8,代码来源:FrankenTrait.php

示例9: isTargeted

 /**
  * Check if given class targeted by locator.
  *
  * @param \ReflectionClass      $class
  * @param \ReflectionClass|null $target
  * @return bool
  */
 protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null)
 {
     if (empty($target)) {
         return true;
     }
     if (!$target->isTrait()) {
         //Target is interface or class
         return $class->isSubclassOf($target) || $class->getName() == $target->getName();
     }
     //Checking using traits
     return in_array($target->getName(), $this->getTraits($class->getName()));
 }
开发者ID:tuneyourserver,项目名称:components,代码行数:19,代码来源:ClassLocator.php

示例10: createFromReflectionClass

 public static function createFromReflectionClass(\ReflectionClass $class)
 {
     if ($class->isInterface()) {
         return new ReflectedInterface($class);
     } else {
         if ($class->isTrait()) {
             throw new \InvalidArgumentException('Traits are not supported');
         } else {
             return new ReflectedClass($class);
         }
     }
 }
开发者ID:mfn,项目名称:php-analyzer,代码行数:12,代码来源:ReflectedObject.php

示例11: getImmediateMethod

 /** Given the name of a method and a ReflectionClass, either returns a
     ReflectionMethod if the method was defined in that specific class, or
     returns false. */
 protected function getImmediateMethod($methodName, \ReflectionClass $class, \ReflectionClass &$instanceClass = null)
 {
     if ($this->includeTraits) {
         if ($class->isTrait()) {
             $methodName = $this->getTraitMethodPrefix($class) . $methodName;
         } else {
             $instanceClass = $class;
         }
     }
     $useClass = $instanceClass ?: $class;
     $method = $useClass->hasMethod($methodName) ? $useClass->getMethod($methodName) : false;
     return $method && $useClass->name === $method->getDeclaringClass()->name ? $method : false;
 }
开发者ID:bettrlife,项目名称:schmancy-oo,代码行数:16,代码来源:MethodCombinator.php

示例12: getPHPUnitMockObjectFor

 public function getPHPUnitMockObjectFor($className, array $methods)
 {
     $rc = new \ReflectionClass($className);
     $mockObject = null;
     if ($rc->isInterface()) {
         $mockObject = $this->testCase->getMockBuilder($className)->getMock();
     } elseif ($rc->isAbstract()) {
         $mockObject = $this->testCase->getMockBuilder($className)->disableOriginalConstructor()->setMethods($methods)->getMockForAbstractClass();
     } elseif ($rc->isTrait()) {
         $mockObject = $this->testCase->getMockBuilder($className)->disableOriginalConstructor()->setMethods($methods)->getMockForTrait();
     } else {
         $mockObject = $this->testCase->getMockBuilder($className)->disableOriginalConstructor()->disableOriginalClone()->disableArgumentCloning()->disallowMockingUnknownTypes()->getMock();
     }
     return $mockObject;
 }
开发者ID:lucatume,项目名称:function-mocker,代码行数:15,代码来源:InstanceForger.php

示例13: getDBALTypes

 /**
  * Get all DBAL types inside the $folder using the $namespace
  *
  * @param string $path The real path to the DBAL types directory
  *
  * @return array
  */
 protected function getDBALTypes($path)
 {
     //find for .php files and load automatically
     $finder = new Finder();
     $finder->files()->name('*.php')->in($path);
     $types = [];
     /** @var SplFileInfo $file */
     foreach ($finder as $file) {
         $class = ClassUtils::getFileClassName($file->getRealPath());
         $reflectionClass = new \ReflectionClass($class);
         if ($reflectionClass->isSubclassOf('Doctrine\\DBAL\\Types\\Type') && !$reflectionClass->isAbstract() && !$reflectionClass->isTrait()) {
             $name = $reflectionClass->newInstanceWithoutConstructor()->getName();
             $types[$name] = $reflectionClass->getName();
         }
     }
     return $types;
 }
开发者ID:rafrsr,项目名称:doctrine-extra-bundle,代码行数:24,代码来源:RafrsrDoctrineExtraExtension.php

示例14: actionExport

 public function actionExport($args)
 {
     printf("Exporting ORM structures...\n\n");
     $orm_dirs = \Gini\Core::pharFilePaths(CLASS_DIR, 'Gini/ORM');
     foreach ($orm_dirs as $orm_dir) {
         if (!is_dir($orm_dir)) {
             continue;
         }
         \Gini\File::eachFilesIn($orm_dir, function ($file) use($orm_dir) {
             $oname = strtolower(preg_replace('|.php$|', '', $file));
             if ($oname == 'object') {
                 return;
             }
             $class_name = '\\Gini\\ORM\\' . str_replace('/', '\\', $oname);
             // Check if it is abstract class
             $rc = new \ReflectionClass($class_name);
             if ($rc->isAbstract() || $rc->isTrait() || $rc->isInterface()) {
                 return;
             }
             printf("   %s\n", $oname);
             $o = \Gini\IoC::construct($class_name);
             $structure = $o->structure();
             // unset system fields
             unset($structure['id']);
             unset($structure['_extra']);
             $i = 1;
             $max = count($structure);
             foreach ($structure as $k => $v) {
                 if ($i == $max) {
                     break;
                 }
                 printf("   ├─ %s (%s)\n", $k, implode(',', array_map(function ($k, $v) {
                     return $v ? "{$k}:{$v}" : $k;
                 }, array_keys($v), $v)));
                 ++$i;
             }
             printf("   └─ %s (%s)\n\n", $k, implode(',', array_map(function ($k, $v) {
                 return $v ? "{$k}:{$v}" : $k;
             }, array_keys($v), $v)));
         });
     }
 }
开发者ID:iamfat,项目名称:gini,代码行数:42,代码来源:ORM.php

示例15: getExistingClasses

 /**
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getExistingClasses(array $paths) : array
 {
     $namespaceList = [];
     $classList = [];
     $list = [];
     foreach ($paths as $path) {
         if (false === $path->isSourceCode()) {
             continue;
         }
         $iter = new ClassIterator($this->getPhpFiles($path->getPathBase()));
         foreach (array_keys($iter->getClassMap()) as $classname) {
             if (in_array(substr($classname, -4), ['Test', 'Spec'])) {
                 continue;
             }
             $reflection = new \ReflectionClass($classname);
             if ($reflection->isAbstract() || $reflection->isTrait() || $reflection->isInterface()) {
                 continue;
             }
             if ($reflection->inNamespace()) {
                 $namespaces = explode('\\', $reflection->getNamespaceName());
                 $namespace = '';
                 foreach ($namespaces as $key => $namespacePart) {
                     if ($namespace !== '') {
                         $namespace .= '/';
                     }
                     $namespace .= $namespacePart;
                     if (!array_key_exists($key, $namespaceList)) {
                         $namespaceList[$key] = [];
                     }
                     $namespaceList[$key][$namespace] = $namespace;
                 }
             }
             $escapedName = str_replace('\\', '/', $classname);
             $classList[$escapedName] = $escapedName;
         }
     }
     foreach ($namespaceList as $namespaceDepthList) {
         $list = array_merge($list, $namespaceDepthList);
     }
     $list = array_merge($list, $classList);
     return $list;
 }
开发者ID:nulldevelopmenthr,项目名称:generator,代码行数:45,代码来源:SourceCodePathReader.php


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