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


PHP ReflectionClass::getTraitNames方法代码示例

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


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

示例1: testTraits

 public function testTraits()
 {
     $reflection = new \ReflectionClass(StandardQuery::class);
     $this->assertInstanceOf(Query::class, $reflection->newInstance());
     $this->assertContains(LimitQueryTrait::class, $reflection->getTraitNames());
     $this->assertContains(OffsetQueryTrait::class, $reflection->getTraitNames());
     $this->assertContains(SortingQueryTrait::class, $reflection->getTraitNames());
 }
开发者ID:wookieb,项目名称:query-object,代码行数:8,代码来源:StandardQueryTest.php

示例2: set_class_plugin

 /**
  * クラスにプラグインをセットする
  * @param object $o
  * @param string $n
  */
 public static function set_class_plugin($o, $n = null)
 {
     if (is_array($o)) {
         foreach ($o as $c => $plugins) {
             $r = new \ReflectionClass('\\' . str_replace('.', '\\', $c));
             if (in_array(__CLASS__, $r->getTraitNames())) {
                 foreach ($plugins as $p) {
                     call_user_func_array([$r->getName(), 'set_class_plugin'], [$p]);
                 }
             }
         }
     } else {
         $g = get_called_class();
         if (is_string($o) && class_exists($c = '\\' . str_replace('.', '\\', $o))) {
             $o = new $c();
         }
         $t = (is_object($o) ? 1 : 0) + (is_callable($o) ? 2 : 0);
         if ($t === 1) {
             self::$_plug_funcs[$g][] = $o;
         } else {
             if ($t === 3 && !empty($n)) {
                 self::$_plug_funcs[$g][] = [$o, (string) $n];
             }
         }
     }
 }
开发者ID:tokushima,项目名称:ebi,代码行数:31,代码来源:Plugin.php

示例3: register

 /**
  * Register plugins
  */
 public function register($path)
 {
     if (!file_exists($path) && !is_dir($path)) {
         throw new ExtensionException(sprintf('path %s not exists', $path));
     }
     $Cyan = \Cyan::initialize();
     $App = $Cyan->getContainer('application');
     $plugin_manager = $App->getContainer('factory_plugin');
     $plugin_types = glob($path . '/*', GLOB_ONLYDIR);
     foreach ($plugin_types as $plugin_type) {
         $plugin_paths = glob($plugin_type . '/*', GLOB_ONLYDIR);
         foreach ($plugin_paths as $plugin_path) {
             $class_name = sprintf('Plugin%s%s', ucfirst(strtolower(basename($plugin_type))), ucfirst(strtolower(basename($plugin_path))));
             $file_path = $plugin_path . DIRECTORY_SEPARATOR . basename($plugin_path) . '.php';
             if (file_exists($file_path)) {
                 $plugin_callback = (require_once $file_path);
                 if (is_callable($plugin_callback)) {
                     $type = basename($plugin_type);
                     $name = basename($plugin_path);
                     $plugin_manager->create($type, $name, $plugin_callback);
                 } elseif (class_exists($class_name)) {
                     $type = basename($plugin_type);
                     $name = basename($plugin_path);
                     $reflection_class = new ReflectionClass($class_name);
                     if (!in_array('Cyan\\Framework\\TraitSingleton', $reflection_class->getTraitNames())) {
                         throw new FactoryException(sprintf('%s class must use Cyan\\Trait\\Singleton', $class_name));
                     }
                     unset($reflection_class);
                     $plugin_manager->create($type, $name, $class_name::getInstance());
                 }
             }
         }
     }
 }
开发者ID:cyan-framework,项目名称:cms,代码行数:37,代码来源:plugin.php

示例4: 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

示例5: test_traits

 /** @coversNothing */
 public function test_traits()
 {
     $subjectReflection = new \ReflectionClass(testSubject::class);
     $subjectTraits = $subjectReflection->getTraitNames();
     $allTraits = getAllTraits($subjectReflection);
     self::assertContains(P\RootTypeTrait::class, $subjectTraits);
     self::assertContains(P\ClosedTrait::class, $allTraits);
 }
开发者ID:rkgladson,项目名称:PHPixme,代码行数:9,代码来源:AttemptTest.php

