Skip to content

Instantly share code, notes, and snippets.

@cherifGsoul
Last active January 3, 2017 18:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherifGsoul/b1f9315bf198d79d195d9b54a0bb03d3 to your computer and use it in GitHub Desktop.
Save cherifGsoul/b1f9315bf198d79d195d9b54a0bb03d3 to your computer and use it in GitHub Desktop.
Yii2 container decorated with container-interop
<?php
use Interop\Container\ContainerInterface;
$container = Yii::$container;
$container->set(ContainerInterface::class, function($container){
return new \app\components\Container($container);
});
<?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