<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Response;
// phpinfo();die;
$environment = 'dev'; //'prod'|'dev'
$dev = ($environment === 'dev');
$path = $_SERVER['REQUEST_URI'];
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
$_SERVER['HTTP_X_FORWARDED_PORT'] = '443';
try {
$m = new \Memcached();
$m->addServer('localhost', 11211);
if (!$dev && $page = $m->get($path)) {
echo $page;
die;
}
} catch (Exception $e) {
if ($dev) {
var_dump($e);
die;
}
} finally {
$loader = require_once __DIR__ . '/../app/autoload.php';
// Enable APC for autoloading to improve performance.
// You should change the ApcClassLoader first argument to a unique prefix
// in order to prevent cache key conflicts with other applications
// also using APC.
/*
$apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);
*/
require_once __DIR__ . '/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel($environment, $dev);
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
try {
$response = $kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, true); //$dev
} catch (Exception $e) {
if ($dev) {
if (property_exists($e, 'xdebug_message')) {
$message = $e->xdebug_message;
} else {
$message = '<tr><td><pre>' . var_export($e, true) . '</pre></td></tr>';
}
echo <<<MES
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<title>Error!</title>
</head>
<body>
<table>
{$message}
</table>
</body>
</html>
MES;
} else {
/*
if (method_exists($kernel = $event->getKernel(), 'terminateWithException')) {
$request = $event->getRequest();
$hasRun = &$this->hasTerminatedWithException;
$this->exceptionHandler = function (\Exception $e) use ($kernel, $request, &$hasRun) {
if ($hasRun) {
throw $e;
}
$hasRun = true;
$kernel->terminateWithException($e, $request);
};
}
*/
// $kernel->terminate($request,new Response());
}
}
// $headers = $response->headers;
//$response->sendHeaders();
/*
if ($request->isXmlHttpRequest()) {
$headers = $request->headers;
}
if ($response->isRedirect() || $response->isRedirection()) {
$response->setStatusCode(302);
$headers = $response->headers;
$kernel->terminate($request, $response);
}
else { */
//$host = $this->getContainer()->get('router')->getContext()->getHost();
if(!empty($response)) {
$response->send();
} else {
$response = new Response();
}
$kernel->terminate($request, $response);
// }
}