Streamline view rendering
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
namespace Ardent\Undercurrent\Container;
|
||||
|
||||
use Ardent\Undercurrent\Http\RouteConfig;
|
||||
use Ardent\Undercurrent\Logger\LogContainer;
|
||||
use Ardent\Undercurrent\Logger\LoggerInterface;
|
||||
use Exception;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
@ -15,12 +17,20 @@ class GenericContainer implements ContainerInterface
|
||||
|
||||
private array $aliases = [];
|
||||
|
||||
public function add(string $className, ?callable $definition = null, bool $singleton = true): self
|
||||
public function add(
|
||||
string $className,
|
||||
?callable $definition = null,
|
||||
bool $singleton = true
|
||||
): self
|
||||
{
|
||||
if (!$definition) {
|
||||
$definition = fn() => $this->autowire($className);
|
||||
}
|
||||
|
||||
if (isset($this->definitions[$className])) {
|
||||
throw new Exception(sprintf('Class %s already defined', $className));
|
||||
}
|
||||
|
||||
$this->definitions[$className] = [
|
||||
'definition' => $definition,
|
||||
'singleton' => $singleton,
|
||||
@ -55,6 +65,10 @@ class GenericContainer implements ContainerInterface
|
||||
return $this->instances[$className];
|
||||
}
|
||||
$instance = $definition($this);
|
||||
if ($className !== LogContainer::class) {
|
||||
$logger = $this->get(LoggerInterface::class);
|
||||
$logger->add(sprintf('Created singleton instance of %s', $className));
|
||||
}
|
||||
$this->instances[$className] = $instance;
|
||||
} else {
|
||||
$instance = $definition($this);
|
||||
|
Reference in New Issue
Block a user