ServiceContainer.php in X Autoload 7.5
File
src/DIC/ServiceContainer.php
View source
<?php
namespace Drupal\xautoload\DIC;
class ServiceContainer implements ServiceContainerInterface {
protected $factory;
protected $services = array();
function get($key) {
return isset($this->services[$key]) ? $this->services[$key] : ($this->services[$key] = $this->factory
->{$key}($this) ?: FALSE);
}
function reset($key) {
$this->services[$key] = NULL;
}
function set($key, $service) {
$this->services[$key] = $service;
}
function __get($key) {
if (isset($this->services[$key])) {
return $this->services[$key];
}
if (!method_exists($this->factory, $key)) {
throw new \Exception("Unsupported key '{$key}' for service factory.");
}
return $this->services[$key] = $this->factory
->{$key}($this) ?: FALSE;
}
function __construct($factory) {
$this->factory = $factory;
}
}