Exemplo n.º 1
0
 /**
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @return void
  */
 protected function addInitStorageObjectCalls(Model\DomainObject $domainObject)
 {
     $anyToManyRelationProperties = $domainObject->getAnyToManyRelationProperties();
     if (count($anyToManyRelationProperties) > 0) {
         if (!$this->classObject->methodExists('__construct')) {
             $constructorMethod = $this->templateClassObject->getMethod('__construct');
             $constructorMethod->setDescription('__construct');
             $this->classObject->addMethod($constructorMethod);
         } else {
             $constructorMethod = $this->classObject->getMethod('__construct');
         }
         if (preg_match('/\\$this->initStorageObjects()/', $this->printerService->render($constructorMethod->getBodyStmts())) < 1) {
             $this->classObject->setMethod($this->classObject->getMethod('__construct'));
         }
         $initStorageObjectsMethod = clone $this->templateClassObject->getMethod('initStorageObjects');
         $methodBodyStmts = array();
         $templateBodyStmts = $initStorageObjectsMethod->getBodyStmts();
         $initStorageObjectsMethod->setModifier('protected');
         foreach ($anyToManyRelationProperties as $relationProperty) {
             $methodBodyStmts = array_merge($methodBodyStmts, $this->parserService->replaceNodeProperty($templateBodyStmts, array('children' => $relationProperty->getName()), array('Expr_PropertyFetch', 'Expr_Variable')));
         }
         $initStorageObjectsMethod->setBodyStmts($methodBodyStmts);
         $this->classObject->setMethod($initStorageObjectsMethod);
     } elseif ($this->classObject->methodExists('initStorageObjects')) {
         $this->classObject->getMethod('initStorageObjects')->setBodyStmts(array());
     }
 }