addTrait() public method

public addTrait ( $trait )
コード例 #1
0
 /**
  * @interitdoc
  */
 public function __invoke($name, $namespace, $classToExtend, $fileDocBlock = null)
 {
     $interfaces = $this->getImplementedInterfaces();
     $properties = $this->getClassProperties();
     $flags = $this->getClassFlags();
     $methods = $this->getMethods($name);
     $traits = $this->getTraits();
     // getUses() must called at the end to allow other methods to add import namespaces directives
     $uses = $this->getUses();
     $fileDocBlock = new DocBlockGenerator($fileDocBlock);
     if ($classToExtend) {
         $uses[] = ltrim($classToExtend, '\\');
         $classToExtend = substr($classToExtend, strrpos($classToExtend, '\\') + 1);
     }
     switch (get_class($this)) {
         case 'Prooph\\Cli\\Code\\Generator\\CommandHandler':
             $className = $name . 'Handler';
             break;
         case 'Prooph\\Cli\\Code\\Generator\\CommandHandlerFactory':
             $className = $name . 'HandlerFactory';
             break;
         default:
             $className = $name;
             break;
     }
     $class = new ClassGenerator($className, $namespace, $flags, $classToExtend, $interfaces, $properties, $methods, $this->getClassDocBlock($name));
     foreach ($traits as $trait) {
         $class->addTrait($trait);
     }
     return new FileGenerator(['classes' => [$class], 'namespace' => $namespace, 'uses' => $uses, 'docBlock' => $fileDocBlock]);
 }
コード例 #2
0
 /**
  * @param Tag $tagItem
  * @return ClassGenerator
  */
 protected function createClass(Tag $tagItem)
 {
     $className = ucfirst($this->stringToCamelCaseConverter->convert($tagItem->getName()));
     $class = new ClassGenerator();
     $class->setNamespaceName('Flex\\Code\\Html\\Tag');
     $class->setName($className);
     $class->addUse('Flex\\Code\\Html\\Tag\\Model\\AbstractTag');
     $class->setExtendedClass('AbstractTag');
     $implementedInterfaces = [];
     if ($tagItem->isGlobalAttributeAware()) {
         $implementedInterfaces[] = 'GlobalAttributeAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Attribute\\GlobalAttributeAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Attribute\\GlobalAttributeAwareTrait');
         $class->addTrait('GlobalAttributeAwareTrait');
     }
     if ($tagItem->isClipboardEventAware()) {
         $implementedInterfaces[] = 'ClipboardEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\ClipboardEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\ClipboardEventAwareTrait');
         $class->addTrait('ClipboardEventAwareTrait');
     }
     if ($tagItem->isFormEventAware()) {
         $implementedInterfaces[] = 'FormEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\FormEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\FormEventAwareTrait');
         $class->addTrait('FormEventAwareTrait');
     }
     if ($tagItem->isKeyboardEventAware()) {
         $implementedInterfaces[] = 'KeyboardEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\KeyboardEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\KeyboardEventAwareTrait');
         $class->addTrait('KeyboardEventAwareTrait');
     }
     if ($tagItem->isMediaEventAware()) {
         $implementedInterfaces[] = 'MediaEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MediaEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MediaEventAwareTrait');
         $class->addTrait('MediaEventAwareTrait');
     }
     if ($tagItem->isMiscEventAware()) {
         $implementedInterfaces[] = 'MiscEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MiscEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MiscEventAwareTrait');
         $class->addTrait('MiscEventAwareTrait');
     }
     if ($tagItem->isMouseEventAware()) {
         $implementedInterfaces[] = 'MouseEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MouseEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MouseEventAwareTrait');
         $class->addTrait('MouseEventAwareTrait');
     }
     if ($tagItem->isWindowEventAware()) {
         $implementedInterfaces[] = 'WindowEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\WindowEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\WindowEventAwareTrait');
         $class->addTrait('WindowEventAwareTrait');
     }
     $class->setImplementedInterfaces($implementedInterfaces);
     $docBlock = new DocBlockGenerator();
     $docBlock->setTag(new GenericTag('author', 'elnebuloso/flex-code-html-generator'));
     $docBlock->setTag(new GenericTag('link', $tagItem->getLink()));
     if (!is_null($tagItem->getShortDescription())) {
         $docBlock->setShortDescription($tagItem->getShortDescription());
     }
     if (!is_null($tagItem->getLongDescription())) {
         $docBlock->setLongDescription($tagItem->getLongDescription());
     }
     $class->setDocBlock($docBlock);
     return $class;
 }