Просмотр поста

.
reaper

А можно ещё вот так сделать:

require __DIR__ . '/vendor/autoload.php';

use Symfony\Component\HttpFoundation\Response;

class Model
{
    public function getData()
    {
        return "MVC example\n";
    }
}

class View
{
    public function render($data)
    {
        return new Response($data);
    }
}

class Controller
{
    private $model;
    private $view;

    public function __construct(Model $model, View $view)
    {
        $this->model = $model;
        $this->view = $view;
    }

    public function __invoke()
    {
        return $this->view->render($this->model->getData());
    }
}

$config = [
    'routing' => [
        'routes' => [
            'home' => [
                'method' => 'GET',
                'path' => '/',
                'handler' => Controller::class,
            ],
        ],
    ],
    'container' => [
        'use_autowiring' => true,
        /*
        'definitions' => [
            'model' => \DI\object(Model::class),
            'view' => \DI\object(View::class),
            'controller' => \DI\object(Controller::class)
                ->constructor(
                    \DI\link('model'),
                    \DI\link('view')
                ),
        ],
        */
    ],
];

(new Vermillion\Http\Application($config))->run();