|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
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 Sylius\Bundle\ResourceBundle\DependencyInjection\Extension; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\DriverProvider; |
|
15
|
|
|
use Sylius\Component\Resource\Metadata\Metadata; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractResourceExtension extends Extension |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @param string $applicationName |
|
26
|
|
|
* @param string $driver |
|
27
|
|
|
* @param array $resources |
|
28
|
|
|
* @param ContainerBuilder $container |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function registerResources($applicationName, $driver, array $resources, ContainerBuilder $container) |
|
31
|
|
|
{ |
|
32
|
|
|
$container->setParameter(sprintf('%s.driver.%s', $this->getAlias(), $driver), true); |
|
33
|
|
|
$container->setParameter(sprintf('%s.driver', $this->getAlias()), $driver); |
|
34
|
|
|
|
|
35
|
|
|
foreach ($resources as $resourceName => $resourceConfig) { |
|
36
|
|
|
$alias = $applicationName.'.'.$resourceName; |
|
37
|
|
|
$resourceConfig = array_merge(['driver' => $driver], $resourceConfig); |
|
38
|
|
|
|
|
39
|
|
|
$resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : []; |
|
40
|
|
|
$resources = array_merge($resources, [$alias => $resourceConfig]); |
|
41
|
|
|
$container->setParameter('sylius.resources', $resources); |
|
42
|
|
|
|
|
43
|
|
|
$metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig); |
|
44
|
|
|
|
|
45
|
|
|
DriverProvider::get($metadata)->load($container, $metadata); |
|
46
|
|
|
|
|
47
|
|
|
if ($metadata->hasParameter('translation')) { |
|
48
|
|
|
$alias = $alias.'_translation'; |
|
49
|
|
|
$resourceConfig = array_merge(['driver' => $driver], $resourceConfig['translation']); |
|
50
|
|
|
|
|
51
|
|
|
$resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : []; |
|
52
|
|
|
$resources = array_merge($resources, [$alias => $resourceConfig]); |
|
53
|
|
|
$container->setParameter('sylius.resources', $resources); |
|
54
|
|
|
|
|
55
|
|
|
$metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig); |
|
56
|
|
|
|
|
57
|
|
|
DriverProvider::get($metadata)->load($container, $metadata); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|