public function __construct($filename = 'global') { if (file_exists(Path::getRoot('app/config/') . $filename . '.config')) { $this->filepath = Path::getRoot('app/config/') . $filename . '.config'; } else { $this->filepath = Path::getRoot('core/config/') . $filename . '.config'; } $this->load(); }
public static function includeController($className, $folder = '') { if (!class_exists($className, false)) { if (file_exists(Path::getRoot('app/controllers/' . $folder . '/' . $className . '.php'))) { require_once Path::getRoot('app/controllers/' . $folder . '/' . $className . '.php'); } else { if (file_exists(Path::getRoot('core/controllers/' . $folder . '/' . $className . '.php'))) { require_once Path::getRoot('core/controllers/' . $folder . '/' . $className . '.php'); } else { throw new Exception('Controller not exist. Please create Controller or configure route! '); } } } }
function run() { // Получаем URI. $uri = $this->uri; if (strpos($uri, '?') !== FALSE) { parse_str(substr($uri, strpos($uri, '?') + 1), $_GET); $uri = substr($uri, 0, strpos($uri, '?')); } if ($uri == '') { $uri = 'none'; } $segments = explode('/', $uri); $this->routes[] = array('rules' => include Path::getRoot('app/routes.php')); $uri = implode('/', $segments); $this->routes = array_reverse($this->routes); // Пытаемся применить к нему правила из конфигуации. foreach ($this->routes as $routes) { foreach ($routes['rules'] as $pattern => $route) { // Если правило совпало. if (preg_match("~^{$pattern}\$~", $uri) && $pattern != ' ') { $internalRoute = preg_replace("~{$pattern}~", $route, $uri, 1); // print_r($internalRoute); // echo $uri; // echo $route; $segments = explode('|', $internalRoute); $controller_folder = array_shift($segments); $controller_url = array_shift($segments); $controller = ucfirst($controller_url) . 'Controller'; $action_array = explode('-', array_shift($segments)); $action_name = ''; foreach ($action_array as $action) { $action_name .= $action; } // echo $action_name; $params = array(); $params['action'] = $action_name; $action_name = ucfirst($action_name); // echo $actionName; if (!$action_name) { $action_name = 'Index'; } $action = 'action' . $action_name; // Остальные сегменты — параметры. $parameters = $segments; // echo 12; // print_r($parameters); foreach ($parameters as &$parameter) { $key_value = explode('=', $parameter); if (isset($key_value[1])) { $params[$key_value[0]] = $key_value[1]; } else { $params[] = $key_value[0]; } } $params['controller'] = $controller_url; $controller_object = ControllerFactory::getController($controller, $controller_folder); self::$params = $params; self::$rule = $pattern; $controller_object->run($action, $params, $controller_url); // Вызываем действие контроллера с параметрами return; } } } $controller_folder = ''; //array_shift($segments); $controller_url = array_shift($segments); // two is controller $controller = ucfirst($controller_url) . 'Controller'; // three — действие. $action_array = explode('-', array_shift($segments)); $action_name = ''; foreach ($action_array as $action) { $action_name .= $action; } $params = array(); $params['action'] = $action_name; $action_name = ucfirst($action_name); // echo $actionName; if (!$action_name) { $action_name = 'Index'; } $action = 'action' . $action_name; $parameters = $segments; // $params = array(); foreach ($parameters as &$parameter) { $key_value = explode('=', $parameter); if (isset($key_value[1])) { $params[$key_value[0]] = $key_value[1]; } else { $params[] = $key_value[0]; } } $params['controller'] = $controller_url; // Подключаем файл контроллера, если он имеется //print_r($action); // echo $controller_folder; $controller_object = ControllerFactory::getController($controller, $controller_folder); self::$params = $params; // Если не загружен нужный класс контроллера или в нём нет // нужного метода — 404 $controller_object->run($action, $params, $controller_url); // Вызываем действие контроллера с параметрами return; }
public static function log($message) { @file_put_contents(Path::getRoot('app/logs/log.txt'), date('Y-m-d h:i:s') . ' ' . $message . PHP_EOL, FILE_APPEND); }
<?php use guidaMedia\Leroy\LeCore\LeSystemFunctions; include '../../../bootStrap.php'; $fileName = str_replace('|', '/', $_GET['file']); $filePath = Path::getRoot() . 'Skins/' . $_GET['accountId'] . '/Images/' . $fileName; $file = null; if ('.png' == substr($fileName, -4)) { $file = imageCreateFromPng($filePath); header("Content-type: image/png"); imagePng($file); } elseif ('.gif' == substr($fileName, -4)) { $file = imagecreatefromgif($filePath); header("Content-type: image/gif"); imagegif($file); } elseif (in_array(substr($fileName, -4), ['.jpg', 'jpeg'])) { $file = imagecreatefromjpeg($filePath); header("Content-type: image/jpeg"); imagejpeg($file); } if (!is_null($file)) { imagedestroy($file); }