corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-14 95ec2424f5adeea827cd69db83daacf9a6e866e1
fix errore caricamento classe (parte 89)
2 files modified
12 ■■■■■ changed files
index.php 3 ●●●●● patch | view | raw | blame | history
src/Framework/Container.php 9 ●●●●● patch | view | raw | blame | history
index.php
@@ -20,6 +20,9 @@
$container = new Framework\Container;
$database = new App\Database("localhost", "product_db", "product_db_user", "secret");
$container->set(App\Database::class, $database);
$dispatcher = new Framework\Dispatcher($router, $container);
$dispatcher->handle($path);
src/Framework/Container.php
@@ -4,7 +4,16 @@
use ReflectionClass;
class Container {
    private array $registry = [];
    public function set(string $name, $value) {
        $this->registry[$name] = $value;
    }
    public function get(string $class_name):object {
        if(array_key_exists($class_name, $this->registry)) {
            return $this->registry[$class_name];
        }
        $reflector = new ReflectionClass($class_name);
        $contructor = $reflector->getConstructor();