當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。