Bicycle/System/Classes/Core.php
Egor Isaev b516ca07dc Initial commit: Bicycle PHP MVC micro-framework
Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 10:04:19 +03:00

104 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @package Bicycle
* @author Egor Isaev
* @description Core.php
* @copyright (c) 03/06/2026
*/
namespace System\Classes;
use ErrorException;
class Core
{
// Среда работы системы
public const PRODUCTION = 10;
public const STAGING = 20;
public const TESTING = 30;
public const DEVELOPMENT = 40;
/**
* @var int Текущая среда системы по умолчанию
*/
public static int $environment = self::DEVELOPMENT;
/**
* @var string Кодировка на ввод и вывод
*/
public static string $charset = 'utf-8';
/**
* @var bool Начальное значение был ли создан [Core::init]?
*/
protected static bool $_init = false;
/**
* @var array
*/
protected static array $_paths = [];
public static function init(): void
{
if (self::$_init) {
return;
}
self::$_init = true;
set_exception_handler([MyException::class, 'handler']);
set_error_handler([__CLASS__, 'errorHandler']);
}
public static function findFile($folder, $file, $ext = null): bool|string
{
if (empty(self::$_paths)) {
self::$_paths = [APPPATH, SYSPATH];
}
if ($ext === null) {
// Используйте расширение по умолчанию
$ext = EXT;
} elseif ($ext) {
// Префикс расширения с точкой
$ext = ".$ext";
} else {
// Не использовать расширение
$ext = '';
}
$path_file = $folder . '/' . $file . $ext;
$found = false;
foreach (self::$_paths as $dir) {
if (is_file($dir . '/' . $path_file)) {
$found = $dir . '/' . $path_file;
break;
}
}
return $found;
}
/**
* @throws ErrorException
*/
public static function errorHandler($code, $error, $file = null, $line = null): bool
{
if (error_reporting() & $code) {
// Эта ошибка не подавляется текущими настройками отчетов об ошибках
// Преобразование ошибки в ErrorException
throw new ErrorException($error, $code, 0, $file, $line);
}
// Продолжаем работать в штатном режиме
return true;
}
public static function getConst(string $name): mixed
{
return constant("self::$name");
}
}