Skip to content

Instantly share code, notes, and snippets.

@Trainmaster
Created June 5, 2013 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trainmaster/5713025 to your computer and use it in GitHub Desktop.
Save Trainmaster/5713025 to your computer and use it in GitHub Desktop.
<?php
$container->addDefinition('AnotherService', new Definition('Application\Service\AnotherService'))
->setter('setFoo', 'Foo');
$container->addDefinition('ExampleService', new Definition('Application\Service\ExampleService'))
->constructor(array('@AnotherService'));
$container->addDefinition('Session', new Definition('lib\Session\Session'));
$container->addDefinition('SessionAwareInterface', new Definition('lib\Session\SessionAwareInterface'))
->setter('setSession', '@Session');
$container->addDefinition(null, new Definition('Application\ExampleController'))
->constructor(array('@ExampleService'));
class BaseController implements SessionAwareInterface
{
public function setSession(Session $session)
{
$this->session = $session;
}
}
class ExampleController extends BaseController
{
public function __construct($exampleService)
{
$this->exampleService = $exampleService;
print $this->exampleService->getAnotherService->getFoo();
}
public function index()
{
var_dump($this->session);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment