/** * Получить приложение * @param string $app Имя приложения * @param string $typeApp Тип приожения * @param $arg Парметр для конструктора приложения * @return object */ public function getApp($app, $typeApp = 'frontend', $arg = null) { $nameClass = $app . '_' . $typeApp; if (!empty($this->appendices[$nameClass])) { return $this->appendices[$nameClass]->object; } else { $folderAppendices = Mr::gt('Env')->folderAppendicesSite; $folderAppendix = $folderAppendices . $app; if (!Mr::loadFile($folderAppendix . '/' . $typeApp . '.php')) { $folderAppendices = Mr::gt('Env')->folderAppendicesCore; $folderAppendix = $folderAppendices . $app; if (!Mr::loadFile($folderAppendix . '/' . $typeApp . '.php')) { return false; } } if (!class_exists($nameClass)) { return false; } $this->appendices[$nameClass] = new stdClass(); $this->appendices[$nameClass]->path = $folderAppendices; $this->appendices[$nameClass]->type = $typeApp; $this->appendices[$nameClass]->name = $app; $this->appendices[$nameClass]->object =& $object; return $object = new $nameClass($arg); } }
/** * * @param string $name Название интерфейса * @param string $type Тип интерфейса */ public function loadInterface($name, $type = 'html') { if (!(include $path = Mr::gt('Env')->folderViewSite . 'interface/' . $name . '.' . $type)) { if (!(include $path = Mr::gt('Env')->folderViewSite . 'interface/' . $name . '.' . $type)) { echo 'Интерфейс "' . $path . '" не найден.'; } } }
/** * Отобразить файл шаблона * @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('Файл шаблона не найден.'); } } }
static function factory($name, $params) { if (is_string($name) && (is_array($params) || is_object($params))) { include_once 'standart.gliss_db.class.php'; include_once Mr::gt('Lib')->getPathToLib() . '/db/' . $name . '.class.php'; if (!class_exists($name . '_gliss_db')) { throw new Exception('Класс "' . $name . '_gliss_db" не найден.'); } $class = $name . '_gliss_db'; return new $class($params); } }
/** * Загрузить библиотеку * @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('Имя библиотеки должно быть строкой.'); } }
/** * Запуск приложения */ protected function _run($filter = "/^[A-z][A-z0-9]+\$/", $default = 'index') { Mr::gt('View')->appendix = Mr::gt('App')->getNameApp(); $this->_default = $default; $this->model = Mr::gt('App')->getApp($_GET[0], App::MODEL); if (method_exists($this->model, 'setObjectDatabase')) { if (@(!is_object($this->db))) { $this->db = Mr::gt('Lib')->getLib('gliss_db')->factory('mysql', Mr::gt('Env')->basis); } $this->model->setObjectDatabase(@$this->db); } if (preg_match($filter, @$_GET[1])) { $this->{$_GET[1]}(); } else { $this->{$default}(); } }
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(); } }
/** * Инициализация текущего приложения */ 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 . '" не найдено.'); } } } }
@ini_set('display_errors', 1); @ini_set('html_errors', 0); @ini_set('magic_quotes_runtime', 0); @ini_set('magic_quotes_sybase', 0); set_time_limit(30); mb_internal_encoding('UTF-8'); header('Content-Type: text/html; charset=utf-8'); session_start(); $start_time = microtime(true); $start_memory = memory_get_usage(); if (defined('ENTRY_POINT')) { define('GLISS_DIR', get_include_path()); } else { define('GLISS_DIR', dirname(__FILE__) . '/'); } @define('ENTRY_POINT', true); include_once GLISS_DIR . 'kernel/Mr.class.php'; include_once GLISS_DIR . 'kernel/std.func.php'; if (get_magic_quotes_gpc()) { $_POST = array_map('stripslashes_deep', (array) $_POST); $_GET = array_map('stripslashes_deep', (array) $_GET); $_COOKIE = array_map('stripslashes_deep', (array) $_COOKIE); } Mr::start(); Mr::gt('App')->start(); $exec_time = microtime(true) - $start_time; $exec_memory = memory_get_usage() - $start_memory; printf("\n<!-- Time: %f сек.-->", $exec_time); printf("\n<!-- Memory: %f mb.-->", round($exec_memory / 1048576, 2)); printf("\n<!-- Gliss Framework 2010 - 2011. Kazin Fedor. -->");
/** * Получить список доступных приложений * @return array список приложений */ public function getAvailableAppendices() { $siteAppendices = (array) @scandir(Mr::gt('Env')->folderAppendicesSite); $coreAppendices = (array) @scandir(Mr::gt('Env')->folderAppendicesCore); $generalAppendices = array_merge($siteAppendices, $coreAppendices); foreach ($generalAppendices as $nameAppendix) { if (preg_match("/^[A-z0-9]+\$/", $nameAppendix)) { $Appendices[] = $nameAppendix; } } $usedAppndices = array_unique(array_diff($Appendices, Mr::gt('Env')->basis->unused)); return $usedAppndices; }
<?php @ini_set('display_errors', 1); @ini_set('html_errors', 0); @ini_set('magic_quotes_runtime', 0); @ini_set('magic_quotes_sybase', 0); error_reporting(E_ALL); set_time_limit(30); mb_internal_encoding('UTF-8'); header('Content-Type: text/html; charset=utf-8'); session_start(); define('GLISS_DIR', defined('ENTRY_POINT') ? get_include_path() : dirname(__FILE__) . '/'); define('GLISS_KERNEL_DIR', GLISS_DIR . 'kernel/'); @define('ENTRY_POINT', true); include_once GLISS_KERNEL_DIR . 'Mr.class.php'; Mr::start(GLISS_KERNEL_DIR); Mr::gt('Env')->start();
/** * Запустить сервис */ public function start() { if (!Mr::gt('Env')->View) { Mr::gt('Env')->View = new Service(); } }
function __construct() { Mr::gt('Lib')->getLib('gliss_sample'); Mr::gt('Lib')->gliss_sample->load('app'); Mr::gt('Lib')->gliss_sample->load('model'); }
function loadSettings($app = null) { $path = is_string($app) ? $this->appendix . $app : Mr::gt('*')->site_dir; if (file_exists($path)) { return @parse_ini_file($path . $this->settings, true); } }
/** * Запуск сервиса * @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() . '" запрещен.'); } }
function load($class) { include_once Mr::gt('Lib')->getPathToLib() . '/' . $class . '.sample.class.php'; }