Skip to content

Commit 70e523b

Browse files
author
Codeliner
committed
Add Voyage Controller and form
1 parent f1fa452 commit 70e523b

File tree

3 files changed

+168
-0
lines changed

3 files changed

+168
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*
3+
* This file is part of the codeliner/php-ddd-cargo-sample package.
4+
* (c) Alexander Miertsch <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
namespace Application\Controller;
10+
11+
use Application\Domain\Model\Voyage;
12+
use Zend\Mvc\Controller\AbstractActionController;
13+
use Zend\View\Model\ViewModel;
14+
/**
15+
* MVC Controller for Voyage management
16+
*
17+
* @author Alexander Miertsch <[email protected]>
18+
*/
19+
class VoyageController extends AbstractActionController
20+
{
21+
/**
22+
*
23+
* @var Voyage\VoyageRepositoryInterface
24+
*/
25+
protected $voyageRepository;
26+
27+
28+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/*
3+
* This file is part of the codeliner/php-ddd-cargo-sample package.
4+
* (c) Alexander Miertsch <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
namespace Application\Form\Service;
10+
11+
use Zend\ServiceManager\FactoryInterface;
12+
use Zend\ServiceManager\ServiceLocatorInterface;
13+
use Application\Form\VoyageForm;
14+
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
15+
/**
16+
* VoyageFormFactory
17+
*
18+
* @author Alexander Miertsch <[email protected]>
19+
*/
20+
class VoyageFormFactory implements FactoryInterface
21+
{
22+
/**
23+
* {@inheritDoc}
24+
*/
25+
public function createService(ServiceLocatorInterface $serviceLocator)
26+
{
27+
$voyageHydrator = new DoctrineObject(
28+
$serviceLocator->get('doctrine.entitymanager.orm_default'),
29+
'Application\Domain\Model\Voyage\Voyage'
30+
);
31+
32+
$voyageForm = new VoyageForm();
33+
$voyageForm->setHydrator($voyageHydrator);
34+
35+
return $voyageForm;
36+
}
37+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/*
3+
* This file is part of the codeliner/php-ddd-cargo-sample package.
4+
* (c) Alexander Miertsch <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
namespace Application\Form;
10+
11+
use Zend\Form\Form;
12+
use Zend\InputFilter\Input;
13+
use Zend\InputFilter\InputFilter;
14+
use Zend\Validator\StringLength;
15+
use Zend\Validator\Digits;
16+
/**
17+
* VoyageForm
18+
*
19+
* @author Alexander Miertsch <[email protected]>
20+
*/
21+
class VoyageForm extends Form
22+
{
23+
public function __construct($name = null, $options = array())
24+
{
25+
parent::__construct('VoyageForm', $options);
26+
27+
$this->add(array(
28+
'name' => 'voyageNumber',
29+
'options' => array(
30+
'label' => 'Number',
31+
),
32+
'attributes' => array(
33+
'class' => 'form-control',
34+
),
35+
'type' => 'Text',
36+
37+
));
38+
39+
$this->add(array(
40+
'name' => 'name',
41+
'options' => array(
42+
'label' => 'Name',
43+
),
44+
'attributes' => array(
45+
'class' => 'form-control',
46+
),
47+
'type' => 'Text',
48+
49+
));
50+
51+
$this->add(array(
52+
'name' => 'capacity',
53+
'options' => array(
54+
'label' => 'Capacity',
55+
),
56+
'attributes' => array(
57+
'class' => 'form-control',
58+
),
59+
'type' => 'Text',
60+
61+
));
62+
63+
$this->add(array(
64+
'name' => 'send',
65+
'type' => 'Submit',
66+
'attributes' => array(
67+
'value' => 'Submit',
68+
'class' => 'btn btn-success'
69+
),
70+
));
71+
}
72+
73+
public function getInputFilter()
74+
{
75+
if (is_null($this->filter)) {
76+
$voyageNumberLengthValidator = new StringLength(30);
77+
$voyageNumberInput = new Input('voyage_number');
78+
$voyageNumberInput->setRequired(true)
79+
->getValidatorChain()
80+
->addValidator($voyageNumberLengthValidator);
81+
82+
$nameLengthValidator = new StringLength(100);
83+
$nameInput = new Input('name');
84+
$nameInput->setRequired(true);
85+
$nameInput->getValidatorChain()
86+
->addValidator($nameLengthValidator);
87+
88+
$digitsValidator = new Digits();
89+
$capacityInput = new Input('capacity');
90+
$capacityInput->setRequired(true);
91+
$capacityInput->getValidatorChain()
92+
->addValidator($digitsValidator);
93+
94+
95+
96+
$filter = new InputFilter();
97+
$filter->add($voyageNumberInput)->add($nameInput)->add($capacityInput);
98+
$this->filter = $filter;
99+
}
100+
101+
return $this->filter;
102+
}
103+
}

0 commit comments

Comments
 (0)