Esempio 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];
 }
 /**
  * @testdox Entities fetched by id are turned into objects using the EntityBuilder
  */
 public function testGetById()
 {
     $this->builder->expects($this->any())->method('castToEntity')->with([$this->articles[1]])->willReturn([(object) $this->articles[1]]);
     $article = $this->dataMapper->getById(1);
     $this->assertEquals(1, $article->id);
 }
 /**
  * @param $article
  *
  * @depends testResolve
  * @testdox reduce() extracts the database structure from an entity
  */
 public function testReduce($article)
 {
     $row = $this->builder->reduce($article);
     $this->assertEquals($this->articles[1], $row);
 }
Esempio n. 4
0
 /**
  * Resolves an alias to a class name
  *
  * @param   string  $alias  The class alias or name
  *
  * @return  string  The fully qualified class name
  */
 public function resolveAlias($alias)
 {
     return $this->builder->resolveAlias($alias);
 }
 /**
  * Build a prototype (once) for the entity.
  *
  * @return  void
  */
 private function buildPrototype()
 {
     if (empty($this->prototype)) {
         $this->prototype = $this->builder->create($this->entityName);
     }
 }