Skip to content

Commit

Permalink
Reading an entity
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Feb 20, 2021
1 parent 511a076 commit d765127
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Process/Entity/ReadEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
namespace Pluf\Core\Process\Entity;

use Pluf\Orm\AssertionTrait;
use Pluf\Orm\EntityQuery;
use Pluf\Orm\EntityManager;

class ReadEntity
{
use AssertionTrait;

private string $class;
private string $name = "itemId";

public function __construct(string $class, string $name = "itemId")
{
$this->class = $class;
$this->name = $name;
}

/**
* Store list of cusomers into the repositoer
*
*
* @param EntityQuery $entityQuery to perform on entities
* @return array of results
*/
public function __invoke(EntityManager $entityManager, $itemId)
{
$result = $entityManager->find($this->class, $itemId);
$this->assertNotEmpty($result, 'Entity type {{type}} not found with ID {{itemId}', [
'type' => $this->class,
'itemId' => $itemId
]);
return $result;
}

}

0 comments on commit d765127

Please sign in to comment.