示例6: isCollectible

 /**
  * Check if the specified object has the `Collectable` trait.
  *
  * @param mixed $object
  *
  * @return bool
  */
 public function isCollectible($object)
 {
     $reflector = new \ReflectionClass($object);
     $filtered = array_filter($reflector->getTraitNames(), function ($trait) {
         return array_reverse(explode('\\', $trait))[0] == 'Collectable';
     });
     return count($filtered) ? true : false;
 }
开发者ID:warrickbayman,项目名称:charms,代码行数:15,代码来源:Collectable.php

示例7: isEntitySupported

 /**
  * Checks whether provided entity is supported.
  *
  * @param \ReflectionClass $reflClass
  *
  * @return bool
  */
 private function isEntitySupported(\ReflectionClass $reflClass)
 {
     $traitNames = [];
     while ($reflClass) {
         $traitNames = array_merge($traitNames, $reflClass->getTraitNames());
         $reflClass = $reflClass->getParentClass();
     }
     return in_array('Unifik\\DoctrineBehaviorsBundle\\Model\\SoftDeletable\\SoftDeletable', $traitNames);
 }
开发者ID:smart85,项目名称:UnifikDoctrineBehaviorsBundle,代码行数:16,代码来源:SoftDeletableListener.php

示例8: getTraitNames

 /**
  * get all trait names
  *
  * @return array
  */
 public function getTraitNames()
 {
     $traits = parent::getTraitNames();
     if ($this->getParentClass()) {
         $parent = $this->getParentClass();
         $traits = array_merge($traits, $this->getParentClassTraits($this->getParentClass()));
     }
     return $traits;
 }
开发者ID:cyan-framework,项目名称:library,代码行数:14,代码来源:class.php

示例9: getTraitNames

 private function getTraitNames(\ReflectionClass $class) : array
 {
     $traitNames = $class->getTraitNames();
     while ($class->getParentClass() !== false) {
         $traitNames = array_values(array_unique(array_merge($traitNames, $class->getParentClass()->getTraitNames())));
         $class = $class->getParentClass();
     }
     return $traitNames;
 }
开发者ID:phpstan,项目名称:phpstan-nette,代码行数:9,代码来源:SmartObjectPropertiesClassReflectionExtension.php

示例10: hasTrait

 /**
  *
  * @param \ReflectionClass $reflClass
  * @param type $traitName
  * @param type $isRecursive
  * @return boolean
  */
 protected function hasTrait(\ReflectionClass $reflClass, $traitName, $isRecursive = false)
 {
     if (in_array($traitName, $reflClass->getTraitNames())) {
         return true;
     }
     $parentClass = $reflClass->getParentClass();
     if (false === $isRecursive || false === $parentClass || null === $parentClass) {
         return false;
     }
     return $this->hasTrait($parentClass, $traitName, $isRecursive);
 }
开发者ID:upro,项目名称:I18nDoctrineBundle,代码行数:18,代码来源:DoctrineListener.php

示例11: isTranslatable

 /**
  * Check if the entity is a Translatable entity
  *
  * @param $entity
  *
  * @return bool
  */
 protected function isTranslatable($entity)
 {
     if (!is_object($entity)) {
         return false;
     }
     // Support Doctrine Proxies
     $realClass = ClassUtils::getRealClass($entity);
     $reflClass = new \ReflectionClass($realClass);
     $traitNames = $reflClass->getTraitNames();
     return in_array('Unifik\\DoctrineBehaviorsBundle\\Model\\Translatable\\Translatable', $traitNames) && $reflClass->hasProperty('translations');
 }
开发者ID:pmdc,项目名称:UnifikSystemBundle,代码行数:18,代码来源:TranslationExtension.php

示例12: traitsUsedRecursive

 protected function traitsUsedRecursive($class, $traitNames = [])
 {
     if (!$class instanceof ReflectionClass) {
         $class = new ReflectionClass($class);
     }
     $traitNames = array_merge($traitNames, $class->getTraitNames());
     if ($class->getParentClass() != false) {
         return array_merge($traitNames, $this->traitsUsedRecursive($class->getParentClass()));
     }
     return $traitNames;
 }
开发者ID:webfox,项目名称:silverstripe-helpers,代码行数:11,代码来源:ExtraPageFieldsExtension.php

