Ejemplo n.º 1
0
 /**
  * @param string $name
  * @param mixed $value
  * @param string $type
  * @param bool $_get
  * @param string $visibility
  * @param bool $_lazy
  * @return \Symforce\AdminBundle\Compiler\Generator\PhpProperty
  */
 public function addProperty($name, $value, $type = null, $_get = false, $visibility = 'protected', $_lazy = false)
 {
     $property = new PhpProperty($name);
     if (null === $type) {
         $type = is_object($value) ? get_class($value) : gettype($value);
     }
     $property->setClass($this)->setDocblock('/** @var ' . $type . ' */')->setVisibility($visibility)->setDefaultValue($value)->useGetter($_get)->setLazy($_lazy);
     return $this;
 }
Ejemplo n.º 2
0
    /**
     * setProperty()
     *
     * @param array|\Zend\CodeGenerator\Php\PhpProperty $property
     * @return \Zend\CodeGenerator\Php\PhpClass
     */
    public function setProperty($property)
    {
        if (is_array($property)) {
            $property = new PhpProperty($property);
            $propertyName = $property->getName();
        } elseif ($property instanceof PhpProperty) {
            $propertyName = $property->getName();
        } else {
            throw new Exception\InvalidArgumentException('setProperty() expects either an array of property options or an instance of Zend_CodeGenerator_Php_Property');
        }

        if (isset($this->_properties[$propertyName])) {
            throw new Exception\InvalidArgumentException('A property by name ' . $propertyName . ' already exists in this class.');
        }

        $this->_properties[$propertyName] = $property;
        return $this;
    }
Ejemplo n.º 3
0
 public function visitProperty(PhpProperty $property)
 {
     $this->writer->write($property->getVisibility() . ' ' . ($property->isStatic() ? 'static ' : '') . '$' . $property->getName());
     if ($property->hasDefaultValue()) {
         $this->writer->write(' = ' . var_export($property->getDefaultValue(), true));
     }
     $this->writer->writeln(';');
 }
Ejemplo n.º 4
0
 /**
  * setConstant()
  *
  * @param array|\Zend\CodeGenerator\Php\PhpProperty $const
  * @return Zend\CodeGenerator\Php\PhpClass
  */
 public function setConstant($const)
 {
     if (is_array($const)) {
         $const = new PhpProperty($const);
         $constName = $const->getName();
     } elseif ($const instanceof PhpProperty) {
         $constName = $const->getName();
     } else {
         throw new Exception\InvalidArgumentException('setConstant() expects either an array of property options or an instance of Zend_CodeGenerator_Php_Property');
     }
     if (!$const->isConst()) {
         throw new Exception\InvalidArgumentException('setProperty() expects argument to define a constant');
     }
     if (isset($this->_constants[$constName])) {
         throw new Exception\InvalidArgumentException('A constant by name ' . $constName . ' already exists in this class.');
     }
     $this->_constants[$constName] = $const;
     return $this;
 }
Ejemplo n.º 5
0
 /** @return PhpProperty */
 public function addProperty($name, $value = NULL)
 {
     $property = new PhpProperty();
     return $this->properties[$name] = $property->setName($name)->setValue($value);
 }