Completed
Pull Request — 1.x (#627)
by Dylan
08:40
created

ChangeEmail::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 12
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Clayton Daley
5
 * Date: 3/10/2015
6
 * Time: 9:34 AM
7
 */
8
9
namespace ZfcUser\Factory\Form;
10
11
use Zend\Form\FormElementManager;
12
use Zend\ServiceManager\FactoryInterface;
13
use Zend\ServiceManager\ServiceLocatorInterface;
14
use ZfcUser\Form;
15
use ZfcUser\Options\AuthenticationOptionsInterface;
16
use ZfcUser\Validator;
17
18
class ChangeEmail implements FactoryInterface
19
{
20
    public function createService(ServiceLocatorInterface $formElementManager)
21
    {
22
        /** @var FormElementManager $formElementManager */
23
        $fem = $formElementManager;
24
        $sm = $formElementManager->getServiceLocator();
25
        /** @var AuthenticationOptionsInterface $options */
26
        $options = $sm->get('zfcuser_module_options');
27
        $form = new Form\ChangeEmail(null, $options);
28
        // Inject the FormElementManager to support custom FormElements
29
        $form->getFormFactory()->setFormElementManager($fem);
30
31
        $form->setInputFilter(new Form\ChangeEmailFilter(
32
            $options,
33
            new Validator\NoRecordExists(array(
34
                'mapper' => $sm->get('zfcuser_user_mapper'),
35
                'key' => 'email'
36
            ))
37
        ));
38
39
        return $form;
40
    }
41
}
42