Pannous

Pannous Git Source Tree

Root/public/index.php

1<?php
2/**
3 * Fuel is a fast, lightweight, community driven PHP5 framework.
4 *
5 * @package Fuel
6 * @version 1.8
7 * @author Fuel Development Team
8 * @license MIT License
9 * @copyright 2010 - 2016 Fuel Development Team
10 * @link http://fuelphp.com
11 */
12
13/**
14 * Set error reporting and display errors settings. You will want to change these when in production.
15 */
16error_reporting(-1);
17ini_set('display_errors', 1);
18
19/**
20 * Website document root
21 */
22define('DOCROOT', __DIR__.DIRECTORY_SEPARATOR);
23
24/**
25 * Path to the application directory.
26 */
27define('APPPATH', realpath(__DIR__.'/../fuel/app/').DIRECTORY_SEPARATOR);
28
29/**
30 * Path to the default packages directory.
31 */
32define('PKGPATH', realpath(__DIR__.'/../fuel/packages/').DIRECTORY_SEPARATOR);
33
34/**
35 * The path to the framework core.
36 */
37define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR);
38
39// Get the start time and memory for use later
40defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
41defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());
42
43// Load in the Fuel autoloader
44if ( ! file_exists(COREPATH.'classes'.DIRECTORY_SEPARATOR.'autoloader.php'))
45{
46die('No composer autoloader found. Please run composer to install the FuelPHP framework dependencies first!');
47}
48
49// Activate the framework class autoloader
50require COREPATH.'classes'.DIRECTORY_SEPARATOR.'autoloader.php';
51class_alias('Fuel\\Core\\Autoloader', 'Autoloader');
52
53// Exception route processing closure
54$routerequest = function($request = null, $e = false)
55{
56Request::reset_request(true);
57
58$route = array_key_exists($request, Router::$routes) ? Router::$routes[$request]->translation : Config::get('routes.'.$request);
59
60if ($route instanceof Closure)
61{
62$response = $route();
63
64if( ! $response instanceof Response)
65{
66$response = Response::forge($response);
67}
68}
69elseif ($e === false)
70{
71$response = Request::forge()->execute()->response();
72}
73elseif ($route)
74{
75$response = Request::forge($route, false)->execute(array($e))->response();
76}
77elseif ($request)
78{
79$response = Request::forge($request)->execute(array($e))->response();
80}
81else
82{
83throw $e;
84}
85
86return $response;
87};
88
89// Generate the request, execute it and send the output.
90try
91{
92// Boot the app...
93require APPPATH.'bootstrap.php';
94
95// ... and execute the main request
96$response = $routerequest();
97}
98catch (HttpBadRequestException $e)
99{
100$response = $routerequest('_400_', $e);
101}
102catch (HttpNoAccessException $e)
103{
104$response = $routerequest('_403_', $e);
105}
106catch (HttpNotFoundException $e)
107{
108$response = $routerequest('_404_', $e);
109}
110catch (HttpServerErrorException $e)
111{
112$response = $routerequest('_500_', $e);
113}
114
115// This will add the execution time and memory usage to the output.
116// Comment this out if you don't use it.
117$response->body((string) $response);
118if (strpos($response->body(), '{exec_time}') !== false or strpos($response->body(), '{mem_usage}') !== false)
119{
120$bm = Profiler::app_total();
121$response->body(
122str_replace(
123array('{exec_time}', '{mem_usage}'),
124array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
125$response->body()
126)
127);
128}
129
130// Send the output to the client
131$response->send(true);

Archive Download this file

Branches