1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of PhpUnitGen. |
5
|
|
|
* |
6
|
|
|
* (c) 2017-2018 Paul Thébaud <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PhpUnitGen\Container; |
13
|
|
|
|
14
|
|
|
use PhpParser\Parser; |
15
|
|
|
use PhpParser\ParserFactory; |
16
|
|
|
use PhpUnitGen\Configuration\ConfigurationInterface\ConfigInterface; |
17
|
|
|
use PhpUnitGen\Configuration\ConfigurationInterface\ConsoleConfigInterface; |
18
|
|
|
use PhpUnitGen\Container\ContainerInterface\ContainerFactoryInterface; |
19
|
|
|
use PhpUnitGen\Executor\Executor; |
20
|
|
|
use PhpUnitGen\Executor\ExecutorInterface\ExecutorInterface; |
21
|
|
|
use PhpUnitGen\Parser\ParserInterface\PhpParserInterface; |
22
|
|
|
use PhpUnitGen\Parser\PhpParser; |
23
|
|
|
use PhpUnitGen\Renderer\PhpFileRenderer; |
24
|
|
|
use PhpUnitGen\Renderer\RendererInterface\PhpFileRendererInterface; |
25
|
|
|
use PhpUnitGen\Report\Report; |
26
|
|
|
use PhpUnitGen\Report\ReportInterface\ReportInterface; |
27
|
|
|
use Psr\Container\ContainerInterface; |
28
|
|
|
use Slim\Views\PhpRenderer; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class ContainerFactory. |
32
|
|
|
* |
33
|
|
|
* @author Paul Thébaud <[email protected]>. |
34
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
35
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
36
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
37
|
|
|
* @since Class available since Release 2.0.0. |
38
|
|
|
*/ |
39
|
|
|
class ContainerFactory implements ContainerFactoryInterface |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function invoke( |
45
|
|
|
ConfigInterface $config |
46
|
|
|
): ContainerInterface { |
47
|
|
|
$container = new Container(); |
48
|
|
|
|
49
|
|
|
// Configuration |
50
|
|
|
$container->setInstance(ConfigInterface::class, $config); |
51
|
|
|
$container->setInstance(ConsoleConfigInterface::class, $config); |
52
|
|
|
// Php parser |
53
|
|
|
$container->setInstance(Parser::class, (new ParserFactory())->create(ParserFactory::PREFER_PHP7)); |
54
|
|
|
// Php renderer |
55
|
|
|
$container->setInstance(PhpRenderer::class, new PhpRenderer($config->getTemplatesPath())); |
56
|
|
|
|
57
|
|
|
// Automatically created dependencies and aliases |
58
|
|
|
$container->set(PhpParserInterface::class, PhpParser::class); |
59
|
|
|
$container->set(ExecutorInterface::class, Executor::class); |
60
|
|
|
$container->set(ReportInterface::class, Report::class); |
61
|
|
|
$container->set(PhpFileRendererInterface::class, PhpFileRenderer::class); |
62
|
|
|
|
63
|
|
|
return $container; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|