/** * Adds the new OrmClass object to the domain * * @throws OrmModelIntegrityException if the сдфыы with the same name already added * * @return OrmDomain */ function addClass(OrmClass $class) { $name = $class->getName(); if (isset($this->classes[$name])) { throw new OrmModelIntegrityException("Class {$class->getName()} already defined"); } $this->classes[$name] = $class; return $this; }
/** * @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; }