Skip to content

Instantly share code, notes, and snippets.

@devosc
Created January 22, 2015 02:01
Show Gist options
  • Save devosc/07f73d07184f67c7d221 to your computer and use it in GitHub Desktop.
Save devosc/07f73d07184f67c7d221 to your computer and use it in GitHub Desktop.
References
<?php
class MyService {
protected $request;
function __construct($request)
{
$this->request = $request;
}
function request()
{
return $this->request;
}
}
class Request {
function withAttribute($name, $value)
{
return clone $this;
}
}
class Container
{
protected $container = [
'request' => null
];
function setRequest($request)
{
$this->container['request'] = $request;
}
function request()
{
return $this->container['request'];
}
function myService()
{
return new MyService($this->container['request']);
}
}
$request = new Request;
$container = new Container;
$container->setRequest($request);
$service = $container->myService();
var_dump($container->request() , $service->request());
$request = $request->withAttribute('test', '123');
$container->setRequest($request);
var_dump($container->request() , $service->request());
@devosc
Copy link
Author

devosc commented Jan 22, 2015

object(Request)[1]

object(Request)[1]

object(Request)[4]

object(Request)[1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment