Commit c5532954 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Trait pour PosteForm

parent 5aac246d
Loading
Loading
Loading
Loading
+6 −2
Changes for module/Application/src/Application/Controller/Poste/PosteController.php: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Application\Controller\Poste;

use Application\Entity\Db\Poste;
use Application\Form\Poste\PosteForm;
use Application\Form\Poste\PosteFormAwareTrait;
use Application\Service\Poste\PosteServiceAwareTrait;
use Octopus\Entity\Db\ImmobilierBatiment;
use Octopus\Service\Immobilier\ImmobilierServiceAwareTrait;
@@ -13,8 +14,11 @@ use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;

class PosteController extends AbstractActionController {
    /** Trait utilisés pour les services */
    use PosteServiceAwareTrait;
    use ImmobilierServiceAwareTrait;
    /** Trait utilisés pour les formulaires */
    use PosteFormAwareTrait;

    public function indexAction()
    {
@@ -44,7 +48,7 @@ class PosteController extends AbstractActionController {
        $poste = new Poste();

        /** @var PosteForm $form */
        $form = $this->getServiceLocator()->get('FormElementManager')->get(PosteForm::class);
        $form = $this->getPosteForm();
        $form->setAttribute('action', $this->url()->fromRoute('poste/ajouter', [], [], true));
        $form->bind($poste);

@@ -74,7 +78,7 @@ class PosteController extends AbstractActionController {
        $poste = $this->getPosteService()->getPoste($posteId);

        /** @var PosteForm $form */
        $form = $this->getServiceLocator()->get('FormElementManager')->get(PosteForm::class);
        $form = $this->getPosteForm();
        $form->setAttribute('action', $this->url()->fromRoute('poste/modifier', ['poste' => $poste->getId()], [], true));
        $form->bind($poste);

+10 −3
Changes for module/Application/src/Application/Controller/Poste/PosteControllerFactory.php: 10 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -2,25 +2,32 @@

namespace Application\Controller\Poste;

use Application\Form\Poste\PosteForm;
use Application\Service\Poste\PosteService;
use Octopus\Service\Immobilier\ImmobilierService;
use Zend\Mvc\Controller\ControllerManager;

class PosteControllerFactory {

    public function __invoke(ControllerManager $controllerManager)
    public function __invoke(ControllerManager $manager)
    {
        /**
         * @var PosteService $posteService
         * @var ImmobilierService $immobilierService
         */
        $posteService    = $controllerManager->getServiceLocator()->get(PosteService::class);
        $immobilierService    = $controllerManager->getServiceLocator()->get(ImmobilierService::class);
        $posteService    = $manager->getServiceLocator()->get(PosteService::class);
        $immobilierService    = $manager->getServiceLocator()->get(ImmobilierService::class);

        /**
         * @var PosteForm $posteForm
         */
        $posteForm = $manager->getServiceLocator()->get('FormElementManager')->get(PosteForm::class);

        /** @var PosteController $controller */
        $controller = new PosteController();
        $controller->setPosteService($posteService);
        $controller->setImmobiliserService($immobilierService);
        $controller->setPosteForm($posteForm);
        return $controller;
    }
}
 No newline at end of file
+29
Changes for module/Application/src/Application/Form/Poste/PosteFormAwareTrait.php: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Form\Poste;

trait PosteFormAwareTrait {

    /** @var PosteForm $posteForm */
    private $posteForm;

    /**
     * @return PosteForm
     */
    public function getPosteForm()
    {
        return $this->posteForm;
    }

    /**
     * @param PosteForm $posteForm
     * @return PosteForm
     */
    public function setPosteForm($posteForm)
    {
        $this->posteForm = $posteForm;
        return $this->posteForm;
    }


}
 No newline at end of file