Example #1
0
 /**
  * Singleton
  * @return app
  */
 public static function getInstance()
 {
     if (self::$self != NULL) {
         return self::$self;
     }
     self::$self = new self();
     /// Получение параметров конфигурации из файла
     self::$config = (include __NGN__ . '/config.inc');
     /// Подключение простого модуля кэширования с помощью APC
     # include(__SYSTEM__.'/aeon.cache.php');
     # self::$cache = new SimpleCache();
     /// Если есть APC храним в нём список helper'ов
     /*
     if(__APC__){
         if(apc_exists('helpers-list')) $ext = json_decode(apc_fetch('helpers-list'), true);
         else {
             $ext = glob(__HELPERS__.'/*.php');
             apc_add('helpers-list', json_encode($ext), 2);
         }
     } else {
         $ext = glob(__HELPERS__.'/*.php');
     };
     */
     /// Модуль авторизации
     # self::$extensions['auth'] = \Auth::getInstance();
     /*
             /// Подключаем Helper'ы
             foreach($ext as $v) {
                 include($v);
                 $ext_name = substr(basename($v), 0, -4);
                 $ext_class_name = '\Helper\\'.$ext_name;
                 self::$extensions[$ext_name] = $ext_class_name::getInstance(self::$self);
             };
             unset($ext);
     */
     include __SYSTEM__ . '/aeon.local.php';
     \Eva\Local::getInstance(self::$self);
     /// Сайт работает с БД?
     if (self::getParam('db:enabled')) {
         try {
             /// Пытаемся подключится
             self::$db = new PDO('mysql:host=' . self::getParam('db:server') . '; dbname=' . self::getParam('db:name'), self::getParam('db:user'), self::getParam('db:password'), array(PDO::ATTR_PERSISTENT => true));
             self::$db->query('SET character_set_client="utf8", character_set_results="utf8", collation_connection="cp1251_general_ci"');
         } catch (Exception $e) {
             /// Падаем и ложим весь сайт
             error_log('PDO is not supported on this OS! Please, contact your administrator!', 0);
             msg503();
         }
     }
     /// Роутер
     self::$router = \Router::getInstance();
     /// Возвращаем экземпляр класса движка
     return self::$self;
 }
Example #2
0
 public function __construct()
 {
     if (!empty($_POST) && !empty($_FILES)) {
         $this->httpMethod = 'post&files';
     } elseif (!empty($_POST)) {
         $this->httpMethod = 'post';
     } elseif (!empty($_FILES)) {
         $this->httpMethod = 'files';
     }
     $_SERVER['REQUEST_URI2'] = iconv('cp1251', 'utf-8', substr($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_URI'][1] == '?' ? 2 : 1));
     # $method = function_exists('apc_exists') ? 'loadCachedResources' : 'loadStaticResources';
     # TODO Сделать возможность работать с кешем APC
     $method = 'loadStaticResources';
     if (!!\Helper\Auth::getInstance()->isAuth()) {
         $this->{$method}(__APP__ . '/*/*/routes.secure.php');
         $role = \Helper\Auth::getInstance()->getRole();
         if (isset($role[1])) {
             $this->{$method}(__APP__ . '/*/*/routes.' . $role . '.php');
         }
     } else {
         $this->{$method}(__APP__ . '/*/*/routes.unsecureonly.php');
     }
     $this->{$method}(__APP__ . "/*/*/routes.php");
     foreach ($this->rules as $section => $rules) {
         $config_temp = \app::getSectionConfig($section);
         $urlSection = $config_temp['eva:urlSection'];
         foreach ($rules as $template => $params) {
             $url = explode(':', $template);
             $url[1] = !$url[1] ? 'get' : $url[1];
             if ($url[1] !== $this->httpMethod) {
                 continue;
             }
             $matches = array();
             $url = str_replace('^', '^([a-z]{2}\\-[a-z]{2}[/]{1})?', str_replace('$section/', $urlSection, $url[0]));
             if (preg_match('/' . str_replace('/', '\\/', $url) . '/', urldecode($_SERVER['REQUEST_URI2']), $matches) == true) {
                 /**
                  * Настройки языка для Section. Например если сайт на русском, а административная панель на ТОЛЬКО английском.
                  * Если файла нет, то настройки по умолчанию.
                  */
                 \app::configSectionInject($section);
                 \Eva\Local::getInstance()->localeCheck();
                 $e = explode('?', $params);
                 $i = sizeof($matches);
                 for ($j = 1; $j < $i; ++$j) {
                     $e[1] = str_replace('$' . $j, $matches[$j + 1], $e[1]);
                 }
                 $e[1] = strtr(addslashes(urldecode($e[1])), array('=' => '":"', '&' => '","'));
                 if (isset($e[1][5])) {
                     $_GET = array_merge($_GET, json_decode(sprintf('{"%s"}', str_replace("\\'", "'", $e[1])), true));
                 }
                 list($class, $method) = explode('/', $e[0]);
                 \app::$app = array('section' => $section, 'class' => $class, 'method' => $method);
                 $class = '\\' . str_replace('.', '', $section) . '\\Presenter\\' . $class;
                 $e = new $class();
                 if (method_exists($e, $method)) {
                     $e->{$method}();
                 } else {
                     unset($class, $section, $method, $e, $url, $matches);
                     msg404();
                 }
                 unset($class, $section, $method, $e, $url, $matches);
                 return;
             }
         }
     }
     msg404();
 }