Last active
January 3, 2017 18:35
-
-
Save cherifGsoul/b1f9315bf198d79d195d9b54a0bb03d3 to your computer and use it in GitHub Desktop.
Yii2 container decorated with container-interop
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 | |
use Interop\Container\ContainerInterface; | |
$container = Yii::$container; | |
$container->set(ContainerInterface::class, function($container){ | |
return new \app\components\Container($container); | |
}); |
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 | |
namespace app\components; | |
use Interop\Container\ContainerInterface; | |
class Container implements ContainerInterface | |
{ | |
private $wrappedContainer; | |
function __construct($container) | |
{ | |
$this->wrappedContainer = $container; | |
} | |
public function get($id) | |
{ | |
return $this->wrappedContainer->get($id); | |
} | |
public function has($id) | |
{ | |
return $this->wrappedContainer->has($id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment