AssertionFactory.php 1.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

namespace UnicaenAuth\Assertion;

use BjyAuthorize\Service\Authorize;
use Interop\Container\ContainerInterface;
use Zend\Authentication\AuthenticationService;
use Zend\Mvc\Application;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
 * Class AssertionFactory
 *
 * @package UnicaenAuth\Assertion
 */
class AssertionFactory implements FactoryInterface
{
    /**
     * @param ContainerInterface $container
     *
     * @return UserContext
     */
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        /* @var $application Application */
        $application = $container->get('Application');
        $mvcEvent    = $application->getMvcEvent();

        /* @var $serviceAuthorize Authorize */
        $serviceAuthorize = $container->get('BjyAuthorize\Service\Authorize');

        /** @var UserContext $serviceUserContext */
        $serviceUserContext = $container->get('UnicaenAuth\Service\UserContext');

        /* @var $assertion AbstractAssertion */
        $assertion = new $requestedName;

        $assertion->setMvcEvent($mvcEvent);
        $assertion->setServiceAuthorize($serviceAuthorize);
        $assertion->setServiceUserContext($serviceUserContext);

        return $assertion;
    }
}