Exemplo n.º 1
0
 /**
  * Gets the identifier for an entity
  *
  * @param   object  $entity  The entity
  *
  * @return  array  The identifier as key-value pair(s)
  */
 protected function getIdentifier($entity)
 {
     $entityId = json_decode($this->entityRegistry->getEntityId($entity), true);
     if (is_array($entityId)) {
         $identifier = [];
         foreach ($entityId as $key => $value) {
             $key = strtolower(Normalise::toUnderscoreSeparated(Normalise::fromCamelCase($key)));
             $identifier[$key] = $value;
         }
         return $identifier;
     }
     $primary = $this->builder->getMeta(get_class($entity))->primary;
     return [$primary => $entityId];
 }
Exemplo n.º 2
0
 /**
  * Delete a tag for a master
  *
  * The system will detect the change and delete the entry in the map.
  * The tag itself will not be affected.
  */
 public function testDeleteATagForAMaster()
 {
     $this->restoreData(['masters', 'maps', 'tags']);
     $repo = $this->repo[Master::class];
     $master = $repo->getById(1);
     $tag = $master->tags->getById(1);
     $master->tags->remove($tag);
     $this->unitOfWork->commit();
     $this->entityRegistry->clear();
     $master = $repo->getById(1);
     $tags = $master->tags->findAll()->columns('tag')->getItems();
     $this->assertEquals(['Tag 2', 'Tag 3'], $tags);
     $tagRepo = $this->repo[Tag::class];
     $tag = $tagRepo->getById(1);
     $this->assertEquals('Tag 1', $tag->tag);
 }
 /**
  * Deletes an entity from the storage
  *
  * @param   object $entity The entity to delete
  *
  * @return  void
  *
  * @throws  OrmException  if the entity could not be deleted
  */
 public function delete($entity)
 {
     $persistor = new DoctrinePersistor($this->connection, $this->table, $this->entityRegistry->getEntityBuilder(), $this->entityRegistry);
     $persistor->delete($entity);
 }
 /**
  * Cast array to entity
  *
  * @param   array $matches The records
  *
  * @return  array
  */
 private function castToEntity($matches)
 {
     $entities = $this->entityRegistry->getEntityBuilder()->castToEntity($matches, $this->entityClass);
     return $entities;
 }
Exemplo n.º 5
0
 /**
  * Deletes an entity from the storage
  *
  * @param   object $entity The entity to delete
  *
  * @return  void
  *
  * @throws  OrmException  if the entity could not be deleted
  */
 public function delete($entity)
 {
     $persistor = new CsvPersistor($this->gateway, $this->table, $this->entityRegistry->getEntityBuilder(), $this->entityRegistry);
     $persistor->delete($entity);
 }