|
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\ExpressionLanguage\Expression; |
|
18
|
|
|
|
|
19
|
|
|
class ConfigTypesPass implements CompilerPassInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public function process(ContainerBuilder $container) |
|
22
|
|
|
{ |
|
23
|
|
|
$config = $container->getParameter('overblog_graphql_types.config'); |
|
24
|
|
|
$generatedClasses = $container->get('overblog_graphql.cache_compiler')->compile($this->processConfig($config)); |
|
25
|
|
|
|
|
26
|
|
|
foreach ($generatedClasses as $class => $file) { |
|
27
|
|
|
$aliases = call_user_func($class.'::getAliases'); |
|
28
|
|
|
$this->setTypeServiceDefinition($container, $class, $aliases); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
private function setTypeServiceDefinition(ContainerBuilder $container, $class, array $aliases) |
|
33
|
|
|
{ |
|
34
|
|
|
$definition = $container->setDefinition($class, new Definition($class)); |
|
35
|
|
|
$definition->setPublic(false); |
|
36
|
|
|
$definition->setAutowired(true); |
|
37
|
|
|
foreach ($aliases as $alias) { |
|
38
|
|
|
$definition->addTag('overblog_graphql.type', ['alias' => $alias]); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function processConfig(array $configs) |
|
43
|
|
|
{ |
|
44
|
|
|
return array_map( |
|
45
|
|
|
function ($v) { |
|
46
|
|
|
if (is_array($v)) { |
|
47
|
|
|
return call_user_func([$this, 'processConfig'], $v); |
|
48
|
|
|
} elseif (is_string($v) && 0 === strpos($v, '@=')) { |
|
49
|
|
|
return new Expression(substr($v, 2)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $v; |
|
53
|
|
|
}, |
|
54
|
|
|
$configs |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|