コード例 #1
0
ファイル: Event.php プロジェクト: Hlavos/obo
 /**
  * @return string
  */
 public function eventIdentificationKey()
 {
     if ($this->onClassWithName !== null) {
         return $this->name . \ltrim($this->onClassWithName, "\\");
     }
     if ($this->onObject !== null) {
         return $this->name . $this->onObject->objectIdentificationKey();
     }
 }
コード例 #2
0
ファイル: EntitiesCollection.php プロジェクト: Hlavos/obo
 /**
  * @return void
  */
 public function loadEntities()
 {
     if (!$this->owner->isBasedInRepository()) {
         return;
     }
     foreach ($this->relationShip->findEntities() as $entity) {
         \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity("beforeConnectToOwner", $entity, ["collection" => $this, "owner" => $this->owner, "columnName" => $this->relationShip->ownerPropertyName]);
         $this->setValueForVariableWithName($entity, $entity->primaryPropertyValue());
         \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity("afterConnectToOwner", $entity, ["collection" => $this, "owner" => $this->owner, "columnName" => $this->relationShip->ownerPropertyName]);
         \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity($this->relationShip->ownerPropertyName . "Connected", $this->owner, ["collection" => $this, "owner" => $this->owner, "columnName" => $this->relationShip->ownerPropertyName, "addedEntity" => $entity]);
     }
 }
