Skip to content

Commit

Permalink
Merge pull request #14 from claudio-dalicandro/master
Browse files Browse the repository at this point in the history
Fix camelCase context name
  • Loading branch information
liuggio committed Jan 20, 2014
2 parents 837ea01 + cab9b46 commit 3c6e20d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PUGX\GodfatherBundle\DependencyInjection;

use PUGX\Godfather\ServiceNameConverter;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Definition;
Expand All @@ -16,6 +17,16 @@
*/
class GodfatherExtension extends Extension
{
/**
* @var \PUGX\Godfather\ServiceNameConverter
*/
protected $nameConverter;

public function __construct(ServiceNameConverter $serviceNameConverter = null)
{
$this->nameConverter = $serviceNameConverter ?: new ServiceNameConverter();
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -65,6 +76,8 @@ protected function addInstance($name, array $parameters, ContainerBuilder $conta
*/
protected function addContext(ContainerBuilder $container, $prefix, $name, array $context)
{
$name = $this->nameConverter->serviceNameConverter($name);

$serviceName = $prefix.'.'.$name;
if (isset($context['fallback']) || isset($context['class'])) {

Expand Down Expand Up @@ -129,7 +142,7 @@ protected function createGodFatherDefinition(ContainerBuilder $container, $prefi
*/
protected function createServiceContainerDefinition(ContainerBuilder $container, $prefix)
{
$container = new Definition('%godfather.class%');
$container = new Definition('%godfather.class%');

return new Definition('%godfather.class%', array($container, $prefix));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ public function testMultipleInstances()
$this->assertTrue($container->hasDefinition('godfather.instance1.manager'));
}

public function testInstanceName()
{
$container = new ContainerBuilder();
$loader = new GodfatherExtension();
$loader->load(array($this->getConfigWithCamelCaseNamedContext()), $container);

$this->assertTrue($container->hasAlias('godfather.object_manager'));
}



protected function getConfigWithCamelCaseNamedContext()
{
$yaml = <<<EOF
default:
contexts:
objectManager: ~
EOF;
$parser = new Parser();

return $parser->parse($yaml);
}

protected function getFullConfigWithMultipleInstances()
{
$yaml = <<<EOF
Expand Down

0 comments on commit 3c6e20d

Please sign in to comment.