/** * @param OrmClass $ormClass object that represents a class to be generated * @param OrmProperty $ormProperty property that implements a ContainerPropertyType */ function __construct(OrmClass $ormClass, OrmProperty $ormProperty) { $this->ormProperty = $ormProperty; $this->propertyType = $ormProperty->getType(); Assert::isTrue($this->propertyType instanceof ContainerPropertyType); parent::__construct($ormClass); }
/** * @param IQueryable $proxy * @param OrmProperty $container * @param OrmProperty $encapsulant */ function __construct(IQueryable $proxy, OrmProperty $container, OrmProperty $encapsulant) { $this->proxy = $proxy; $this->container = $container; $this->encapsulant = $encapsulant; parent::__construct($container->getType()->getContainer(), $encapsulant->getType()->getContainer()); }
protected function getPropertyTuple(OrmProperty $property, array $tuple) { $propertyTuple = array(); foreach ($property->getFields() as $field) { $propertyTuple[] = $tuple[$field]; } $propertyType = $property->getType(); $propertyTuple = array_combine(array_keys($propertyType->getSqlTypes()), $propertyTuple); return $propertyTuple; }
private function insert(IdentifiableOrmEntity $entity) { $id = $entity->_getId(); $idType = $this->identifier->getType(); $generator = !$id && $idType instanceof IOrmEntityIdGenerator ? $idType->getIdGenerator($entity) : null; $generatorType = $generator ? $generator->getType() : null; if ($generatorType && $generatorType->isPre()) { $id = $generator->generate($entity); if ($id) { $entity->_setId($id); } } $affected = $this->executeQuery(InsertQuery::create($this->physicalSchema->getTable())->setValues($this->map->disassemble($entity))); if ($generatorType && $generatorType->isPost()) { $id = $generator->generate($entity); if ($id) { $entity->_setId($id); } } $this->identityMap->add($entity); $entity->setFetched(); }
/** * @return void */ private function importProperty() { if (!sizeof($this->ormProperty->getFields())) { // columnless properties are skipped return; } $columns = array_combine($this->ormProperty->getFields(), $this->ormProperty->getType()->getSqlTypes()); $dbColumns = array(); foreach ($columns as $name => $dbType) { $dbColumns[$name] = new DBColumn($name, $dbType); } $fields = array_keys($dbColumns); $this->dbTable->addColumns($dbColumns); if ($this->ormProperty->getType() instanceof AssociationPropertyType) { $this->dbTable->addConstraint(new DBOneToOneConstraint($fields, $this->dbSchema->getTable($this->ormProperty->getType()->getContainer()->getTable()), $this->ormProperty->getType()->getAssociationBreakAction())); } if ($this->ormProperty->isIdentifier()) { $this->dbTable->addConstraint(new DBPrimaryKeyConstraint($fields)); } else { if ($this->ormProperty->isUnique()) { $this->dbTable->addConstraint(new DBUniqueConstraint($fields)); } } }
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)); } }
function __construct(IdentifiableOrmEntity $parent, IQueryable $children, OrmProperty $referentialProperty, $readOnly) { $this->mtm = $referentialProperty->getType(); Assert::isTrue($this->mtm instanceof ManyToManyContainerPropertyType); parent::__construct($parent, $children, $readOnly); }
/** * @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()); }
/** * @return void */ private function fetchClassMembers(OrmProperty $property) { $visibility = $property->getVisibility(); if ($visibility->is(OrmPropertyVisibility::TRANSPARENT)) { return; } $type = $property->getType(); // make property itself $this->classProperties[] = $type->toField($this->ormClass, $property); // make setter if ($visibility->isSettable()) { $this->classMethods[] = $type->toSetter($this->ormClass, $property); if ($property->isIdentifier()) { $this->classMethods[] = <<<EOT \tfunction _setId(\$id) \t{ \t\t\$this->{$property->getSetter()}(\$id); \t\treturn \$this; \t} EOT; } } // make getter if ($visibility->isGettable()) { $this->classMethods[] = $type->toGetter($this->ormClass, $property); if ($property->isIdentifier()) { $this->classMethods[] = <<<EOT \tfunction _getId() \t{ \t\treturn \$this->{$property->getGetter()}(); \t} EOT; } } }
private function processProperty($path, OrmProperty $property) { $type = $property->getType(); if (!$path) { return new EntityProperty($this, $property); } if ($type instanceof AssociationPropertyType) { return $this->guessAssociated($path, $property, $type); } else { if ($type instanceof CompositePropertyType) { return $this->guessComposite($path, $property, $type); } else { Assert::isUnreachable('do not know how to refer %s', get_class($type)); } } }