Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Last active May 25, 2023 08:39
Show Gist options
  • Save webdevilopers/5b0e90031b6a0c5da3bc to your computer and use it in GitHub Desktop.
Save webdevilopers/5b0e90031b6a0c5da3bc to your computer and use it in GitHub Desktop.

Revisions

  1. webdevilopers revised this gist Aug 7, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions ContractController.php
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,8 @@ class ContractAdminController extends Controller
    */
    public function invoiceAction(Request $request)
    {
    // ...
    $invoice = new Invoice($contract);
    // ...
    // $invoice = $this->get('contract.invoice');
    $invoice = new Invoice($contract, $em->getRepository('PlusquamContractBundle:Contract'));
    }
    }
  2. webdevilopers revised this gist Aug 7, 2015. 1 changed file with 31 additions and 0 deletions.
    31 changes: 31 additions & 0 deletions Invoice.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    <?php

    namespace Plusquam\Bundle\ContractBundle\Service;

    use Doctrine\ORM\EntityRepository;

    class Invoice
    {
    private $repository;

    private $contract;

    private $filters;

    private $timeAndExpense;

    public function __construct($contract, EntityRepository $repository) {
    $this->contract = $contract;
    $this->repository = $repository;
    }

    public function setFilters($filters)
    {
    $this->filters = $filters;
    }

    public function getTimeAndExpense()
    {
    return $this->repository->getTimeAndExpenseByContract($this->filters);
    }
    }
  3. webdevilopers created this gist Aug 7, 2015.
    17 changes: 17 additions & 0 deletions ContractController.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?php

    use Plusquam\Bundle\ContractBundle\Service\Invoice;

    class ContractAdminController extends Controller
    {
    /**
    * Invoice action
    *
    * @return Response
    */
    public function invoiceAction(Request $request)
    {
    // ...
    $invoice = new Invoice($contract);
    }
    }
    12 changes: 12 additions & 0 deletions services.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    services:
    contract.repository:
    class: Doctrine\ORM\EntityRepository
    factory_service: doctrine.orm.entity_manager
    factory_method: getRepository
    arguments:
    - Plusquam\Bundle\ContractBundle\Entity\Contract

    contract.invoice:
    class: Plusquam\Bundle\ContractBundle\Service\Invoice
    arguments:
    - "@contract.repository"