コード例 #1
0
ファイル: Application.php プロジェクト: tigron/skeleton-error
 /**
  * Handle the exception with a hook in the current application
  *
  * @return string
  */
 public function handle()
 {
     if (\Skeleton\Core\Hook::exists('handle_error', [$this->exception])) {
         // If the error is handled within the application, no need to continue
         // internally.
         $this->last_handler = true;
         \Skeleton\Core\Hook::call('handle_error', [$this->exception]);
     }
 }
コード例 #2
0
ファイル: Module.php プロジェクト: tigron/skeleton-core
 /**
  * Accept the request
  *
  * @access public
  */
 public function accept_request()
 {
     /**
      * Cleanup sticky session
      */
     \Skeleton\Core\Web\Session\Sticky::cleanup();
     $sticky = \Skeleton\Core\Web\Session\Sticky::Get();
     // Bootstrap the application
     $application = \Skeleton\Core\Application::get();
     // Call the bootstrap hook if it exists
     Hook::call_if_exists('bootstrap', [$this]);
     // Find the template and set it up
     $template = \Skeleton\Core\Web\Template::Get();
     $template->add_environment('module', $this);
     $template->add_environment('sticky_session', $sticky->get_as_array());
     // Call our magic secure() method before passing on the request
     $allowed = true;
     if (method_exists($this, 'secure')) {
         $allowed = $this->secure();
     }
     // If the request is not allowed, make sure it gets handled properly
     if ($allowed === false) {
         $module_403 = strtolower(\Skeleton\Core\Config::$module_403);
         // Always check if it can not be handled by a hook first
         if (Hook::exists('module_access_denied')) {
             Hook::call('module_access_denied', [$this]);
         } elseif ($module_403 !== null and file_exists($application->module_path . '/' . $module_403 . '.php')) {
             require $application->module_path . '/' . $module_403 . '.php';
             $classname = 'Web_Module_' . $module_403;
             $module = new $classname();
             $module->accept_request();
         } else {
             throw new \Exception('Access denied');
         }
     } else {
         $this->handle_request();
     }
     // Call the teardown hook if it exists
     Hook::call_if_exists('teardown', [$this]);
 }
コード例 #3
0
ファイル: Handler.php プロジェクト: tigron/skeleton-core
 /**
  * Handle the request and send it to the correct module
  *
  * @access public
  */
 public static function run()
 {
     /**
      * Record the start time in microseconds
      */
     $start = microtime(true);
     mb_internal_encoding('utf-8');
     /**
      * Hide PHP powered by
      */
     header('X-Powered-By: Me');
     /**
      * Parse the requested URL
      */
     $components = parse_url($_SERVER['REQUEST_URI']);
     if (isset($components['query'])) {
         $query_string = $components['query'];
     } else {
         $query_string = '';
     }
     if (isset($components['path']) and $components['path'] !== '/') {
         $request_uri_parts = explode('/', $components['path']);
         array_shift($request_uri_parts);
     } else {
         $request_uri_parts = [];
     }
     $request_uri = '/' . implode('/', $request_uri_parts) . '/';
     // Find out what the hostname is, if none was found, bail out
     if (!empty($_SERVER['SERVER_NAME'])) {
         $hostname = $_SERVER['SERVER_NAME'];
     } elseif (!empty($_SERVER['HTTP_HOST'])) {
         $hostname = $_SERVER['HTTP_HOST'];
     } else {
         throw new \Exception('Not a web request');
     }
     /**
      * Define the application
      */
     try {
         $application = Application::detect($hostname, $request_uri);
     } catch (Exception $e) {
         HTTP\Status::code_404('application');
     }
     /**
      * Handle the media
      */
     if (isset($application->config->detect_media) and $application->config->detect_media === true or !isset($application->config->detect_media)) {
         Media::detect($application->request_relative_uri);
     }
     /**
      * Start the session
      */
     Session::start();
     /**
      * Find the module to load
      *
      * FIXME: this nested try/catch is not the prettiest of things
      */
     $module = null;
     try {
         // Attempt to find the module by matching defined routes
         $module = $application->route($request_uri);
     } catch (\Exception $e) {
         try {
             // Attempt to find a module by matching paths
             $module = Module::get($application->request_relative_uri);
         } catch (\Exception $e) {
             if (Hook::exists('module_not_found')) {
                 Hook::call('module_not_found');
             } else {
                 HTTP\Status::code_404('module');
             }
         }
     }
     /**
      * Set language
      */
     // Set the language to something sensible if it isn't set yet
     if (class_exists('\\Skeleton\\I18n\\Config') and isset(\Skeleton\I18n\Config::$language_interface)) {
         $language_interface = \Skeleton\I18n\Config::$language_interface;
         if (!class_exists($language_interface)) {
             throw new \Exception('The language interface does not exists: ' . $language_interface);
         }
         if (!isset($_SESSION['language'])) {
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $languages = $language_interface::get_all();
                 foreach ($languages as $language) {
                     if (strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], $language->name_short) !== false) {
                         $language = $language;
                         $_SESSION['language'] = $language;
                     }
                 }
             }
             if (!isset($_SESSION['language'])) {
                 $language = $language_interface::get_by_name_short($application->config->default_language);
                 $_SESSION['language'] = $language;
             }
         }
         if (isset($_GET['language'])) {
             try {
                 $language = $language_interface::get_by_name_short($_GET['language']);
                 $_SESSION['language'] = $language;
             } catch (\Exception $e) {
                 $_SESSION['language'] = $language_interface::get_by_name_short($application->config->default_language);
             }
         }
         $application->language = $_SESSION['language'];
     }
     if ($module !== null) {
         $module->accept_request();
     }
 }
コード例 #4
0
ファイル: Media.php プロジェクト: tigron/skeleton-core
 /**
  * Fail
  *
  * @access private
  */
 private static function fail()
 {
     if (\Skeleton\Core\Hook::exists('media_not_found')) {
         \Skeleton\Core\Hook::call('media_not_found');
     } else {
         HTTP\Status::code_404('media');
     }
 }