1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
18
|
|
|
use Symfony\Component\ExpressionLanguage\Expression; |
19
|
|
|
|
20
|
|
|
class TypesPass implements CompilerPassInterface |
21
|
|
|
{ |
22
|
8 |
|
public function process(ContainerBuilder $container) |
23
|
|
|
{ |
24
|
8 |
|
$config = $container->getParameter('overblog_graphql_types.config'); |
25
|
8 |
|
$classes = array_keys($container->get('overblog_graphql.cache_compiler')->compile($this->processConfig($config))); |
26
|
|
|
|
27
|
8 |
|
foreach ($classes as $class) { |
28
|
8 |
|
$name = $class::getName(); |
29
|
|
|
|
30
|
8 |
|
$customTypeId = sprintf('overblog_graphql.definition.custom_%s_type', $container->underscore($name)); |
31
|
|
|
|
32
|
|
|
$container |
33
|
8 |
|
->setDefinition($customTypeId, new Definition($class)) |
34
|
8 |
|
->setArguments([new Reference('service_container')]) |
35
|
8 |
|
->addTag('overblog_graphql.type', ['alias' => $name]) |
36
|
|
|
; |
37
|
8 |
|
} |
38
|
8 |
|
} |
39
|
|
|
|
40
|
8 |
|
private function processConfig(array $configs) |
41
|
|
|
{ |
42
|
8 |
|
return array_map( |
43
|
8 |
|
function ($v) { |
44
|
8 |
|
if (is_array($v)) { |
45
|
8 |
|
return call_user_func([$this, 'processConfig'], $v); |
46
|
8 |
|
} elseif (is_string($v) && 0 === strpos($v, '@=')) { |
47
|
7 |
|
return new Expression(substr($v, 2)); |
48
|
|
|
} |
49
|
|
|
|
50
|
8 |
|
return $v; |
51
|
8 |
|
}, |
52
|
|
|
$configs |
53
|
8 |
|
); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|