use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
-use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
{
$this->parameters = $this->getDefaultParameters();
- $this->services =
- $this->scopedServices =
- $this->scopeStacks = array();
- $this->scopes = array();
- $this->scopeChildren = array();
+ $this->services = array();
$this->methodMap = array(
'bar' => 'getBarService',
'baz' => 'getBazService',
'configured_service' => 'getConfiguredServiceService',
+ 'configured_service_simple' => 'getConfiguredServiceSimpleService',
'decorator_service' => 'getDecoratorServiceService',
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
'deprecated_service' => 'getDeprecatedServiceService',
'factory_service' => 'getFactoryServiceService',
+ 'factory_service_simple' => 'getFactoryServiceSimpleService',
'foo' => 'getFooService',
'foo.baz' => 'getFoo_BazService',
'foo_bar' => 'getFooBarService',
}
/**
- * Gets the 'bar' service.
+ * Gets the public 'bar' shared service.
*
- * This service is shared.
- * This method always returns the same instance of the service.
- *
- * @return \Bar\FooClass A Bar\FooClass instance
+ * @return \Bar\FooClass
*/
protected function getBarService()
{
}
/**
- * Gets the 'baz' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'baz' shared service.
*
- * @return \Baz A Baz instance
+ * @return \Baz
*/
protected function getBazService()
{
}
/**
- * Gets the 'configured_service' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'configured_service' shared service.
*
- * @return \stdClass A stdClass instance
+ * @return \stdClass
*/
protected function getConfiguredServiceService()
{
}
/**
- * Gets the 'decorator_service' service.
+ * Gets the public 'configured_service_simple' shared service.
*
- * This service is shared.
- * This method always returns the same instance of the service.
+ * @return \stdClass
+ */
+ protected function getConfiguredServiceSimpleService()
+ {
+ $this->services['configured_service_simple'] = $instance = new \stdClass();
+
+ (new \ConfClass('bar'))->configureStdClass($instance);
+
+ return $instance;
+ }
+
+ /**
+ * Gets the public 'decorator_service' shared service.
*
- * @return \stdClass A stdClass instance
+ * @return \stdClass
*/
protected function getDecoratorServiceService()
{
}
/**
- * Gets the 'decorator_service_with_name' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'decorator_service_with_name' shared service.
*
- * @return \stdClass A stdClass instance
+ * @return \stdClass
*/
protected function getDecoratorServiceWithNameService()
{
}
/**
- * Gets the 'deprecated_service' service.
+ * Gets the public 'deprecated_service' shared service.
*
- * This service is shared.
- * This method always returns the same instance of the service.
- *
- * @return \stdClass A stdClass instance
+ * @return \stdClass
*
* @deprecated The "deprecated_service" service is deprecated. You should stop using it, as it will soon be removed.
*/
}
/**
- * Gets the 'factory_service' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'factory_service' shared service.
*
- * @return \Bar A Bar instance
+ * @return \Bar
*/
protected function getFactoryServiceService()
{
}
/**
- * Gets the 'foo' service.
+ * Gets the public 'factory_service_simple' shared service.
*
- * This service is shared.
- * This method always returns the same instance of the service.
+ * @return \Bar
+ */
+ protected function getFactoryServiceSimpleService()
+ {
+ return $this->services['factory_service_simple'] = (new \SimpleFactoryClass('foo'))->getInstance();
+ }
+
+ /**
+ * Gets the public 'foo' shared service.
*
- * @return \Bar\FooClass A Bar\FooClass instance
+ * @return \Bar\FooClass
*/
protected function getFooService()
{
}
/**
- * Gets the 'foo.baz' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'foo.baz' shared service.
*
- * @return \BazClass A BazClass instance
+ * @return \BazClass
*/
protected function getFoo_BazService()
{
}
/**
- * Gets the 'foo_bar' service.
+ * Gets the public 'foo_bar' service.
*
- * @return \Bar\FooClass A Bar\FooClass instance
+ * @return \Bar\FooClass
*/
protected function getFooBarService()
{
}
/**
- * Gets the 'foo_with_inline' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'foo_with_inline' shared service.
*
- * @return \Foo A Foo instance
+ * @return \Foo
*/
protected function getFooWithInlineService()
{
}
/**
- * Gets the 'method_call1' service.
+ * Gets the public 'method_call1' shared service.
*
- * This service is shared.
- * This method always returns the same instance of the service.
- *
- * @return \Bar\FooClass A Bar\FooClass instance
+ * @return \Bar\FooClass
*/
protected function getMethodCall1Service()
{
$instance->setBar($this->get('foo'));
$instance->setBar(NULL);
- $instance->setBar(($this->get("foo")->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
+ $instance->setBar(($this->get('foo')->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
return $instance;
}
/**
- * Gets the 'new_factory_service' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'new_factory_service' shared service.
*
- * @return \FooBarBaz A FooBarBaz instance
+ * @return \FooBarBaz
*/
protected function getNewFactoryServiceService()
{
}
/**
- * Gets the 'request' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'request' shared service.
*
* @throws RuntimeException always since this service is expected to be injected dynamically
*/
}
/**
- * Gets the 'service_from_static_method' service.
- *
- * This service is shared.
- * This method always returns the same instance of the service.
+ * Gets the public 'service_from_static_method' shared service.
*
- * @return \Bar\FooClass A Bar\FooClass instance
+ * @return \Bar\FooClass
*/
protected function getServiceFromStaticMethodService()
{
{
$name = strtolower($name);
- if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
+ if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters) || isset($this->loadedDynamicParameters[$name]))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
+ if (isset($this->loadedDynamicParameters[$name])) {
+ return $this->loadedDynamicParameters[$name] ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name);
+ }
return $this->parameters[$name];
}
{
$name = strtolower($name);
- return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters);
+ return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters) || isset($this->loadedDynamicParameters[$name]);
}
/**
public function getParameterBag()
{
if (null === $this->parameterBag) {
- $this->parameterBag = new FrozenParameterBag($this->parameters);
+ $parameters = $this->parameters;
+ foreach ($this->loadedDynamicParameters as $name => $loaded) {
+ $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name);
+ }
+ $this->parameterBag = new FrozenParameterBag($parameters);
}
return $this->parameterBag;
}
+ private $loadedDynamicParameters = array();
+ private $dynamicParameters = array();
+
+ /**
+ * Computes a dynamic parameter.
+ *
+ * @param string The name of the dynamic parameter to load
+ *
+ * @return mixed The value of the dynamic parameter
+ *
+ * @throws InvalidArgumentException When the dynamic parameter does not exist
+ */
+ private function getDynamicParameter($name)
+ {
+ throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name));
+ }
+
/**
* Gets the default parameters.
*