Permalink
Browse files

Handle disabled opcache

  • Loading branch information...
PeeHaa committed Dec 3, 2014
1 parent 43e57b4 commit 3f093187094d3a16b2486a54b4ad947872cf5958
Showing with 75 additions and 50 deletions.
  1. +12 −3 index.php
  2. +45 −0 public-routes.php
  3. +0 −44 routes.php
  4. +3 −3 template/error.phtml
  5. +5 −0 texts/de.php
  6. +5 −0 texts/en.php
  7. +5 −0 texts/nl.php
@@ -92,17 +92,26 @@
$routeFactory = new RouteFactory();
$router = new Router($request, $routeFactory, $uriScheme);
/**
* Load public routes
*/
require_once __DIR__ . '/public-routes.php';
/**
* Load the routes
*/
if (!extension_loaded('Zend OPcache')) {
if ($router->getIdentifier() !== 'error') {
if (!extension_loaded('Zend OPcache') || opcache_get_status() === false) {
if (!in_array($router->getIdentifier(), ['error', 'mainjs', 'maincss', 'fontawesome-webfont_eot', 'fontawesome-webfont_woff', 'fontawesome-webfont_ttf', 'fontawesome-webfont_svg'], true)) {
header('Location: ' . $urlRenderer->get('error'));
exit;
}
$router->get('error', function() use ($htmlTemplate) {
return $htmlTemplate->render('error.phtml');
return $htmlTemplate->render('error.phtml', [
'login' => true,
'title' => 'Error',
'type' => !extension_loaded('Zend OPcache') ? 'installed' : 'enabled',
]);
});
} else {
require_once __DIR__ . '/routes.php';
@@ -0,0 +1,45 @@
<?php
use OpCacheGUI\Network\Router;
$router->get('mainjs', function() {
header('Content-Type: application/javascript');
readfile(__DIR__ . '/public/js/main.js');
exit;
});
$router->get('maincss', function() use ($uriScheme) {
header('Content-Type: text/css');
$prefix = '?';
if ($uriScheme === Router::URL_REWRITE) {
$prefix = '/';
}
echo str_replace('{urltype}', $prefix, file_get_contents(__DIR__ . '/public/style/main.css'));
exit;
});
$router->get('fontawesome-webfont_eot', function() {
header('Content-Type: application/vnd.ms-fontobject');
readfile(__DIR__ . '/public/style/fonts/fontawesome-webfont.eot');
exit;
});
$router->get('fontawesome-webfont_woff', function() {
header('Content-Type: font/x-woff');
readfile(__DIR__ . '/public/style/fonts/fontawesome-webfont.woff');
exit;
});
$router->get('fontawesome-webfont_ttf', function() {
header('Content-Type: font/ttf');
readfile(__DIR__ . '/public/style/fonts/fontawesome-webfont.ttf');
exit;
});
$router->get('fontawesome-webfont_svg', function() {
header('Content-Type: image/svg+xml');
readfile(__DIR__ . '/public/style/fonts/fontawesome-webfont.svg');
exit;
});
@@ -1,49 +1,5 @@
<?php
use OpCacheGUI\Network\Router;
$router->get('mainjs', function() {
header('Content-Type: application/javascript');
readfile(__DIR__ . '/public/js/main.js');
exit;
});
$router->get('maincss', function() use ($uriScheme) {
header('Content-Type: text/css');
$prefix = '?';
if ($uriScheme === Router::URL_REWRITE) {
$prefix = '/';
}
echo str_replace('{urltype}', $prefix, file_get_contents(__DIR__ . '/public/style/main.css'));
exit;
});
$router->get('fontawesome-webfont_eot', function() {
header('Content-Type: application/vnd.ms-fontobject');
readfile(__DIR__ . '/public/style/fonts/fontawesome-webfont.eot');
exit;
});
$router->get('fontawesome-webfont_woff', function() {
header('Content-Type: font/x-woff');
readfile(__DIR__ . '/public/style/fonts/fontawesome-webfont.woff');
exit;
});
$router->get('fontawesome-webfont_ttf', function() {
header('Content-Type: font/ttf');
readfile(__DIR__ . '/public/style/fonts/fontawesome-webfont.ttf');
exit;
});
$router->get('fontawesome-webfont_svg', function() {
header('Content-Type: image/svg+xml');
readfile(__DIR__ . '/public/style/fonts/fontawesome-webfont.svg');
exit;
});
if ($user->requiresLogin()) {
$router->get('', function() use ($htmlTemplate, $csrfToken) {
return $htmlTemplate->render('login.phtml', [
@@ -1,4 +1,4 @@
<article class="cols-1 error">
<h2><?= $this->translator->translate('error.notenabled.title'); ?></h2>
<p><?= $this->translator->translate('error.notenabled.description'); ?></p>
<article class="cols-1 error" id="login">
<h2><?= $this->translator->translate('error.not.' . $this->type . '.title'); ?></h2>
<p><?= $this->translator->translate('error.not.' . $this->type . '.description'); ?></p>
</article>
@@ -3,6 +3,11 @@
$texts = [
'project.link' => 'Project auf GitHub',
'error.not.installed.title' => 'Not installed',
'error.not.installed.description' => 'It looks like OpCache is not installed.',
'error.not.enabled.title' => 'Not enabled',
'error.not.enabled.description' => 'It looks like OpCache is not enabled.',
'menu.status' => 'Status',
'menu.config' => 'Konfiguration',
'menu.scripts' => 'Dateien im Cache',
@@ -3,6 +3,11 @@
$texts = [
'project.link' => 'Project on GitHub',
'error.not.installed.title' => 'Not installed',
'error.not.installed.description' => 'It looks like OpCache is not installed.',
'error.not.enabled.title' => 'Not enabled',
'error.not.enabled.description' => 'It looks like OpCache is not enabled.',
'menu.status' => 'Status',
'menu.config' => 'Configuration',
'menu.scripts' => 'Cached Scripts',
@@ -3,6 +3,11 @@
$texts = [
'project.link' => 'Project op GitHub',
'error.not.installed.title' => 'Niet geïnstalleerd',
'error.not.installed.description' => 'Het lijkt erop dat OpCache niet geïnstalleerd is.',
'error.not.enabled.title' => 'Niet actief',
'error.not.enabled.description' => 'Het lijkt erop dat OpCache niet actief is.',
'menu.status' => 'Status',
'menu.config' => 'Configuratie',
'menu.scripts' => 'Opgeslagen Scripts',

0 comments on commit 3f09318

Please sign in to comment.