Skip to content

Instantly share code, notes, and snippets.

@seiffert
Created July 15, 2013 14:26
Show Gist options
  • Save seiffert/6000371 to your computer and use it in GitHub Desktop.
Save seiffert/6000371 to your computer and use it in GitHub Desktop.
<?php
namespace Sensio\Bridge\Phpmig;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The ContainerAdapter allows the Symfony DIC to be used with phpmig. Phpmig is the tool that's used for executing
* migrations on the application and expects a service container that implements \ArrayAccess. This is achieved by
* wrapping Symfony's DIC with an adapter that implements \ArrayAccess and proxies to the DIC.
*
* @package Sensio\Bridge\Phpmig
*/
class ContainerAdapter implements \ArrayAccess
{
/** @var ContainerInterface */
private $dic;
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->dic = $container;
}
/**
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset)
{
return $this->dic->has($offset);
}
/**
* @param mixed $offset
* @return mixed|object
*/
public function offsetGet($offset)
{
return $this->dic->get($offset);
}
/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
{
$this->dic->set($offset, $value);
}
/**
* @param mixed $offset
* @throws \RuntimeException
*/
public function offsetUnset($offset)
{
throw new \RuntimeException('Symfony DIC does not support the removal of services.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment