Zend\Code\Generator\ClassGenerator::addTrait PHP Метод

addTrait() публичный Метод

public addTrait ( $trait )
    public function addTrait($trait)
    {
        $this->traitUsageGenerator->addTrait($trait);
        return $this;
    }

Usage Example

Пример #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]);
 }
All Usage Examples Of Zend\Code\Generator\ClassGenerator::addTrait