Author: fabien
Date: 2010-01-22 11:00:08 +0100 (Fri, 22 Jan 2010)
New Revision: 27033
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderTest.php
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php
Log:
Merge branch 'master' of git://github.com/symfony/symfony
Modified: branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
===================================================================
--- branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
2010-01-22 09:58:37 UTC (rev 27032)
+++ branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
2010-01-22 10:00:08 UTC (rev 27033)
@@ -175,6 +175,18 @@
}
/**
+ * Returns true if an alias exists under the given identifier.
+ *
+ * @param string $id The service identifier
+ *
+ * @return Boolean true if the alias exists, false otherwise
+ */
+ public function hasAlias($id)
+ {
+ return array_key_exists($id, $this->aliases);
+ }
+
+ /**
* Gets all defined aliases.
*
* @return array An array of aliases
@@ -185,6 +197,25 @@
}
/**
+ * Gets an alias.
+ *
+ * @param string $id The service identifier
+ *
+ * @return string The aliased service identifier
+ *
+ * @throws \InvalidArgumentException if the alias does not exist
+ */
+ public function getAlias($id)
+ {
+ if (!$this->hasAlias($id))
+ {
+ throw new \InvalidArgumentException(sprintf('The service alias "%s" does
not exist.', $id));
+ }
+
+ return $this->aliases[$id];
+ }
+
+ /**
* Registers a service definition.
*
* This methods allows for simple registration of service definition
Modified: branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
===================================================================
--- branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
2010-01-22 09:58:37 UTC (rev 27032)
+++ branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
2010-01-22 10:00:08 UTC (rev 27033)
@@ -194,14 +194,14 @@
throw new \InvalidArgumentException(sprintf('A service id should be a
string (%s given).', str_replace("\n", '', var_export($id, true))));
}
- if (isset($this->services[$id]))
+ if (method_exists($this, $method = 'get'.self::camelize($id).'Service'))
{
- return $this->services[$id];
+ return $this->$method();
}
- if (method_exists($this, $method = 'get'.self::camelize($id).'Service'))
+ if (isset($this->services[$id]))
{
- return $this->$method();
+ return $this->services[$id];
}
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior)
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php
2010-01-22 09:58:37 UTC (rev 27032)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php
2010-01-22 10:00:08 UTC (rev 27033)
@@ -442,7 +442,7 @@
protected function getServiceCall($id, Reference $reference = null)
{
- if ('service_container' == $id)
+ if ('service_container' === $id)
{
return '$this';
}
@@ -453,6 +453,16 @@
}
else
{
+ if ($this->container->hasAlias($id))
+ {
+ $id = $this->container->getAlias($id);
+ }
+
+ if ($this->container->hasDefinition($id))
+ {
+ return sprintf('$this->get%sService()', Container::camelize($id));
+ }
+
return sprintf('$this->getService(\'%s\')', $id);
}
}
Modified:
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
===================================================================
---
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
2010-01-22 09:58:37 UTC (rev 27032)
+++
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
2010-01-22 10:00:08 UTC (rev 27033)
@@ -70,8 +70,15 @@
);
}
-
$configuration->getDefinition('symfony.templating.loader.chain')->addArgument($loaders);
- $configuration->setAlias('symfony.templating.loader',
'symfony.templating.loader.chain');
+ if (1 === count($loaders))
+ {
+ $configuration->setAlias('symfony.templating.loader', (string)
$loaders[0]);
+ }
+ else
+ {
+
$configuration->getDefinition('symfony.templating.loader.chain')->addArgument($loaders);
+ $configuration->setAlias('symfony.templating.loader',
'symfony.templating.loader.chain');
+ }
// helpers
if (isset($config['helper']))
@@ -85,7 +92,7 @@
}
else
{
- $helpers = array(
+ $helpers = null === $config['helper'] ? array() : array(
new Reference('symfony.templating.helper.javascripts'),
new Reference('symfony.templating.helper.stylesheets'),
);
Modified:
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
2010-01-22 09:58:37 UTC (rev 27032)
+++
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
2010-01-22 10:00:08 UTC (rev 27033)
@@ -38,7 +38,7 @@
{
require_once '%path%/foo.php';
- $instance = call_user_func(array('FooClass', 'getInstance'), 'foo',
$this->getService('foo.baz'), array($this->getParameter('foo') => 'foo is
'.$this->getParameter('foo'), 'bar' => $this->getParameter('foo')), true,
$this);
+ $instance = call_user_func(array('FooClass', 'getInstance'), 'foo',
$this->getFoo_BazService(), array($this->getParameter('foo') => 'foo is
'.$this->getParameter('foo'), 'bar' => $this->getParameter('foo')), true,
$this);
$instance->setBar('bar');
$instance->initialize();
sc_configure($instance);
@@ -58,8 +58,8 @@
{
if (isset($this->shared['bar'])) return $this->shared['bar'];
- $instance = new FooClass('foo', $this->getService('foo.baz'),
$this->getParameter('foo_bar'));
- $this->getService('foo.baz')->configure($instance);
+ $instance = new FooClass('foo', $this->getFoo_BazService(),
$this->getParameter('foo_bar'));
+ $this->getFoo_BazService()->configure($instance);
return $this->shared['bar'] = $instance;
}
@@ -113,7 +113,7 @@
if (isset($this->shared['method_call1'])) return
$this->shared['method_call1'];
$instance = new FooClass();
- $instance->setBar($this->getService('foo'));
+ $instance->setBar($this->getFooService());
$instance->setBar($this->getService('foo',
Container::NULL_ON_INVALID_REFERENCE));
if ($this->hasService('foo'))
{
@@ -134,7 +134,7 @@
*/
protected function getAliasForFooService()
{
- return $this->getService('foo');
+ return $this->getFooService();
}
/**
Modified:
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderTest.php
2010-01-22 09:58:37 UTC (rev 27032)
+++
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderTest.php
2010-01-22 10:00:08 UTC (rev 27033)
@@ -17,7 +17,7 @@
$fixturesPath =
__DIR__.'/../../../../fixtures/Symfony/Components/DependencyInjection/';
-$t = new LimeTest(55);
+$t = new LimeTest(59);
// ->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition()
->getDefinition() ->hasDefinition()
$t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions()
->setDefinition() ->getDefinition() ->hasDefinition()');
@@ -89,7 +89,7 @@
@$builder->getService('baz');
$t->fail('->getService() throws a LogicException if the service has a
circular reference to itself');
}
-catch (LogicException $e)
+catch (\LogicException $e)
{
$t->pass('->getService() throws a LogicException if the service has a
circular reference to itself');
}
@@ -105,14 +105,27 @@
$builder->register('bar', 'stdClass');
$t->is($builder->getServiceIds(), array('foo', 'bar', 'service_container'),
'->getServiceIds() returns all defined service ids');
-// ->setAlias()
-$t->diag('->setAlias()');
+// ->setAlias() ->getAlias() ->hasAlias()
+$t->diag('->setAlias() ->getAlias() ->hasAlias()');
$builder = new Builder();
$builder->register('foo', 'stdClass');
$builder->setAlias('bar', 'foo');
+$t->ok($builder->hasAlias('bar'), '->hasAlias() returns true if the alias
exists');
+$t->ok(!$builder->hasAlias('foobar'), '->hasAlias() returns false if the alias
does not exist');
+$t->is($builder->getAlias('bar'), 'foo', '->getAlias() returns the aliased
service');
$t->ok($builder->hasService('bar'), '->setAlias() defines a new service');
$t->ok($builder->getService('bar') === $builder->getService('foo'),
'->setAlias() creates a service that is an alias to another one');
+try
+{
+ $builder->getAlias('foobar');
+ $t->fail('->getAlias() throws an InvalidArgumentException if the alias does
not exist');
+}
+catch (\InvalidArgumentException $e)
+{
+ $t->pass('->getAlias() throws an InvalidArgumentException if the alias does
not exist');
+}
+
// ->getAliases()
$t->diag('->getAliases()');
$builder = new Builder();
@@ -186,7 +199,7 @@
$builder->getService('foo4');
$t->fail('->createService() throws an InvalidArgumentException if the
configure callable is not a valid callable');
}
-catch (InvalidArgumentException $e)
+catch (\InvalidArgumentException $e)
{
$t->pass('->createService() throws an InvalidArgumentException if the
configure callable is not a valid callable');
}
Modified:
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php
===================================================================
---
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php
2010-01-22 09:58:37 UTC (rev 27032)
+++
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php
2010-01-22 10:00:08 UTC (rev 27033)
@@ -155,7 +155,7 @@
$t->ok($sc->hasService('bar'), '->hasService() returns true if the service has
been defined as a getXXXService() method');
$sc->setService('bar', $bar = new stdClass());
-$t->is(spl_object_hash($sc->getService('bar')), spl_object_hash($bar),
'->getService() prefers to return a service defined with setService() than one
defined with a getXXXService() method');
+$t->isnt(spl_object_hash($sc->getService('bar')), spl_object_hash($bar),
'->getService() prefers to return a service defined with a getXXXService()
method than one defined with setService()');
try
{
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.