2014-08-02 12:11:33 -07:00
< ? php
2018-08-24 11:31:51 +03:00
2016-07-11 16:07:14 -06:00
/**
* @ package Grav . Core
*
2024-01-05 11:43:52 +00:00
* @ copyright Copyright ( c ) 2015 - 2024 Trilby Media , LLC . All rights reserved .
2016-07-11 16:07:14 -06:00
* @ license MIT License ; see LICENSE file for details .
*/
2014-08-18 14:13:51 +03:00
namespace Grav ;
2018-08-24 11:31:51 +03:00
2018-10-16 13:12:26 +03:00
\define ( 'GRAV_REQUEST_TIME' , microtime ( true ));
2020-11-13 16:01:26 -07:00
\define ( 'GRAV_PHP_MIN' , '7.3.6' );
2025-10-17 11:07:17 -06:00
if ( ! \defined ( 'GRAV_ROOT' )) {
\define ( 'GRAV_ROOT' , __DIR__ );
}
2014-08-02 12:11:33 -07:00
2019-07-02 11:23:32 -06:00
if ( PHP_SAPI === 'cli-server' ) {
2021-07-19 22:35:57 -06:00
$symfony_server = stripos ( getenv ( '_' ), 'symfony' ) !== false || stripos ( $_SERVER [ 'SERVER_SOFTWARE' ] ? ? '' , 'symfony' ) !== false || stripos ( $_ENV [ 'SERVER_SOFTWARE' ] ? ? '' , 'symfony' ) !== false ;
2021-07-06 22:40:12 +02:00
2019-07-02 11:23:32 -06:00
if ( ! isset ( $_SERVER [ 'PHP_CLI_ROUTER' ]) && ! $symfony_server ) {
die ( " PHP webserver requires a router to run Grav, please use: <pre>php -S { $_SERVER [ 'SERVER_NAME' ] } : { $_SERVER [ 'SERVER_PORT' ] } system/router.php</pre> " );
}
2016-12-17 07:07:40 -07:00
}
2025-10-16 23:31:05 -06:00
if ( PHP_SAPI !== 'cli' ) {
$requestUri = $_SERVER [ 'REQUEST_URI' ] ? ? '' ;
$scriptName = $_SERVER [ 'SCRIPT_NAME' ] ? ? '' ;
$path = parse_url ( $requestUri , PHP_URL_PATH ) ? ? '/' ;
$path = str_replace ( '\\' , '/' , $path );
$scriptDir = str_replace ( '\\' , '/' , dirname ( $scriptName ));
if ( $scriptDir && $scriptDir !== '/' && $scriptDir !== '.' ) {
if ( strpos ( $path , $scriptDir ) === 0 ) {
$path = substr ( $path , strlen ( $scriptDir ));
$path = $path === '' ? '/' : $path ;
}
}
if ( $path === '/___safe-upgrade-status' ) {
$statusEndpoint = __DIR__ . '/user/plugins/admin/safe-upgrade-status.php' ;
header ( 'Content-Type: application/json; charset=utf-8' );
if ( is_file ( $statusEndpoint )) {
require $statusEndpoint ;
} else {
http_response_code ( 404 );
echo json_encode ([
'status' => 'error' ,
'message' => 'Safe upgrade status endpoint unavailable.' ,
]);
}
exit ;
}
}
2018-10-12 12:06:10 +03:00
// Ensure vendor libraries exist
$autoload = __DIR__ . '/vendor/autoload.php' ;
if ( ! is_file ( $autoload )) {
die ( 'Please run: <i>bin/grav install</i>' );
2015-12-28 18:46:14 +01:00
}
2017-02-16 10:16:30 +01:00
// Register the auto-loader.
2018-08-24 11:31:51 +03:00
$loader = require $autoload ;
2017-02-16 10:16:30 +01:00
2025-10-16 14:19:16 -06:00
if ( ! class_exists ( \Symfony\Component\ErrorHandler\Exception\FlattenException :: class , false ) && class_exists ( \Symfony\Component\HttpKernel\Exception\FlattenException :: class )) {
class_alias ( \Symfony\Component\HttpKernel\Exception\FlattenException :: class , \Symfony\Component\ErrorHandler\Exception\FlattenException :: class );
}
2025-10-16 14:32:05 -06:00
if ( ! class_exists ( \Monolog\Logger :: class , false )) {
class_exists ( \Monolog\Logger :: class );
}
if ( defined ( 'Monolog\Logger::API' ) && \Monolog\Logger :: API < 3 ) {
require_once __DIR__ . '/system/src/Grav/Framework/Compat/Monolog/bootstrap.php' ;
}
2022-02-14 09:38:22 +02:00
// Set timezone to default, falls back to system if php.ini not set
date_default_timezone_set ( @ date_default_timezone_get ());
// Set internal encoding.
@ ini_set ( 'default_charset' , 'UTF-8' );
mb_internal_encoding ( 'UTF-8' );
2025-10-15 10:29:26 -06:00
$recoveryFlag = __DIR__ . '/system/recovery.flag' ;
if ( PHP_SAPI !== 'cli' && is_file ( $recoveryFlag )) {
require __DIR__ . '/system/recovery.php' ;
return 0 ;
}
2018-10-12 12:06:10 +03:00
use Grav\Common\Grav ;
use RocketTheme\Toolbox\Event\Event ;
2015-02-14 10:38:01 -07:00
// Get the Grav instance
2022-02-14 09:38:22 +02:00
$grav = Grav :: instance ( array ( 'loader' => $loader ));
2014-08-18 14:13:51 +03:00
2015-02-14 10:38:01 -07:00
// Process the page
2014-08-06 12:51:49 +03:00
try {
$grav -> process ();
2022-02-15 05:33:21 +01:00
} catch ( \Error | \Exception $e ) {
2017-02-16 10:16:30 +01:00
$grav -> fireEvent ( 'onFatalException' , new Event ( array ( 'exception' => $e )));
2014-08-06 12:51:49 +03:00
throw $e ;
}