/** * Adds the new property to the ORM-related entity * * @throws OrmModelIntegrityException if the property with the same name already added * @param OrmProperty $property * * @return OrmClass */ function addProperty(OrmProperty $property) { $name = $property->getName(); if (isset($this->properties[$name])) { throw new OrmModelIntegrityException("Property {$property->getName()} already defined"); } $this->properties[$name] = $property; return $this; }
function toGetter(IMappable $entity, OrmProperty $property) { $capitalizedPropertyName = ucfirst($property->getName()); $class = $this->getContainerClassName($property); return <<<EOT \t/** \t * @return {$class} \t */ \tfunction get{$capitalizedPropertyName}(\$readOnly = false) \t{ \t\treturn new {$class}(\$this, \$readOnly); \t} EOT; }
/** * Create a php code which implements a field within the entity class * @param IMappable $entity * @param OrmProperty $property */ function toField(IMappable $entity, OrmProperty $property) { $typeImpl = ($typeImpl = $this->getImplClass()) ? $typeImpl : 'scalar'; if ($property->getMultiplicity()->isNullable()) { $typeImpl .= '|null'; } return <<<EOT \t/** \t * @var {$typeImpl} \t */ \tprotected \${$property->getName()}; EOT; }
function toGetter(IMappable $entity, OrmProperty $property) { $returnValue = ($implClass = $this->getImplClass()) ? $implClass : 'mixed'; if ($property->getMultiplicity()->isNullable()) { $returnValue .= '|null'; } $propertyName = $property->getName(); $capitalizedPropertyName = ucfirst($propertyName); return <<<EOT \t/** \t * @return {$returnValue} \t */ \tfunction get{$capitalizedPropertyName}() \t{ //\t\tif (\$this->{$propertyName}) { // thats is what called lazy fetching //\t\t\t\$this->{$propertyName}->fetch(); //\t\t} \t\treturn \$this->{$propertyName}; \t} EOT; }
private function importConstraints(OrmProperty $property) { $name = $this->dbTable->getName() . '_' . $property->getName(); $fields = $property->getFields(); if ($property->isIdentifier()) { $this->dbTable->addConstraint(new DBPrimaryKeyConstraint($name . '_pk', $this->dbTable, $fields)); } else { if ($property->isUnique()) { $this->dbTable->addConstraint(new DBUniqueConstraint($name . '_uq', $this->dbTable, $fields)); } } $type = $property->getType(); if ($type instanceof AssociationPropertyType) { $this->dbTable->addConstraint(new DBOneToOneConstraint($name . '_fk', $this->dbTable, $fields, $this->dbSchema->getTable($property->getType()->getContainer()->getTable()), $property->getType()->getAssociationBreakAction())); } else { if ($type instanceof CompositePropertyType) { foreach ($type->getProperties($property) as $_property) { $this->importConstraints($_property); } } } if ($property->isQueryable()) { $this->dbTable->addIndex(new DBIndex($name . '_idx', $this->dbTable, $fields)); } }
/** * @param EntityQueryBuilder $builder * @param OrmProperty $property */ function __construct(EntityQueryBuilder $builder, OrmProperty $property) { $this->owner = $builder->getAlias(); $this->property = $property; Assert::isTrue($property->getType()->getColumnCount() == 1, 'composite property querying is not supported (`%s`.`%s` is ambiguous)', $builder->getEntity()->getLogicalSchema()->getEntityName(), $property->getName()); }
private function guessAssociated($path, OrmProperty $property, AssociationPropertyType $type) { if (!isset($this->joined[$property->getName()])) { $builder = $this->joined[$property->getName()] = new self($type->getContainer(), (APP_SLOT_CONFIGURATION & SLOT_CONFIGURATION_FLAG_DEVELOPMENT ? $this->alias : substr(sha1($this->alias), 0, 6)) . '_' . $property->getName()); $builder->joins = array(); $this->join($property, $type, $builder, end($this->joins)); } return $this->joined[$property->getName()]->getEntityProperty($path); }