Nette\PhpGenerator\PhpNamespace::setBracketedSyntax PHP Метод

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

public setBracketedSyntax ( $state = TRUE ) : self
Результат self
    public function setBracketedSyntax($state = TRUE)
    {
        $this->bracketedSyntax = (bool) $state;
        return $this;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $root_class = $this->app['engine']->fetch('doctrine/entities', 'root_class');
     $base_namespace = $this->app['engine']->fetch('doctrine/entities', 'base_namespace');
     $entity_root = $this->app['engine']->fetch('doctrine/entities', 'entity_root');
     $entity_root = $this->app->getDirectory($entity_root);
     $repo_root = $this->app['engine']->fetch('doctrine/entities', 'repository_root');
     $repo_root = $this->app->getDirectory($repo_root);
     foreach ($this->metaData as $meta_data) {
         $class_name = $meta_data->getName();
         $space_name = $this->parseNamespace($class_name);
         printf('Generated classes related to %s\\%s', $space_name, $class_name);
         $base_space = new PhpNamespace(ltrim($space_name . '\\' . $base_namespace, '\\'));
         $base_class = $base_space->addClass($class_name);
         $constructor = $base_class->addMethod('__construct')->setVisibility("public")->addComment("Instantiate a new " . $base_class->getName());
         if ($root_class) {
             $base_space->addUse($root_class);
             $base_class->setExtends($root_class);
         }
         $base_space->setBracketedSyntax(TRUE);
         $base_space->addUse('Doctrine\\Common\\Collections\\ArrayCollection');
         foreach ($meta_data->getFieldNames() as $field) {
             $type = $this->translateType($meta_data->getTypeOfField($field));
             $base_class->addProperty($field)->setVisibility("protected")->addComment("")->addComment("@access protected")->addComment("@var {$type}");
             $base_class->addMethod('get' . ucfirst($field))->setVisibility("public")->addComment("Get the value of {$field}")->addComment("")->addComment("@access public")->addComment("@return {$type} The value of {$field}")->addBody("return \$this->{$field};");
             $base_class->addMethod('set' . ucfirst($field))->setVisibility("public")->addComment("Set the value of {$field}")->addComment("")->addComment("@access public")->addComment("@param {$type} \$value The value to set to {$field}")->addComment("@return " . $base_class->getName() . " The object instance for method chaining")->addBody("\$this->{$field} = \$value;")->addBody("")->addBody("return \$this;")->addParameter("value");
         }
         foreach ($meta_data->getAssociationMappings() as $mapping) {
             $field = $mapping['fieldName'];
             $type = in_array($mapping['type'], $this->toOneTypes) ? $mapping['targetEntity'] : 'ArrayCollection';
             $base_class->addProperty($field)->setVisibility("protected")->addComment("")->addComment("@access protected")->addComment("@var {$type}");
             $base_class->addMethod('get' . ucfirst($field))->setVisibility("public")->addComment("Get the value of {$field}")->addComment("")->addComment("@access public")->addComment("@return {$type} The value of {$field}")->addBody("return \$this->{$field};");
             if ($type == 'ArrayCollection') {
                 $constructor->addBody("\$this->{$field} = new ArrayCollection();");
                 //
                 // hasRelatedEntities()
                 // addRelatedEntities()
                 // removeRelatedEntities()
                 //
             } else {
                 //
                 // hasRelatedEntity()
                 //
                 // On set, if value is set to null, check if bi-directional and remove
                 //
                 $base_class->addMethod('set' . ucfirst($field))->setVisibility("public")->addComment("Set the value of {$field}")->addComment("")->addComment("@access public")->addComment("@param {$type} \$value The value to set to {$field}")->addComment("@return " . $base_class->getName() . " The object instance for method chaining")->addBody("\$this->{$field} = \$value;")->addBody("")->addBody("return \$this;")->addParameter("value")->setTypeHint($type);
             }
         }
         $this->sortMethods($base_class);
         $this->sortProperties($base_class);
         $this->write($entity_root, $base_space, $base_class, TRUE);
         $space = new PhpNamespace($space_name);
         $class = $space->addClass($class_name)->setExtends($space_name . '\\' . $base_namespace . '\\' . $class_name);
         $class->addMethod('__construct')->setVisibility("public")->addComment("Instantiate a new " . $class->getName())->addBody("return parent::__construct();");
         $space->setBracketedSyntax(TRUE);
         $this->write($entity_root, $space, $class);
         if ($meta_data->customRepositoryClassName) {
             $repo_class_name = $meta_data->customRepositoryClassName;
             $repo_space_name = $this->parseNamespace($repo_class_name);
             $repo_space = new PhpNamespace($repo_space_name);
             $repo_class = $repo_space->addClass($repo_class_name);
             $repo_space->setBracketedSyntax(TRUE);
             $repo_space->addUse('Inkwell\\Doctrine\\Repository');
             $repo_class->setExtends('Inkwell\\Doctrine\\Repository');
             $this->write($repo_root, $repo_space, $repo_class);
         }
         echo PHP_EOL;
     }
 }