i create my own container, i made"bind" method that get "string $alias" and "Closure $closure". the method bind the alias to the object on the $container array , like that:
public function bind(string $alias,$closure)
{
$this->container[$alias] = $closure();
}
The second method is "call", that simply call to some instance from the $container. Of course first the method check if the given alias exists, and if doesnt throw an exception
public function call(string $alias)
{
if(array_key_exists($alias,$this->container))
return $this->container[$alias];
throw new \Exception();
}
is that good ? what more i need to add ? cause i saw on laravel for example that the container is full of method and props, and i dont know why. its just bind and call, isnt ?
Aucun commentaire:
Enregistrer un commentaire