1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the zibios/wrike-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Zbigniew Ślązak |
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 Zibios\Bundle\WrikeBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
15
|
|
|
use Symfony\Component\Config\FileLocator; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
20
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
21
|
|
|
use Zibios\WrikePhpLibrary\Api; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Extension. |
25
|
|
|
*/ |
26
|
|
|
class ZibiosWrikeExtension extends Extension |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Loads the Wrike configuration. |
30
|
|
|
* |
31
|
|
|
* @param array $configs An array of configuration settings |
32
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance |
33
|
|
|
* |
34
|
|
|
* @throws \Exception |
35
|
|
|
*/ |
36
|
22 |
|
public function load(array $configs, ContainerBuilder $container) |
37
|
|
|
{ |
38
|
|
|
/** @var ConfigurationInterface $configuration */ |
39
|
22 |
|
$configuration = $this->getConfiguration($configs, $container); |
40
|
22 |
|
$config = $this->processConfiguration($configuration, $configs); |
41
|
11 |
|
$config = (array) $config; |
42
|
|
|
|
43
|
11 |
|
$container->setParameter('zibios_wrike', $config); |
44
|
11 |
|
foreach ($config as $key => $value) { |
45
|
8 |
|
$container->setParameter(sprintf('zibios_wrike.%s', $key), $value); |
46
|
|
|
} |
47
|
|
|
|
48
|
11 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
49
|
11 |
|
$loader->load('services.xml'); |
50
|
|
|
|
51
|
11 |
|
$this->addPermanentTokenAppDefinitions($config, $container); |
52
|
11 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the recommended alias to use in XML. |
56
|
|
|
* |
57
|
|
|
* @throws \BadMethodCallException When the extension name does not follow conventions |
58
|
|
|
* |
59
|
|
|
* @return string The alias |
60
|
|
|
*/ |
61
|
8 |
|
public function getAlias() |
62
|
|
|
{ |
63
|
8 |
|
return 'zibios_wrike'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param array $config |
68
|
|
|
* @param ContainerBuilder $container |
69
|
|
|
* |
70
|
|
|
* @throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException |
71
|
|
|
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException |
72
|
|
|
*/ |
73
|
11 |
|
protected function addPermanentTokenAppDefinitions(array $config, ContainerBuilder $container) |
74
|
|
|
{ |
75
|
11 |
|
if (isset($config['permanent_tokens']['tokens']) && is_array($config['permanent_tokens']['tokens'])) { |
76
|
|
|
/** @var array $tokens */ |
77
|
7 |
|
$tokens = $config['permanent_tokens']['tokens']; |
78
|
7 |
|
foreach ($tokens as $tokenName => $tokenCode) { |
79
|
7 |
|
$serviceId = sprintf('zibios_wrike.app.%s', strtolower($tokenName)); |
80
|
|
|
|
81
|
7 |
|
$definition = new Definition(Api::class); |
82
|
7 |
|
$definition->setFactory( |
83
|
|
|
[ |
84
|
7 |
|
new Reference('zibios_wrike.api_factory'), |
85
|
7 |
|
'createForPermanentToken', |
86
|
|
|
] |
87
|
|
|
); |
88
|
7 |
|
$definition->addArgument($tokenCode); |
89
|
|
|
|
90
|
7 |
|
$container->setDefinition($serviceId, $definition); |
91
|
|
|
} |
92
|
|
|
} |
93
|
11 |
|
} |
94
|
|
|
} |
95
|
|
|
|