Created
January 22, 2015 02:01
-
-
Save devosc/07f73d07184f67c7d221 to your computer and use it in GitHub Desktop.
References
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
<?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()); |
Author
devosc
commented
Jan 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment