|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Tomasz Kunicki <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace AppBundle\Controller\Unit; |
|
9
|
|
|
|
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Domain\Unit\UseCase\CreateUnit\CreateUnitRequest; |
|
12
|
|
|
use Domain\Unit\UseCase\CreateUnit\CreateUnitResponderInterface; |
|
13
|
|
|
use Domain\Unit\UseCase\CreateUnit\CreateUnitResponse; |
|
14
|
|
|
use Domain\Unit\UseCase\CreateUnit\CreateUnitUseCase; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
16
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
17
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class CreateUnitController |
|
21
|
|
|
* |
|
22
|
|
|
* @package AppBundle\Controller |
|
23
|
|
|
* @Route(service="unit.controller.create_unit") |
|
24
|
|
|
*/ |
|
25
|
|
|
class CreateUnitController extends Controller implements CreateUnitResponderInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var CreateUnitUseCase */ |
|
28
|
|
|
private $createUniteUseCase; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* CreateUnitController constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* @param CreateUnitUseCase $createUniteUseCase |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(CreateUnitUseCase $createUniteUseCase) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->createUniteUseCase = $createUniteUseCase; |
|
38
|
|
|
$this->createUniteUseCase->addResponder($this); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
43
|
|
|
* @Route("/new", name="unit_new") |
|
44
|
|
|
* @Method({"GET", "POST"}) |
|
45
|
|
|
* |
|
46
|
|
|
* @param $request |
|
47
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
|
48
|
|
|
*/ |
|
49
|
|
|
public function newAction(Request $request) |
|
50
|
|
|
{ |
|
51
|
|
|
$form = $this->createForm('AppBundle\Form\Type\UnitType'); |
|
52
|
|
|
$form->handleRequest($request); |
|
53
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
54
|
|
|
|
|
55
|
|
|
$data = $form->getData(); |
|
56
|
|
|
$createRequest = new CreateUnitRequest($data['name'], $data['shortcut']); |
|
57
|
|
|
$this->createUniteUseCase->execute($createRequest); |
|
58
|
|
|
|
|
59
|
|
|
return $this->redirectToRoute('unit_list'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $this->render( |
|
63
|
|
|
'AppBundle:Unit:new.html.twig', |
|
64
|
|
|
array( |
|
65
|
|
|
'form' => $form->createView(), |
|
66
|
|
|
) |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param CreateUnitResponse $response |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
public function unitCreated(CreateUnitResponse $response) |
|
75
|
|
|
{ |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|