/** * Эскейпить Url * @param string $string * @return string * @exception Указанный параметр не является строкой */ public function escapeUrl($string = null) { if (is_string($string) || !$string) { return htmlentities($string); } else { Mr::exception('Указанный параметр не является строкой.'); } }
/** * Отобразить файл вида * @param string $name Название вида */ public function display($name = null, $type = 'html') { $view = (!empty($name) ? $name : Mr::gt('Env')->basis->view) . '.' . $type; if (!(include Mr::gt('Env')->folderViewSite . $view)) { if (!(include Mr::gt('Env')->folderViewCore . $view)) { Mr::exception('Файл шаблона не найден.'); } } }
/** * Отобразить файл шаблона * @param string $path */ public function display($path = null) { $this->_folderTemplate = !is_string($path) ? Mr::gt('Env')->folderInterfacesSite . Mr::gt('Env')->basis->interface : $path; $this->data = Mr::gt('Env')->data; if (!$this->loadTemplate()) { $this->_folderTemplate = Mr::gt('Env')->folderInterfacesCore . Mr::gt('Env')->basis->interface; if (!$this->loadTemplate()) { Mr::exception('Файл шаблона не найден.'); } } }
/** * Получить сервис * @param string|null $service Название сервиса * @return object Сервис или клон ядра */ public static function gt($name = null) { if (!empty($name)) { if (isset(self::$Services[$name])) { return self::$Services[$name]; } else { Mr::exception('Cервис "' . $name . '" не найден.'); } } else { return clone self::$Mr; } }
/** * Конструктор класса Env */ public function __construct() { if (!defined('GLISS_DIR')) { Mr::exception('Константа GLISS_DIR не установлена.'); } else { /** * Настройка параметров сервиса */ $this->setDefaultAccess(Service::READONLY); $this->gliss_dir = GLISS_DIR; $this->settings = '/settings.php'; $this->lang = '/lang/'; $this->frontend = '/frontend.php'; $this->backend = '/backend.php'; $this->appendix = Mr::gt('*')->site_dir . 'appendix/'; $this->interface = Mr::gt('*')->site_dir . 'interface/'; $this->data = Mr::gt('*')->host . 'data/'; $this->gliss_library = $this->gliss_dir . 'library/'; $this->gliss_appendix = $this->gliss_dir . 'appendix/'; $this->site_library = Mr::gt('*')->site_dir . 'library/'; $this->humanurl = substr(Mr::gt('*')->url, 0, 1) != '?'; $this->global = new Service(); $this->global->divider = '/'; $this->global->appendix = 'welcome'; $this->global->interface = 'default'; $this->global->rewrite = false; /** * Подгрузка модифицированных настроек */ if ($settings = $this->loadSettings()) { foreach ($settings as $key => $value) { if (is_scalar($value)) { $this->global->{$key} = $value; } } } /** * Эмуляция глобального массива $_GET */ if ($this->humanurl) { if (Mr::gt('*')->url) { $_GET = explode($this->global->divider, Mr::gt('*')->url); } else { parse_str(substr(Mr::gt('*')->url, 1), $_GET); } } if (isset($_GET[0])) { $_GET[0] = str_replace('/', '', $_GET[0]); } $this->GET = $_GET; } }
/** * Загрузить библиотеку * @return bool Статус загрузки * @exception Не найден класс/адаптер библиотеки */ private function loadLib() { $lib = Mr::gt('Env')->Lib->lib; if (is_file(Mr::gt('Env')->Lib->path . '/Adapter.php')) { include_once Mr::gt('Env')->Lib->path . '/Adapter.php'; if (class_exists($lib)) { $this->{$lib} = new $lib(); return true; } else { Mr::exception('Не найден класс/адаптер библиотеки "' . $lib . '"'); } } else { return false; } }
/** * Получить библиотеку * @param string $name Имя библиотека * @return object|bool * @exception Библиотека не найдена * @exception Имя библиотеки должно быть строкой */ public function getLib($name) { if (is_string($this->nameLibrary = $name)) { $this->forlderLibraries = Mr::gt('Env')->folderLibrariesSite; $this->forlderLibrary = $this->forlderLibraries . $this->nameLibrary; if (!($loadStatus = $this->loadLib())) { $this->folderLibraries = Mr::gt('Env')->folderLibrariesCore; $this->forlderLibrary = $this->folderLibraries . $this->nameLibrary; if (!($loadStatus = $this->loadLib())) { Mr::exception('Библиотека "' . $this->nameLibrary . '" не найдена!'); } } return $loadStatus; } else { Mr::exception('Имя библиотеки должно быть строкой.'); } }
public function __construct() { if (!defined('GLISS_DIR')) { Mr::exception('Константа GLISS_DIR не установлена.'); } else { $this->host = Mr::gt('*')->host; $this->url = Mr::gt('*')->url; $this->data = $this->host . 'data/'; $this->folderSite = Mr::gt('*')->site_dir; $this->folderCore = GLISS_DIR; $this->nameFileSetting = '/settings.php'; $this->folderAppendicesSite = $this->folderSite . 'appendix/'; $this->folderInterfacesSite = $this->folderSite . 'interface/'; $this->folderLibrariesSite = $this->folderSite . 'library/'; $this->folderAppendicesCore = $this->folderCore . 'appendix/'; $this->folderInterfacesCore = $this->folderCore . 'interface/'; $this->folderLibrariesCore = $this->folderCore . 'library/'; $this->friendlyURL = substr($this->url, 0, 1) != '?'; $this->basis->unused = array(); $this->basis->divider = '/'; $this->basis->appendix = 'welcome'; $this->basis->interface = 'default'; $this->basis->rewrite = false; $settingBasis = (array) $this->loadSettings(); foreach ($settingBasis as $key => $value) { $this->basis->{$key} = $value; } $this->global = $this->basis; if ($this->friendlyURL) { if ($this->url) { $_GET = explode($this->basis->divider, $this->url); } else { $_GET = gliss_parse_str(substr($this->url, 1)); } } else { $_GET = gliss_parse_str(substr($this->url, 1)); } if (isset($_GET[0])) { $_GET[0] = str_replace('/', null, $_GET[0]); } $this->GET = $_GET; } }
/** * Получить библиотеку * @param string $name Название библитеки * @return object */ public function getLib($name) { if (isset($this->libraries[$name])) { return $this->libraries[$name]->object; } else { $nameAdapter = $name . '_adapter'; $forlderLibraries = Mr::gt('Env')->folderLibrariesSite; $forlderLibrary = $forlderLibraries . $name; if (!Mr::loadFile($forlderLibrary . '/Adapter.php')) { $folderLibraries = Mr::gt('Env')->folderLibrariesCore; $forlderLibrary = $folderLibraries . $name; if (!Mr::loadFile($forlderLibrary . '/Adapter.php')) { Mr::exception('Библиотека "' . $name . '" не найдена!'); } } if (!class_exists($nameAdapter)) { Mr::exception('Класс "' . $nameAdapter . '" не найден.'); } $this->libraries[$name]->path = $forlderLibrary; $this->libraries[$name]->object =& $library; return $library = new $nameAdapter(); } }
/** * Запуск сервиса * @exception Приложение не найжено. * @exception Повторный вызов сервиса запрещен. */ public function start() { if (!isset(Mr::gt('Env')->App->startStatus)) { Mr::gt('Env')->App = new Service(); Mr::gt('Env')->App->setDefaultAccess(Service::READWRITE); Mr::gt('Env')->App->startStatus = true; Mr::gt('Env')->App->setAccessVar('startStatus', Service::READONLY); if (!$this->getApp($this->getNameCurrentApp())) { if (!$this->getApp($this->getNameCurrentApp(true))) { Mr::exception('Приложение "' . Mr::gt('Env')->global->appendix . '" не найдено.'); } } } else { Mr::exception('Повторный вызов серсиса "' . get_class() . '" запрещен.'); } }
/** * Инициализация текущего приложения */ public function start() { if (!isset($this->statusStart)) { $this->statusStart = true; if (!Mr::gt('App')->getApp($this->getCurrentApp())) { if (!Mr::gt('App')->getApp($this->getCurrentApp())) { Mr::exception('Приложение "' . Mr::gt('Env')->basis->appendix . '" не найдено.'); } } } }
public function fetchAll() { if ($this->_result) { while ($raw = $this->fetch()) { $row[] = $raw; } return @$row; } else { Mr::exception('Сначала нужно выполнить запрос.'); } }
/** * Запуск сервиса * @exception Приложение не найжено. * @exception Повторный вызов сервиса запрещен. */ public function start() { if (!isset($this->statusService)) { $this->statusService = true; if (!$this->getApp($this->getNameCurrentApp())) { if (!$this->getApp($this->getNameCurrentApp(true))) { Mr::exception('Приложение "' . Mr::gt('Env')->basis->appendix . '" не найдено.'); } } } else { Mr::exception('Повторный вызов серсиса "' . get_class() . '" запрещен.'); } }