コード例 #3
0
ファイル: One.php プロジェクト: Hlavos/obo
 /**
  * @param \obo\Entity $owner
  * @param array $foreignKey
  * @param boolean $autoCreate
  * @return \obo\Entity|null
  */
 public function entityForOwnerForeignKey(\obo\Entity $owner, array $foreignKey, $autoCreate = true)
 {
     if ($owner->primaryPropertyValue() === null) {
         return null;
     }
     $this->owner = $owner;
     $entityClassNameToBeConnected = $this->entityClassNameToBeConnected;
     $entityManagerName = $entityClassNameToBeConnected::entityInformation()->managerName;
     $specification = $entityManagerName::querySpecification();
     if (\count($foreignKey) === 1) {
         $specification->where("{{$foreignKey[0]}} = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER, $owner->primaryPropertyValue());
     } else {
         $this->ownerNameInProperty = $foreignKey[1];
         $specification->where("{{$foreignKey[0]}} = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER . " AND {{$foreignKey[1]}} = " . \obo\Interfaces\IQuerySpecification::PARAMETER_PLACEHOLDER, $owner->primaryPropertyValue(), $owner->entityInformation()->className);
     }
     if ($entity = $entityManagerName::findEntity($specification, false)) {
         return $entity;
     } else {
         return ($autoCreate and $this->autoCreate and !$owner->isDeleted()) ? $entityManagerName::entityFromArray([$foreignKey[0] => $owner]) : null;
     }
 }
コード例 #4
0
 /**
  * @param \obo\Carriers\QueryCarrier $specification
  * @param string $repositoryName
  * @param \obo\Entity $owner
  * @param string $targetEntity
  */
 protected function constructJoinQueryForRelationship(\obo\Carriers\QueryCarrier $specification, $repositoryName, \obo\Entity $owner, $targetEntity)
 {
     $targetEntityPropertyNameForSoftDelete = $targetEntity::entityInformation()->propertyNameForSoftDelete;
     if ($targetEntityPropertyNameForSoftDelete === "") {
         $specification->join("JOIN [{$repositoryName}] ON [{$owner->entityInformation()->repositoryName}] = " . $this->informationForEntity($owner->entityInformation())["columns"][$owner->entityInformation()->informationForPropertyWithName($owner->entityInformation()->primaryPropertyName)->columnName]["placeholder"] . " AND [{$targetEntity::entityInformation()->repositoryName}] = [{$targetEntity::informationForPropertyWithName($targetEntity::entityInformation()->primaryPropertyName)->columnName}]", $owner->primaryPropertyValue());
     } else {
         $softDeleteJoinQuery = "AND [{$targetEntity::entityInformation()->repositoryName}].[{$targetEntity::informationForPropertyWithName($targetEntityPropertyNameForSoftDelete)->columnName}] = %b";
         $specification->join("JOIN [{$repositoryName}] ON [{$owner->entityInformation()->repositoryName}] = " . $this->informationForEntity($owner->entityInformation())["columns"][$owner->entityInformation()->informationForPropertyWithName($owner->entityInformation()->primaryPropertyName)->columnName]["placeholder"] . " AND [{$targetEntity::entityInformation()->repositoryName}] = [{$targetEntity::informationForPropertyWithName($targetEntity::entityInformation()->primaryPropertyName)->columnName}]" . $softDeleteJoinQuery, $owner->primaryPropertyValue(), FALSE);
     }
 }
コード例 #5
0
ファイル: IdentityMapper.php プロジェクト: Hlavos/obo
 /**
  * @param \obo\Entity $entity
  * @return bool
  */
 public function isMappedEntity(\obo\Entity $entity)
 {
     return isset($this->entities[$entity->entityIdentificationKey()]);
 }
コード例 #6
0
ファイル: Many.php プロジェクト: Hlavos/obo
 public function remove(\obo\Entity $entity)
 {
     if ($this->connectViaPropertyWithName !== "") {
         $entity->setValueForPropertyWithName(null, $this->connectViaPropertyWithName);
         $entity->save();
     } elseif ($this->connectViaRepositoryWithName !== "") {
         $ownerManagerName = $this->owner->entityInformation()->managerName;
         $ownerManagerName::dataStorage()->removeRelationshipBetweenEntities($this->connectViaRepositoryWithName, [$this->owner, $entity]);
     } else {
         throw new \obo\Exceptions\Exception("This relationship is not well configured");
     }
 }
コード例 #7
0
 /**
  * @param \obo\Entity $entity
  */
 public function removeEntity(\obo\Entity $entity)
 {
     $primaryPropertyValue = $entity->primaryPropertyValue();
     $repositoryName = $entity->entityInformation()->repositoryName;
     unset($this->data[$repositoryName][$primaryPropertyValue]);
 }
コード例 #8
0
ファイル: EventManager.php プロジェクト: Hlavos/obo
 /**
  * @param \obo\Entity $entity
  * @return bool
  */
 public function isRegisteredEntity(\obo\Entity $entity)
 {
     return isset($this->registeredEntities[$entity->objectIdentificationKey()]);
 }
コード例 #9
0
ファイル: EntityManager.php プロジェクト: Hlavos/obo
 /**
  * @param \obo\Entity $entity
  * @param bool $triggerEvents
  * @return void
  * @throws \obo\Exceptions\EntityIsNotInitializedException
  */
 public static function deleteEntity(\obo\Entity $entity, $triggerEvents = true)
 {
     if (!$entity->isInitialized()) {
         throw new \obo\Exceptions\EntityIsNotInitializedException("Cannot delete entity which is not initialized");
     }
     $entity->setDeletingInProgress();
     if ($triggerEvents) {
         \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity("beforeDelete", $entity);
     }
     if (($propertyNameForSoftDelete = $entity->entityInformation()->propertyNameForSoftDelete) === "") {
         $entity->dataStorage()->removeEntity($entity);
     } else {
         $entity->discardNonPersistedChanges();
         $entity->setValueForPropertyWithName(true, $propertyNameForSoftDelete);
         self::saveEntity($entity, true, false);
     }
     $entity->setDeleted(true);
     if ($triggerEvents) {
         \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity("afterDelete", $entity);
     }
     $entity->setDeletingInProgress(false);
 }
コード例 #10
0
ファイル: EntityProperties.php プロジェクト: Hlavos/obo
 /**
  * @param string $name
  * @param mixed $value
  * @throws \obo\Exceptions\PropertyNotFoundException
  */
 public function __set($name, $value)
 {
     throw new \obo\Exceptions\PropertyNotFoundException("Can't write to the property with name '{$name}' in entity '" . $this->_owner->className() . "', it is read-only");
 }