Exemplo n.º 1
0
 /**
  * @return string
  */
 function toPhpCall()
 {
     $fields = array();
     foreach ($this->fields as $field) {
         $fields[] = '\'' . $field . '\'';
     }
     $ctorArguments = array("'{$this->name}'", 'array(' . join(', ', $fields) . ')', $this->type->toPhpCodeCall(), "new OrmPropertyVisibility(OrmPropertyVisibility::{$this->visibility->getId()})", "new AssociationMultiplicity(AssociationMultiplicity::{$this->multiplicity->getId()})", $this->isUnique ? 'true' : 'false', $this->isIdentifier ? 'true' : 'false');
     return join('', array('new OrmProperty(', join(', ', $ctorArguments), ')'));
 }
 /**
  * @return OrmProperty
  */
 private function generateContainer(OrmClass $type, SimpleXMLElement $xmlContainer)
 {
     $referredTypeName = (string) $xmlContainer['type'];
     if (!($referredType = $this->importEntity($referredTypeName))) {
         if (TypeUtils::isExists($referredTypeName) && TypeUtils::isInherits($referredTypeName, 'IDaoRelated')) {
             $referredType = call_user_func(array($referredTypeName, 'orm'));
         } else {
             $referrer = $type->getName() . '.' . (string) $xmlContainer['name'];
             throw new OrmModelIntegrityException($referrer . ' refers to unknown entity ' . $referredTypeName);
         }
     }
     try {
         // one-to-many
         $referredProperty = $referredType->getProperty((string) $xmlContainer['refs']);
         $propertyType = new OneToManyContainerPropertyType($type, $referredType, $referredProperty);
     } catch (OrmModelIntegrityException $e) {
         // many to many
         try {
             $proxy = $this->ormDomain->getClass((string) $xmlContainer['refs']);
         } catch (OrmModelIntegrityException $e) {
             $proxy = new OrmClass();
             $proxy->setHasDao(true);
             $proxy->setName((string) $xmlContainer['refs']);
             $this->ormDomain->addClass($proxy);
         }
         $propName = strtolower($type->getEntityName());
         try {
             $mtmType = new AssociationPropertyType($type, AssociationMultiplicity::exactlyOne(), AssociationBreakAction::cascade());
             $type_property = new OrmProperty($propName, $this->makeFields($type->getTable(), $mtmType), $mtmType, OrmPropertyVisibility::full(), AssociationMultiplicity::exactlyOne());
             $proxy->addProperty($type_property);
         } catch (OrmModelIntegrityException $e) {
             $type_property = $proxy->getProperty($propName);
         }
         $propName = strtolower($referredType->getEntityName());
         try {
             $mtmType = new AssociationPropertyType($referredType, AssociationMultiplicity::exactlyOne(), AssociationBreakAction::cascade());
             $referredType_property = new OrmProperty($propName, $this->makeFields($referredType->getTable(), $mtmType), $mtmType, OrmPropertyVisibility::full(), AssociationMultiplicity::exactlyOne());
             $proxy->addProperty($referredType_property);
         } catch (OrmModelIntegrityException $e) {
             $referredType_property = $proxy->getProperty($propName);
         }
         $propertyType = new ManyToManyContainerPropertyType($proxy, $type_property, $referredType_property);
     }
     $property = new OrmProperty((string) $xmlContainer['name'], array(), $propertyType, new OrmPropertyVisibility(OrmPropertyVisibility::READONLY), AssociationMultiplicity::zeroOrOne(), false);
     if (isset($xmlContainer['db-columns'])) {
         $property->setDBColumnNames($this->getFields($xmlContainer['db-columns']));
     }
     return $property;
 }