Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DependencyInjection] Tweaked factories
- Loading branch information
Showing
17 changed files
with
203 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container19.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
require_once __DIR__.'/../includes/classes.php'; | ||
|
||
$container = new ContainerBuilder(); | ||
|
||
$container | ||
->register('service_from_anonymous_factory', 'Bar\FooClass') | ||
->setFactory(array(new Definition('Bar\FooClass'), 'getInstance')) | ||
; | ||
|
||
$anonymousServiceWithFactory = new Definition('Bar\FooClass'); | ||
$anonymousServiceWithFactory->setFactory('Bar\FooClass::getInstance'); | ||
$container | ||
->register('service_with_method_call_and_factory', 'Bar\FooClass') | ||
->addMethodCall('setBar', array($anonymousServiceWithFactory)) | ||
; | ||
|
||
return $container; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
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; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; | ||
|
||
/** | ||
* ProjectServiceContainer | ||
* | ||
* This class has been auto-generated | ||
* by the Symfony Dependency Injection Component. | ||
*/ | ||
class ProjectServiceContainer extends Container | ||
{ | ||
private static $parameters = array( | ||
|
||
); | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(new ParameterBag(self::$parameters)); | ||
$this->methodMap = array( | ||
'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService', | ||
'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService', | ||
); | ||
} | ||
|
||
/** | ||
* Gets the 'service_from_anonymous_factory' service. | ||
* | ||
* This service is shared. | ||
* This method always returns the same instance of the service. | ||
* | ||
* @return \Bar\FooClass A Bar\FooClass instance. | ||
*/ | ||
protected function getServiceFromAnonymousFactoryService() | ||
{ | ||
return $this->services['service_from_anonymous_factory'] = call_user_func(array(new \Bar\FooClass(), 'getInstance')); | ||
} | ||
|
||
/** | ||
* Gets the 'service_with_method_call_and_factory' service. | ||
* | ||
* This service is shared. | ||
* This method always returns the same instance of the service. | ||
* | ||
* @return \Bar\FooClass A Bar\FooClass instance. | ||
*/ | ||
protected function getServiceWithMethodCallAndFactoryService() | ||
{ | ||
$this->services['service_with_method_call_and_factory'] = $instance = new \Bar\FooClass(); | ||
|
||
$instance->setBar(\Bar\FooClass::getInstance()); | ||
|
||
return $instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services14.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
services: | ||
factory: { class: FooBarClass, factory: baz:getClass} | ||
factory_with_static_call: { class: FooBarClass, factory: FooBacFactory::createFooBar} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters