#3 | Phalcon\Mvc\Application->handle
/home/bh61542/amberedge.ru/app/Common.php (216) <?php
declare(strict_types=1);
namespace AmberEdge;
use Phalcon\Config\Config;
use Phalcon\Mvc\Application as MvcApp;
use Phalcon\DI\FactoryDefault;
use Phalcon\Http\Request;
use Phalcon\Session\Manager;
use Phalcon\Flash\Session as FlashSession;
use Phalcon\Mvc\Router;
use Phalcon\Session\Adapter\Stream;
/**
* General class of modules
*
* Class Application
* @package AmberEdge
* @see https://docs.phalcon.io/5.0/en/mvc
*/
class Application extends MvcApp
{
protected function registerServices()
{
/**
* Creation of DI
* @see https://docs.phalcon.io/5.0/en/api/phalcon_di
*/
$di = new FactoryDefault();
/**
* Registering the Configuration Service
* @see https://docs.phalcon.io/5.0/en/config
*/
$di->set('cfg', function()
{
return require_once APP_PATH . 'Config.php';
});
/**
* Registering the Query Service
* @see https://docs.phalcon.io/5.0/en/request
*/
$di->set('request', function()
{
return new Request();
});
/**
* Registration of information messages service
* @see https://docs.phalcon.io/5.0/en/flash
*/
$di->set('flash', function()
{
return new FlashSession();
});
/**
* Registering the Session Service
* @see https://docs.phalcon.io/5.0/en/session
*/
/*
$di->set('session', function() use ($di)
{
$session = new Manager();
$files = new Stream(array
(
'savePath' => $di['cfg']->app->tmp_path
));
$session->setAdapter($files)->start();
return $session;
});
*/
/**
* Registering the Route Service
* @see https://docs.phalcon.io/5.0/en/routing
*/
$di->set('router', function() use ($di)
{
// Creating a router without support for standard routing
$router = new Router();
// Setting default options
$router->setDefaultModule('frontend');
$router->setDefaultController('index');
$router->setDefaultAction('index');
// Getting the routes
$routes = $di['cfg']->routes;
if ($di['cfg']->app->frontend->maintenance_mode)
{
$routes = new Config
(
array
(
'/' => array
(
'params' => array
(
'module' => 'frontend',
'controller' => 'index',
'action' => 'redirectIndex',
),
),
'/{language:(%languages%)}/' => array
(
'params' => array
(
'module' => 'frontend',
'controller' => 'errors',
'action' => 'e503',
'language' => 1
),
),
'/{language:(%languages%)}' => array
(
'params' => array
(
'module' => 'frontend',
'controller' => 'index',
'action' => 'redirectIndex',
'language' => 1
),
)
)
);
}
// Defining routing rules
if (count($routes))
{
$languages = $di['cfg']->app->frontend->languages->toArray();
foreach ($routes as $route => $items)
{
$lang = str_replace('%languages%', join('|', $languages), $route);
$router->add($lang, $items->params->toArray());
}
}
$params = array
(
'controller' => 'errors',
'action' => 'e404',
);
if ($di['cfg']->app->frontend->maintenance_mode)
{
$params['action'] = 'e503';
}
// Specifying options for paths not found
$router->notFound($params);
return $router;
});
// URI Presentation Mode Check
$base_ui = $di['cfg']->app->base_uri;
$protocol = $di['cfg']->app->protocol;
$uri = rtrim($base_ui, '/') . $di['request']->getURI();
if ($di['cfg']->app->www_uri_mode)
{
if (strpos($base_ui, 'www.') === false)
{
$this->response->redirect(str_replace($protocol . '://', $protocol . '://www.', $uri), false, 301);
}
}
else
{
if (strpos($base_ui, 'www.') !== false)
{
$this->response->redirect(str_replace('www.', '', $uri), false, 301);
}
}
$this->setDI($di);
}
// Application launch
public function run()
{
// Registering common services for all modules
$this->registerServices();
// Registering application modules
$this->registerModules([
'frontend' => [
'className' => 'AmberEdge\Frontend\Module',
'path' => join('', [
$this->di['cfg']->app->app_path,
join(DIRECTORY_SEPARATOR, [
'frontend',
'Module.php'
])
])
],
'backend' => [
'className' => 'AmberEdge\Backend\Module',
'path' => join('', [
$this->di['cfg']->app->app_path,
join(DIRECTORY_SEPARATOR, [
'backend',
'Module.php'
])
])
],
]);
$requestUri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
$response = $this->handle($requestUri);
$response->send();
}
}
|
#4 | AmberEdge\Application->run
/home/bh61542/amberedge.ru/public/index.php (136) <?php
declare(strict_types=1);
namespace AmberEdge;
use Phalcon\Support\Debug;
use Phalcon\Support\Debug\Exception;
/**
* Bootstrap for App
* @copyright 2023+ AmberEdge
* @link http://amberedge.ru
* @author Pavel Vecherin (vpa2k) <vecherins@gmail.com>
*/
// System requirements
define('USED_PHP_VERSION', '8.1.21');
define('USED_PHALCON_VERSION', '5.2.1');
// Main settings
define('LOCAL_SERVER', isset($_ENV['COMPOSE_PROJECT_NAME']));
define('DEBUG_MODE', 0);
function stop($value)
{
if (DEBUG_MODE)
{
$template = '<p style="color: red">%s</p>';
echo sprintf($template, $value);
}
die;
}
// Check PHP version
$php_version = phpversion();
if (!version_compare($php_version, USED_PHP_VERSION, '>='))
{
stop(join(' ', [
sprintf('The current version (%s) of PHP is not supported.', $php_version),
sprintf('Please use PHP version %s or higher.', USED_PHP_VERSION)
]));
}
// Verifying the installation of the Phalcon extension
if (!extension_loaded('phalcon'))
{
stop(join(' ', [
'The Phalcon extension is not available.',
'Please enable the Phalcon extension on your web server to continue.',
]));
}
// Checking the version of the Phalcon extension
$phalcon_version = phpversion('phalcon');
if (!version_compare($phalcon_version, USED_PHALCON_VERSION, '>='))
{
stop(join(' ', [
sprintf('The current version (%s) of Phalcon extension is not supported.', $phalcon_version),
sprintf('Please use the Phalcon extension version %s or higher.', USED_PHALCON_VERSION)
]));
}
// Defining the timezone
define('TZ', isset($_ENV['TZ']) ? $_ENV['TZ'] : 'Europe/Moscow');
// Defining the default timezone
date_default_timezone_set(TZ);
// Defining the protocol to use
define('PROTOCOL', isset($_SERVER['HTTPS']) ? 'https' : 'http');
// Domain name definition
define('DN', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost');
// Defining the root URL
define('ROOT_HTTP', PROTOCOL . '://' . DN . '/');
// Defining the base path
define('BASE_PATH', realpath('..') . DIRECTORY_SEPARATOR);
// Defining the application directory
define('APP_DIR', 'app' . DIRECTORY_SEPARATOR);
// Defining the application path
define('APP_PATH', BASE_PATH . APP_DIR);
// Defining the config directory
define('CFG_DIR', 'config' . DIRECTORY_SEPARATOR);
// Defining the config path
define('CFG_PATH', APP_PATH . CFG_DIR);
// Defining the application temporary directory
define('TMP_DIR', 'tmp' . DIRECTORY_SEPARATOR);
// Defining the application path to temporary directory
define('TMP_PATH', BASE_PATH . TMP_DIR);
if (!is_dir(TMP_PATH))
{
if (!mkdir(TMP_PATH, 0700))
{
stop(sprintf('Please create a directory "%s".', rtrim(TMP_DIR, '/')));
}
}
// Configuration option
if (DEBUG_MODE)
{
error_reporting(-1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
}
else
{
error_reporting(0);
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
}
try
{
/**
* Debugging Application
* @see https://docs.phalcon.io/5.0/en/support-debug
*/
$debug = new Debug();
$debug->listen();
// Loading the general application class
require_once APP_PATH . 'Common.php';
// Creating and running the application
$app = new Application();
$app->run();
}
catch (Exception $e)
{
stop(join('<br>', array
(
'--[ Exception ]--',
'Message: ' . $e->getMessage(),
'Code: ' . $e->getCode(),
'Line: ' . $e->getLine(),
'File: ' . $e->getFile(),
'Trace: ' . $e->getTraceAsString(),
)));
}
|