Created
January 18, 2011 13:53
-
-
Save kriswallsmith/784453 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Symfony\Component\DependencyInjection\Factory\StaticFactory; | |
use Symfony\Component\DependencyInjection\Scope\ContainerScope; | |
use Symfony\Component\DependencyInjection\Scope\NestingContainerScope; | |
use Symfony\Component\DependencyInjection\Scope\Scope; | |
use Symfony\Component\DependencyInjection\ScopedContainer; | |
class Connection | |
{ | |
public $logger; | |
} | |
class Logger | |
{ | |
} | |
class Response | |
{ | |
} | |
class Request | |
{ | |
} | |
class ContainerFactory extends StaticFactory | |
{ | |
protected function createConnectionService(ContainerInterface $container) | |
{ | |
$conn = new Connection(); | |
$conn->logger = $container->get('logger'); | |
return $conn; | |
} | |
protected function createLoggerService(ContainerInterface $container) | |
{ | |
return new Logger(); | |
} | |
} | |
class PrototypeFactory extends StaticFactory | |
{ | |
protected function createResponseService(ContainerInterface $container) | |
{ | |
return new Response(); | |
} | |
} | |
class RequestFactory extends StaticFactory | |
{ | |
protected function createRequestService(ContainerInterface $container) | |
{ | |
return new Request(); | |
} | |
} | |
class Container extends ScopedContainer | |
{ | |
public function __construct() | |
{ | |
$this->registerScope('container', new ContainerScope(new ContainerFactory())); | |
$this->registerScope('prototype', new Scope(new PrototypeFactory())); | |
$this->registerScope('request', new NestingContainerScope(new RequestFactory()), 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment