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

Trait pour AgentForm

parent 2411b4a2
Loading
Loading
Loading
Loading
+6 −2
Changes for module/Application/src/Application/Controller/Agent/AgentController.php: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Application\Controller\Agent;

use Application\Entity\Db\Agent;
use Application\Form\Agent\AgentForm;
use Application\Form\Agent\AgentFormAwareTrait;
use Application\Service\Agent\AgentServiceAwareTrait;
use Zend\Http\Request;
use Zend\Mvc\Controller\AbstractActionController;
@@ -11,7 +12,10 @@ use Zend\View\Model\ViewModel;

class AgentController extends AbstractActionController
{
    /** Trait utilisés pour les services */
    use AgentServiceAwareTrait;
    /** Trait utilisés pour les formulaires */
    use AgentFormAwareTrait;

    public function indexAction()
    {
@@ -38,7 +42,7 @@ class AgentController extends AbstractActionController
        $agent = new Agent();

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

@@ -68,7 +72,7 @@ class AgentController extends AbstractActionController
        $agent = $this->getAgentService()->getAgent($agentId);

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

+7 −2
Changes for module/Application/src/Application/Controller/Agent/AgentControllerFactory.php: 7 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,19 +2,24 @@

namespace Application\Controller\Agent;

use Application\Form\Agent\AgentForm;
use Application\Service\Agent\AgentService;
use Zend\Mvc\Controller\ControllerManager;

class AgentControllerFactory {

    public function __invoke(ControllerManager $controllerManager)
    public function __invoke(ControllerManager $manager)
    {
        /** @var AgentService $agentService */
        $agentService = $controllerManager->getServiceLocator()->get(AgentService::class);
        $agentService = $manager->getServiceLocator()->get(AgentService::class);

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

        /** @var AgentController $controller */
        $controller = new AgentController();
        $controller->setAgentService($agentService);
        $controller->setAgentForm($agentForm);
        return $controller;
    }
}
 No newline at end of file
+27
Changes for module/Application/src/Application/Form/Agent/AgentFormAwareTrait.php: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Form\Agent;

trait AgentFormAwareTrait {

    /** @var AgentForm $agentForm */
    private $agentForm;

    /**
     * @return AgentForm
     */
    public function getAgentForm()
    {
        return $this->agentForm;
    }

    /**
     * @param AgentForm $agentForm
     * @return AgentForm
     */
    public function setAgentForm($agentForm)
    {
        $this->agentForm = $agentForm;
        return $this->agentForm;
    }
}
 No newline at end of file