Skip to content

Commit

Permalink
Revert Repository class and interface to avoid BC break
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Oct 15, 2020
1 parent c2be2c0 commit 250d47a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
32 changes: 25 additions & 7 deletions src/Repository/DoctrineInvoiceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,43 @@

@trigger_error('The "DoctrineInvoiceRepository" class is deprecated since version 1.0.0 Use standardized class located at "src/Doctrine/ORM/" instead.');

use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Sylius\InvoicingPlugin\Entity\Invoice;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Webmozart\Assert\Assert;

final class DoctrineInvoiceRepository extends EntityRepository implements InvoiceRepository
final class DoctrineInvoiceRepository implements InvoiceRepository
{
/** @var EntityManagerInterface */
private $entityManager;

/** @var ObjectRepository */
private $entityRepository;

public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
$this->entityRepository = $entityManager->getRepository(Invoice::class);
}

public function get(string $invoiceId): InvoiceInterface
{
/** @var InvoiceInterface|null $invoice */
$invoice = $this->find($invoiceId);
Assert::notNull($invoice);
/** @var InvoiceInterface $invoice */
$invoice = $this->entityRepository->find($invoiceId);

return $invoice;
}

public function add(InvoiceInterface $invoice): void
{
$this->entityManager->persist($invoice);
$this->entityManager->flush();
}

public function findOneByOrderNumber(string $orderNumber): ?InvoiceInterface
{
/** @var InvoiceInterface|null $invoice */
$invoice = $this->findOneBy(['orderNumber' => $orderNumber]);
$invoice = $this->entityRepository->findOneBy(['orderNumber' => $orderNumber]);

return $invoice;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Repository/InvoiceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

@trigger_error('The "InvoiceRepository" interface is deprecated since version 1.0.0 Use standardized interface located at "src/Doctrine/ORM/" instead.');

use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;

interface InvoiceRepository extends RepositoryInterface
interface InvoiceRepository
{
public function get(string $invoiceId): InvoiceInterface;

public function findOneByOrderNumber(string $orderNumber): ?InvoiceInterface;

public function add(InvoiceInterface $invoice): void;
}
6 changes: 1 addition & 5 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
<service id="sylius_invoicing_plugin.date_time_provider" class="Sylius\InvoicingPlugin\SystemDateTimeProvider" />

<service id="sylius_invoicing_plugin.custom_repository.invoice" class="Sylius\InvoicingPlugin\Repository\DoctrineInvoiceRepository">
<deprecated>
The "%service_id%" service is deprecated since version 0.11.1
and will be removed in version 1.0.0
use sylius_invoicing_plugin.repository.invoice service instead
</deprecated>
<deprecated>The "%service_id%" service is deprecated since version 0.11.1 and will be removed in version 1.0.0 use sylius_invoicing_plugin.repository.invoice service instead</deprecated>
</service>

<service id="sylius_invoicing_plugin.email.invoice_email_sender" class="Sylius\InvoicingPlugin\Email\InvoiceEmailSender">
Expand Down

0 comments on commit 250d47a

Please sign in to comment.