diff --git a/DependencyInjection/JMSDiExtraExtension.php b/DependencyInjection/JMSDiExtraExtension.php
index fab9623..e5cac51 100644
--- a/DependencyInjection/JMSDiExtraExtension.php
+++ b/DependencyInjection/JMSDiExtraExtension.php
@@ -53,6 +53,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('jms_di_extra.cache_dir', $config['cache_dir']);
$container->setParameter('jms_di_extra.disable_grep', $config['disable_grep']);
$container->setParameter('jms_di_extra.doctrine_integration', $config['doctrine_integration']);
+
if ($config['cache_warmer']['enabled']) {
foreach ($config['cache_warmer']['controller_file_blacklist'] as $filename) {
$this->blackListControllerFile($filename);
diff --git a/Metadata/DefaultNamingStrategy.php b/Metadata/DefaultNamingStrategy.php
new file mode 100644
index 0000000..3903efd
--- /dev/null
+++ b/Metadata/DefaultNamingStrategy.php
@@ -0,0 +1,20 @@
+reader = $reader;
+ $this->namingStrategy = $namingStrategy;
}
public function loadMetadataForClass(\ReflectionClass $class)
@@ -69,7 +72,7 @@ public function loadMetadataForClass(\ReflectionClass $class)
foreach ($this->reader->getClassAnnotations($class) as $annot) {
if ($annot instanceof Service) {
if (null === $annot->id) {
- $metadata->id = $this->generateId($className);
+ $metadata->id = $this->namingStrategy->classToServiceName($className);
} else {
$metadata->id = $annot->id;
}
@@ -83,7 +86,7 @@ public function loadMetadataForClass(\ReflectionClass $class)
} else if ($annot instanceof Validator) {
// automatically register as service if not done explicitly
if (null === $metadata->id) {
- $metadata->id = $this->generateId($className);
+ $metadata->id = $this->namingStrategy->classToServiceName($className);
}
$metadata->tags['validator.constraint_validator'][] = array(
@@ -91,7 +94,7 @@ public function loadMetadataForClass(\ReflectionClass $class)
);
} else if ($annot instanceof AbstractDoctrineListener) {
if (null === $metadata->id) {
- $metadata->id = $this->generateId($className);
+ $metadata->id = $this->namingStrategy->classToServiceName($className);
}
foreach ($annot->events as $event) {
@@ -104,7 +107,7 @@ public function loadMetadataForClass(\ReflectionClass $class)
}
} else if ($annot instanceof FormType) {
if (null === $metadata->id) {
- $metadata->id = $this->generateId($className);
+ $metadata->id = $this->namingStrategy->classToServiceName($className);
}
$alias = $annot->alias;
@@ -210,7 +213,7 @@ public function loadMetadataForClass(\ReflectionClass $class)
private function convertReferenceValue($name, AnnotReference $annot)
{
if (null === $annot->value) {
- return new Reference($this->generateId($name), false !== $annot->required ? ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE : ContainerInterface::NULL_ON_INVALID_REFERENCE, $annot->strict);
+ return new Reference($this->namingStrategy->classToServiceName($name), false !== $annot->required ? ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE : ContainerInterface::NULL_ON_INVALID_REFERENCE, $annot->strict);
}
if (false === strpos($annot->value, '%')) {
@@ -219,11 +222,4 @@ private function convertReferenceValue($name, AnnotReference $annot)
return $annot->value;
}
-
- private function generateId($name)
- {
- $name = preg_replace('/(?<=[a-zA-Z0-9])[A-Z]/', '_\\0', $name);
-
- return strtolower(strtr($name, '\\', '.'));
- }
}
diff --git a/Metadata/NamingStrategy.php b/Metadata/NamingStrategy.php
new file mode 100644
index 0000000..8084293
--- /dev/null
+++ b/Metadata/NamingStrategy.php
@@ -0,0 +1,15 @@
+JMS\DiExtraBundle\Metadata\Driver\ConfiguredControllerInjectionsDriver
Metadata\Driver\LazyLoadingDriver
+ JMS\DiExtraBundle\Metadata\DefaultNamingStrategy
+
Metadata\MetadataFactory
Metadata\Cache\FileCache
@@ -22,7 +24,10 @@
+
+
diff --git a/Tests/Metadata/Driver/AnnotationDriverTest.php b/Tests/Metadata/Driver/AnnotationDriverTest.php
index 200404f..459657f 100644
--- a/Tests/Metadata/Driver/AnnotationDriverTest.php
+++ b/Tests/Metadata/Driver/AnnotationDriverTest.php
@@ -3,6 +3,7 @@
namespace JMS\DiExtraBundle\Tests\Metadata\Driver;
use Doctrine\Common\Annotations\AnnotationReader;
+use JMS\DiExtraBundle\Metadata\DefaultNamingStrategy;
use JMS\DiExtraBundle\Metadata\Driver\AnnotationDriver;
class AnnotationDriverTest extends \PHPUnit_Framework_TestCase
@@ -32,6 +33,6 @@ public function testFormTypeWithExplicitAlias()
private function getDriver()
{
- return new AnnotationDriver(new AnnotationReader());
+ return new AnnotationDriver(new AnnotationReader(), new DefaultNamingStrategy());
}
}