How to apply SOLID to this simple PHP class? This is a simple implementation of a dependency injection container.
<?php namespace Classes;
class Container
{
/**
* An array that contains container's elements
* @var array
*/
private $container = [];
/**
* Add a new element in the container
* @param string $name
* @param callable $callable
* @throws \Exception
*/
public function bind($name, callable $callable)
{
if (is_string($name)) {
$this->container[$name] = $callable;
} else {
throw new \Exception('Containe: You have to provide a name in the bind method');
}
}
/**
* Resolve an element from container.
* @param string $name
* @return object
*/
public function resolve($name)
{
if (isset($this->container[$name])) {
return call_user_func($this->container[$name]);
} else {
throw new \Exception('Container: The '. $name . ' was not found in the container');
}
}
}