/** * Setting an entity object. * * This can be simplified even further, by not accepting an entity name but use the name of the object. I choose * not to do that, to be more consistent in this example. In production code I probably would, however. * * @param $entityName * @param \EntityInterface $object * @return IdentityMap */ public function set($entityName, EntityInterface $object) { if (isset($this->container[$entityName][$object->getId()])) { // At this point, the key already exists, this might be something we want to act against. // To keep it simple, I don't do anything in this example. } // Define an entry, based on the entity name, and the ID (primary key) of the entity $this->container[$entityName][$object->getId()] = $object; // Return this, so that we can easily chain set calls. (Fluent interface) return $this; }
public function has(EntityInterface $entity) { return $this->hasEntity($entity->getId()); }
/** * Renders linked resource object. * @param EntityInterface $entity * @param EntityInterface $subEntity * @param Relation $relation * @return array */ protected function renderLinkedResourceObject(EntityInterface $entity, EntityInterface $subEntity, Relation $relation) { $resourceObject = array(); $resourceObject['id'] = (string) $subEntity->getId(); if ($this->attachResourceObjectHref) { $binds = array($this->collectionName => $entity->getId(), $relation->getCollectionName() => $subEntity->getId()); $href = $this->prepareHref($relation->getHref(), $binds); $resourceObject['href'] = $href; } $resourceObject += $subEntity->toArray(); return $resourceObject; }
/** * Удаление записи * @param EntityInterface $Entity * @return boolean */ public function delete(EntityInterface $Entity) { $result = false; $delete_key = $this->setSoftDeleteKey(); if ($delete_key > '' && $Entity->getId() > 0) { $result = $this->getAdapter()->update($this->getEntityTable(), [$delete_key => 1], "{$this->getPrimaryKey()} = '{$Entity->getId()}'"); } elseif ($Entity->getId() > 0) { if ($result = $this->getAdapter()->delete($this->getEntityTable(), $this->getPrimaryKey() . " = " . $Entity->getId())) { if (method_exists($this, 'onBeforeDelete')) { $result = $this->onBeforeDelete($Entity); } } } return $result; }
/** * Delete record. * * @param EntityInterface $entity * @return boolean */ public function delete(EntityInterface $entity) { return $this->deleteById($entity->getId()); }