use NilPortugues\Foundation\Infrastructure\Model\Repository\EloquentMongoDB\EloquentRepository;
class UserRepository extends EloquentRepository
{
/**
* {@inheritdoc}
*/
protected function modelClassName()
{
return User::class;
}
}
use NilPortugues\Foundation\Infrastructure\Model\Repository\EloquentMongoDB\EloquentRepository;
class UserRepository extends EloquentRepository
{
protected $userAdapter;
/**
* @param $userAdapter
*/
public function __construct($userAdapter)
{
$this->userAdapter = $userAdapter;
}
/**
* {@inheritdoc}
*/
protected function modelClassName()
{
return User::class;
}
/**
* {@inheritdoc}
*/
public function find(Identity $id, Fields $fields = null)
{
$eloquentModel = parent::find($id, $fields);
return $this->userAdapter->fromEloquent($eloquentModel);
}
/**
* {@inheritdoc}
*/
public function findBy(Filter $filter = null, Sort $sort = null, Fields $fields = null)
{
$eloquentModelArray = parent::findBy($filter, $sort, $fields);
return $this->fromEloquentArray($eloquentModelArray);
}
/**
* {@inheritdoc}
*/
public function findAll(Pageable $pageable = null)
{
$page = parent::findAll($pageable);
return new Page(
$this->fromEloquentArray($page->content()),
$page->totalElements(),
$page->pageNumber(),
$page->totalPages(),
$page->sortings(),
$page->filters(),
$page->fields()
);
}
/**
* {@inheritdoc}
*/
public function add(Identity $value)
{
$value = $this->userAdapter->toEloquent($value);
return parent::add($value);
}
/**
* {@inheritdoc}
*/
public function addAll(array $values)
{
$eloquent = [];
foreach ($values as $value) {
$eloquent[] = $this->userAdapter->toEloquent($value);
}
parent::addAll($eloquent);
}
/**
* @param array $eloquentModelArray
* @return array
*/
protected function fromEloquentArray(array $eloquentModelArray)
{
$results = [];
foreach ($eloquentModelArray as $eloquentModel) {
//This is
use NilPortugues\Foundation\Infrastructure\Model\Repository\EloquentMongoDB\EloquentRepository;
class EloquentMongoDBRepository extends EloquentRepository
{
/**
* @var string
*/
protected $modelClass;
/**
* @param string $modelClass
*/
public function __construct($modelClass)
{
$this->modelClass = (string) $modelClass;
}
/**
* {@inheritdoc}
*/
protected function modelClassName()
{
return $this->modelClass;
}
}
use NilPortugues\Foundation\Domain\Model\Repository\Filter;
$repository = new UserRepository();
$filter = new Filter();
$filter->must()->contain('name', 'Ken');
echo $repository->count($filter);
use NilPortugues\Foundation\Domain\Model\Repository\Sort;
$repository = new UserRepository();
$filter = null; //all records
$sort = new Sort(['name', 'id'], new Order('ASC', 'DESC'));
$fields = null; //all columns
$results = $repository->findBy($filter, $sort, $fields);
use NilPortugues\Foundation\Domain\Model\Repository\Contracts\Fields;
$repository = new UserRepository();
$filter = null; //all records
$sort = null; //existing order
$fields = new Fields(['name', 'id']);
$results = $repository->findBy($filter, $sort, $fields);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.