Skip to content

Instantly share code, notes, and snippets.

@xphere
Created March 24, 2011 08:22
Show Gist options
  • Save xphere/884740 to your computer and use it in GitHub Desktop.
Save xphere/884740 to your computer and use it in GitHub Desktop.
<?php
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
// Interface implementation for testing purposes
class MyParameterBag implements ParameterBagInterface
{
private $container = array();
public function add(array $parameters)
{
echo '-- Bag::add ', print_r($parameters, true), ' --', PHP_EOL;
}
public function all()
{
echo '-- Bag::all --', PHP_EOL;
return $this->container;
}
public function clear()
{
echo '-- Bag::clear --', PHP_EOL;
$this->container = array();
}
public function get($name)
{
echo '-- Bag::get ', print_r(compact('name'), true), ' --', PHP_EOL;
return isset($this->container[$name]) ? $this->container[$name] : null;
}
public function has($name)
{
echo '-- Bag::has ', print_r(compact('name'), true), ' --', PHP_EOL;
return isset($this->container[$name]);
}
public function set($name, $value)
{
echo '-- Bag::set ', print_r(compact('name', 'value'), true), ' --', PHP_EOL;
$this->container[$name] = $value;
}
}
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder,
Symfony\Component\DependencyInjection\Loader\XmlFileLoader,
Symfony\Component\Config\FileLocator;
$bag = new MyParameterBag();
$container = new ContainerBuilder($bag);
$path = explode(PATH_SEPARATOR, get_include_path());
$locator = new FileLocator($path);
$loader = new XmlFileLoader($container, $locator);
$loader->load('dependencies.xml');
/**
* Throws:
* Fatal error: Call to undefined method MyParameterBag::resolveValue()
* in Symfony/Component/DependencyInjection/ContainerBuilder.php on line 725
*/
$container->get('entityManager');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment