PHP Classes

File: web/index.php

Recommend this page to a friend!
  Classes of Nahidul Hasan   Simple PHP Framework Application   web/index.php   Download  
File: web/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple PHP Framework Application
Example MVC application with the Symfony framework
Author: By
Last change:
Date: 1 year ago
Size: 1,103 bytes
 

Contents

Class file image Download
<?php

define
('ROOT_DIR', realpath(__DIR__ . '/../'));

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

use
Symfony\Component\HttpFoundation\Request;
use
Symfony\Component\HttpFoundation\Response;
use
Symfony\Component\Routing;
use
Symfony\Component\HttpKernel;
use
Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use
Symfony\Component\HttpKernel\Controller\ControllerResolver;

function
render_template(Request $request)
{
   
extract($request->attributes->all(), EXTR_SKIP);
   
ob_start();
    include
sprintf(__DIR__.'/../src/pages/%s.php', $_route);

    return new
Response(ob_get_clean());
}


$dotenv = new Dotenv\Dotenv(ROOT_DIR);
$dotenv->load();

$request = Request::createFromGlobals();
$routes = include __DIR__.'/../src/routes.php';

$context = new Routing\RequestContext();
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);

$controllerResolver = new ControllerResolver();
$argumentResolver = new ArgumentResolver();

$framework = new Simplex\Framework($matcher, $controllerResolver, $argumentResolver);
$response = $framework->handle($request);

$response->send();