Example #1
0
 /**
  * Add getter and setter for each param
  *
  * @param Deflection\Element\Classes $class      Current class
  * @param array                      $definition Param definition
  *
  * @return \Raoul\Generator
  */
 protected function addMethodsFromDefinition(Classes $class, $definition)
 {
     if (!isset($definition['all'])) {
         return $this;
     }
     foreach ($definition['all'] as $name => $infos) {
         foreach (array('get', 'set') as $type) {
             $method = $type . ucfirst($name);
             $description = ucfirst($type) . ' ' . $name;
             $docblock = new Docblock();
             $function = new Functions();
             $function->setDocblock($docblock);
             $function->isPublic(true);
             $function->setName($method);
             if ($type == 'set') {
                 $method = $infos['collection'] === true ? 'add' . ucfirst($name) : $method;
                 $description = $infos['collection'] === true ? 'Add element on ' . $name . ' collection' : $description;
                 $docblock->setDescription($description);
                 $docblock->addParam('return', '\\' . $class->getNamespace() . '\\' . $class->getName());
                 $docblock->addVar('value', $this->getType($infos['type'], $class->getNamespace()), $name);
                 $function->addParam('value' . ($infos['nullable'] === true ? ' = null' : ''), $this->getArgType($infos['type'], $class->getNamespace()));
                 $function->setContent(array('$this->' . $name . ($infos['collection'] === true ? '[]' : '') . ' = $value;', 'return $this;'));
             } else {
                 $docblock->setDescription($description);
                 $docblock->addParam('return', $this->getType($infos['type'], $class->getNamespace()));
                 $function->setContent(array('return $this->' . $name . ';'));
             }
             $class->addFunction($function);
         }
     }
     return $this;
 }
Example #2
0
 /**
  * Add param to structure
  *
  * @param \Deflection\Element\Functions $function Function
  *
  * @return \Deflection\Element\Classes
  */
 public function addFunction(\Deflection\Element\Functions $function)
 {
     $element = $function->getElement();
     $this->functions = array_merge($this->functions, array(''), $element);
     return $this;
 }
Example #3
0
 /**
  * Returns well formated function declaration
  *
  * @param array $definition Functions definition
  *
  * @return Deflection\Element\Functions
  */
 public function arrayToFunctionElement(array $definition)
 {
     $function = new Functions();
     if (isset($definition['docblock'])) {
         $docblock = $this->arrayToDocblockElement($definition['docblock']);
         $function->setDocbloc($docblock);
     }
     if (isset($definition['public'])) {
         $function->isPublic(true);
     }
     if (isset($definition['name'])) {
         $function->setName($definition['name']);
     }
     if (isset($definition['params'])) {
         foreach ($definition['params'] as $name => $type) {
             $function->addParam($name, $type);
         }
     }
     if (isset($definition['content'])) {
         $function->setContent($definition['content']);
     }
     return $function;
 }