Created
March 24, 2011 08:22
-
-
Save xphere/884740 to your computer and use it in GitHub Desktop.
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 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; | |
} | |
} |
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 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