|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the LightSAML-Core package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Milos Tomic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LightSaml\Bridge\Pimple\Container\Factory; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\Bridge\Pimple\Container\SystemContainer; |
|
15
|
|
|
use LightSaml\Provider\TimeProvider\SystemTimeProvider; |
|
16
|
|
|
use Pimple\Container; |
|
17
|
|
|
use Pimple\ServiceProviderInterface; |
|
18
|
|
|
use Psr\Log\NullLogger; |
|
19
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; |
|
23
|
|
|
|
|
24
|
|
|
class SystemContainerProvider implements ServiceProviderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var bool */ |
|
27
|
|
|
private $mockSession; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct($mockSession = false) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$this->mockSession = true; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param Container $pimple A container instance |
|
36
|
|
|
*/ |
|
37
|
|
|
public function register(Container $pimple) |
|
38
|
|
|
{ |
|
39
|
|
|
$pimple[SystemContainer::REQUEST] = function () { |
|
40
|
|
|
return Request::createFromGlobals(); |
|
41
|
|
|
}; |
|
42
|
|
|
|
|
43
|
|
|
$pimple[SystemContainer::SESSION] = function () { |
|
44
|
|
|
if ($this->mockSession) { |
|
45
|
|
|
$session = new Session(new MockArraySessionStorage()); |
|
46
|
|
|
} else { |
|
47
|
|
|
$session = new Session(); |
|
48
|
|
|
} |
|
49
|
|
|
$session->setName(sprintf('SID%s', mt_rand(1000, 9999))); |
|
50
|
|
|
$session->start(); |
|
51
|
|
|
|
|
52
|
|
|
return $session; |
|
53
|
|
|
}; |
|
54
|
|
|
|
|
55
|
|
|
$pimple[SystemContainer::TIME_PROVIDER] = function () { |
|
56
|
|
|
return new SystemTimeProvider(); |
|
57
|
|
|
}; |
|
58
|
|
|
|
|
59
|
|
|
$pimple[SystemContainer::EVENT_DISPATCHER] = function () { |
|
60
|
|
|
return new EventDispatcher(); |
|
61
|
|
|
}; |
|
62
|
|
|
|
|
63
|
|
|
$pimple[SystemContainer::LOGGER] = function () { |
|
64
|
|
|
return new NullLogger(); |
|
65
|
|
|
}; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.