Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created January 18, 2011 13:53
Show Gist options
  • Save kriswallsmith/784453 to your computer and use it in GitHub Desktop.
Save kriswallsmith/784453 to your computer and use it in GitHub Desktop.
<?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