示例#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
 /**
  * @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
 /**
  * @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");
     }
 }
 /**
  * @param \obo\Entity $entity
  */
 public function removeEntity(\obo\Entity $entity)
 {
     $primaryPropertyValue = $entity->primaryPropertyValue();
     $repositoryName = $entity->entityInformation()->repositoryName;
     unset($this->data[$repositoryName][$primaryPropertyValue]);
 }
示例#8
0
 /**
  * @param \obo\Entity $entity
  * @return bool
  */
 public function isRegisteredEntity(\obo\Entity $entity)
 {
     return isset($this->registeredEntities[$entity->objectIdentificationKey()]);
 }
示例#9
0
 /**
  * @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
 /**
  * @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");
 }