示例13: extractModule

 protected function extractModule($module)
 {
     $Iterator = new \RecursiveIteratorIterator($iterator = new \RecursiveDirectoryIterator($module));
     $Regex = new \RegexIterator($Iterator, '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH);
     foreach ($Regex as $file => $vv) {
         $this->currentService = null;
         $this->currentSecurity = null;
         $this->currentMethod = null;
         $this->currentClass = $this->resolveClassName($file);
         $this->currentPrefix = '';
         try {
             $r = new \ReflectionClass($this->currentClass);
         } catch (\ReflectionException $e) {
             var_dump($e->getMessage());
             continue;
         }
         foreach ($this->parseAnnotations($r->getDocComment()) as $annotation) {
             $method = substr($annotation, 0, strpos($annotation, '('));
             if (method_exists($this, $method)) {
                 eval('$this->' . $annotation . ';');
             }
         }
         if ($r->isSubclassOf('eBuildy\\Container\\ContainerAware') || in_array('eBuildy\\Container\\ContainerAwareTrait', $r->getTraitNames()) || $r->hasProperty('container')) {
             $this->services[$this->currentService]['containerAware'] = true;
         }
         $methods = $r->getMethods(\ReflectionMethod::IS_PUBLIC);
         foreach ($methods as $method) {
             if ($this->currentClass === $method->getDeclaringClass()->getName()) {
                 $this->currentMethod = $method->getName();
                 foreach ($this->parseAnnotations($method->getDocComment()) as $annotation) {
                     if (strpos($annotation, '(') !== false) {
                         $annotationMethod = substr($annotation, 0, strpos($annotation, '('));
                         if (strpos($annotationMethod, ' ') === false && method_exists($this, $annotationMethod)) {
                             eval('$this->' . $annotation . ';');
                         }
                     }
                 }
             }
         }
         $properties = $r->getProperties(\ReflectionMethod::IS_PUBLIC);
         foreach ($properties as $property) {
             $this->currentProperty = $property->getName();
             foreach ($this->parseAnnotations($property->getDocComment()) as $annotation) {
                 $annotationMethod = substr($annotation, 0, strpos($annotation, '('));
                 if (method_exists($this, $annotationMethod)) {
                     eval('$this->' . $annotation . ';');
                 }
             }
         }
     }
 }
开发者ID:ebuildy,项目名称:ebuildy,代码行数:51,代码来源:AnnotationLoader.php

示例14: hasTrait

 /**
  * Return TRUE if the given object use the given trait, FALSE if not
  * Extends from ClassAnalyzer::hasTrait to check in ancestors traits as well
  * 
  * @param \ReflectionClass $class
  * @param string $traitName
  * @param boolean $isRecursive
  */
 public function hasTrait(\ReflectionClass $class, $traitName, $isRecursive = false)
 {
     $classTraits = $class->getTraitNames();
     // Trait directly present in final class
     if (in_array($traitName, $classTraits)) {
         return true;
     }
     // Check in parents traits
     foreach ($classTraits as $classTrait) {
         $traitObject = new \ReflectionClass($classTrait);
         if ($this->hasTrait($traitObject, $traitName, $isRecursive)) {
             return true;
         }
     }
     // Check in parents classes
     $parentClass = $class->getParentClass();
     if (false === $isRecursive || false === $parentClass || null === $parentClass) {
         return false;
     }
     return $this->hasTrait($parentClass, $traitName, $isRecursive);
 }
开发者ID:devgiants,项目名称:seo-bundle,代码行数:29,代码来源:ClassAnalyzer.php

示例15: assign

 /**
  * @param $type
  * @param TraitsEvent $target_object
  */
 public function assign($type, $target_object)
 {
     $type = strtolower($type);
     $required = __NAMESPACE__ . '\\TraitEvent';
     $reflection_class = new ReflectionClass($target_object);
     $parent = $reflection_class->getParentClass();
     $use = $reflection_class->getTraitNames();
     unset($reflection_class);
     if ($parent) {
         $use = array_merge($use, $parent->getTraitNames());
     }
     if (!in_array($required, $use)) {
         throw new FactoryException(sprintf('Cant assign %s Plugins to %s %s, because they are not use TraitEvent.', $type, get_class($target_object), gettype($target_object)));
     }
     if (!isset($this->factory_registry[$type]) || empty($this->factory_registry[$type])) {
         return;
     }
     foreach ($this->factory_registry[$type] as $plugin_name => $plugin) {
         $target_object->registerEventPlugin($plugin_name, $plugin);
     }
 }
开发者ID:cyan-framework,项目名称:library,代码行数:25,代码来源:plugin.php


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