Ejemplo n.º 1
0
 public static function call($message = 'Application Error', $code = 500)
 {
     $_SERVER['REQUEST_URI'] = '/error';
     header('HTTP/1.1 ' . $code . ' ' . $message);
     application::$instance = new application();
     application::get_instance()->bootstrap()->run();
     exit;
 }
Ejemplo n.º 2
0
 public static function get_instance()
 {
     if (self::$instance == null) {
         // Инициализируем автолоадер. Он ищет сначала в каталоге приложения, если класса нет и есть такой же с префиксом k_ в ядре, содает класс обертку с запрашиваемым именем и наследует ее от найденного в ядре класса
         spl_autoload_register(function ($class) {
             $is_zend = substr($class, 0, 5) == 'Zend\\';
             if ($is_zend) {
                 if (application::$zend_icluded) {
                     return;
                 }
                 include_once PATH_ROOT . '/' . DIR_LIBRARY . '/lib/Zend/Loader/StandardAutoloader.php';
                 $loader = new Zend\Loader\StandardAutoloader();
                 $loader->registerNamespace('Zend', PATH_ROOT . '/' . DIR_LIBRARY . '/lib/Zend');
                 $loader->register();
                 if ($class !== 'Zend\\Loader\\StandardAutoloader') {
                     $loader->autoload($class);
                 }
             } else {
                 $is_kernel = substr($class, 0, 2) == 'k_';
                 $fn = str_replace('_', '/', $is_kernel ? preg_replace('/^k\\_/', '', $class) : $class) . '.php';
                 if (!$is_kernel && file_exists(PATH_ROOT . '/' . DIR_APPLICATION . '/' . $fn)) {
                     require_once PATH_ROOT . '/' . DIR_APPLICATION . '/' . $fn;
                 } else {
                     if (!$is_kernel && defined('DIR_ZLIBRARY') && file_exists(PATH_ROOT . '/' . DIR_ZLIBRARY . '/' . $fn)) {
                         require_once PATH_ROOT . '/' . DIR_ZLIBRARY . '/' . $fn;
                     } else {
                         if (file_exists(PATH_ROOT . '/' . DIR_LIBRARY . '/' . $fn)) {
                             require_once PATH_ROOT . '/' . DIR_LIBRARY . '/' . $fn;
                             if (!$is_kernel && class_exists('k_' . $class)) {
                                 eval('class ' . $class . ' extends k_' . $class . ' {};');
                             }
                         } else {
                             if (class_exists('common') && method_exists('common', 'autoload')) {
                                 common::autoload($class);
                             }
                         }
                     }
                 }
             }
         });
         // Экземпляр приложения создается не из текущего класса, а из класса, который находится в папке приложения
         application::$instance = new application();
     }
     return application::$instance;
 }
 public static function getApplication() {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }