PHP Classes

File: app/bootstrap.php

Recommend this page to a friend!
  Classes of Pierre-Henry Soria   pH7 PHP Web App Boilerplate   app/bootstrap.php   Download  
File: app/bootstrap.php
Role: Example script
Content type: text/plain
Description: Example script
Class: pH7 PHP Web App Boilerplate
Start a Web app development using boilerplate code
Author: By
Last change:
Date: 1 year ago
Size: 1,420 bytes
 

Contents

Class file image Download
<?php

declare(strict_types = 1);

namespace
PH7\Boilerplate;

use
Symfony\Component\Debug\ErrorHandler;
use
Symfony\Component\Debug\ExceptionHandler;
use
Symfony\Component\HttpFoundation\Request;
use
Silex\Provider\DoctrineServiceProvider;
use
Silex\Provider\TwigServiceProvider;
use
Silex\Provider\AssetServiceProvider;
use
Twig_Environment;
use
Twig_Extensions_Extension_Text;
use
Exception;

ErrorHandler::register();
ExceptionHandler::register();

$app->register(new DoctrineServiceProvider());

$app->register(new TwigServiceProvider(), array(
   
'twig.path' => dirname(__DIR__) . '/views',
   
'twig.options' => array(
       
'cache' => dirname(__DIR__) . '/var/cache/twig',
    )
));

$app['twig'] = $app->extend('twig', function(Twig_Environment $twig, $app) {
   
$twig->addExtension(new Twig_Extensions_Extension_Text());

    return
$twig;
});

$app->register(new AssetServiceProvider(), array(
   
'assets.version' => 'v1'
));

// Register Error Handler
$app->error(function (Exception $except, Request $request, int $code) use ($app) {
    switch (
$code) {
        case
403:
           
$message = 'Access denied!';
            break;
        case
404:
           
$message = 'The requested resource could not be found.';
            break;
        default:
           
$message = 'Oops! Something went wrong...';
    }
    return
$app['twig']->render('error.twig', array('message' => $message));
});