Skip to content

Instantly share code, notes, and snippets.

@mikemix
Last active February 8, 2019 12:12
Show Gist options
  • Save mikemix/c0092208216e4f07dd0f0c6e4978fbe7 to your computer and use it in GitHub Desktop.
Save mikemix/c0092208216e4f07dd0f0c6e4978fbe7 to your computer and use it in GitHub Desktop.
Focused repositories
<?php
declare(strict_types=1);
namespace Base\Organizers\Infrastructure\Domain\Repository;
use Base\Organizers\Domain\Model\Company;
use Base\Organizers\Domain\Repository\CompanyCollection;
use Doctrine\Common\Persistence\ObjectManager;
final class DoctrineCompanyCollection implements CompanyCollection
{
private $objectManager;
public function __construct(ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
}
public function add(Company $company): void
{
$this->objectManager->persist($company);
$this->objectManager->flush();
}
public function remove(Company $company): void
{
$this->objectManager->remove($company);
$this->objectManager->flush();
}
}
<?php
declare(strict_types=1);
namespace Base\Organizers\Infrastructure\Domain\Repository;
use Base\Organizers\Domain\Model\Field;
use Base\Organizers\Domain\Repository\FieldsByCompany;
use Base\SharedKernel\Identification\CompanyId;
use Doctrine\Common\Persistence\ObjectManager;
final class DoctrineFieldsByCompany implements FieldsByCompany
{
private $objectManager;
public function __construct(ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
}
public function getFieldsByCompany(CompanyId $companyId): array
{
return $this->objectManager->getRepository(Field::class)->findBy(['company' => $companyId], ['position' => 'asc']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment