1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoS\ResourceBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use DoS\ResourceBundle\DependencyInjection\Compiler\ResolveDoctrineTargetEntitiesPass; |
6
|
|
|
use Sylius\Bundle\ResourceBundle\AbstractResourceBundle as BaseAbstractResourceBundle; |
7
|
|
|
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; |
8
|
|
|
use Symfony\Component\DependencyInjection\Container; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
10
|
|
|
|
11
|
|
|
abstract class AbstractResourceBundle extends BaseAbstractResourceBundle |
12
|
|
|
{ |
13
|
|
|
protected $mappingFormat = self::MAPPING_YAML; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
|
|
public static function getSupportedDrivers() |
19
|
|
|
{ |
20
|
|
|
return array( |
21
|
|
|
SyliusResourceBundle::DRIVER_DOCTRINE_ORM, |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function getModelNamespace() |
29
|
|
|
{ |
30
|
|
|
$bundle = explode('\\', $class = get_called_class()); |
31
|
|
|
|
32
|
|
|
return str_replace($bundle[count($bundle) - 1], 'Model', $class); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Dos expected alias (dos_xx not do_s_xx). |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public static function expectedAlias($name) |
41
|
|
|
{ |
42
|
|
|
return Container::underscore(preg_replace('/^DoS/', 'Dos', $name)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
protected function getBundlePrefix() |
49
|
|
|
{ |
50
|
|
|
return static::expectedAlias(substr(strrchr(get_class($this), '\\'), 1, -6)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function getContainerExtension() |
57
|
|
|
{ |
58
|
|
|
if (null === $this->extension) { |
59
|
|
|
$class = $this->getContainerExtensionClass(); |
60
|
|
|
if (class_exists($class)) { |
61
|
|
|
$extension = new $class(); |
62
|
|
|
|
63
|
|
|
// check naming convention |
64
|
|
|
$basename = preg_replace('/Bundle$/', '', $this->getName()); |
65
|
|
|
$expectedAlias = static::expectedAlias($basename); |
66
|
|
|
|
67
|
|
|
if ($expectedAlias != $extension->getAlias()) { |
68
|
|
|
throw new \LogicException(sprintf( |
69
|
|
|
'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', |
70
|
|
|
$expectedAlias, $extension->getAlias() |
71
|
|
|
)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->extension = $extension; |
75
|
|
|
} else { |
76
|
|
|
$this->extension = false; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($this->extension) { |
81
|
|
|
return $this->extension; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|