Пример #1
0
 /**
  *
  * @param WS_Model_Xml_Entity $e
  * @throws InvalidArgumentException On properties with dublicate names.
  */
 public function addEntity(WS_Model_Xml_Entity $e)
 {
     if ($this->hasEntity($e->getName())) {
         throw new InvalidArgumentException("Entity with name '{$e->getName()}' allready added to the model!");
     }
     $this->entities[$e->getName()] = $e;
 }
 protected function parseEntity(SimpleXMLElement $xml)
 {
     $this->expectTag('entity', $xml);
     $attributes = $xml->attributes();
     if (!isset($attributes['name'])) {
         throw new Exception("Does not have expected attribute name in entity tag!");
     }
     $entity = new WS_Model_Xml_Entity($attributes['name']);
     foreach ($xml as $node) {
         $entity->addProperty($this->parseProperty($node));
     }
     return $entity;
 }
Пример #3
0
 /**
  * Generates the models base class constructor.
  *
  * The base class constructor provides an array with all property names to its
  * parent constructor (@see WS_Model_AbstractBase).
  *
  * @param WS_Model_Xml_Entity $entity The entity holds the properties with their names.
  *
  * @return WS_Model_Template_Method
  */
 protected function generateBaseClassConstructor(WS_Model_Xml_Entity $entity)
 {
     $methodTpl = $this->generateMethod('__construct', WS_Model_Template_Abstract::MODIFIER_PUBLIC);
     $argument = $this->tplFactory->createArgumentTemplate();
     $argument->setName('data');
     $argument->setDefault('null');
     $methodTpl->addArgument($argument);
     $body = 'parent::__construct(array(';
     if ($entity->countProperties()) {
         $body .= PHP_EOL;
         $index = 0;
         foreach ($entity->getProperties() as $property) {
             /* @var $property WS_Model_Xml_Property */
             if ($index > 0) {
                 $body .= ',' . PHP_EOL;
             }
             $body .= WS_Model_Template_Abstract::getIndentation(3);
             $body .= "'{$property->getName()}'";
             $index++;
         }
         $body .= PHP_EOL . WS_Model_Template_Abstract::getIndentation(2);
     }
     $body .= '), $data);';
     $methodTpl->setBody($body);
     return $methodTpl;
 }