示例#1
0
 /**
  * Includes the php file that contains the given class (must contain namespace)
  *
  * @param $class_name string class name (with or without namespace)
  * @return boolean
  */
 public function autoload($class_name)
 {
     if ($i = strrpos($class_name, '\\')) {
         $namespace = strtolower(str_replace('\\', '/', substr($class_name, 0, $i)));
         $file_name = substr($class_name, $i + 1);
         // 'A\Class' stored into 'a/class/Class.php'
         if (file_exists($file1 = strtolower($namespace . '/' . $file_name) . '/' . $file_name . '.php')) {
             /** @noinspection PhpIncludeInspection */
             $result = (include_once Include_Filter::file($file1));
         } elseif (file_exists($file2 = strtolower($namespace) . '/' . $file_name . '.php')) {
             /** @noinspection PhpIncludeInspection */
             $result = (include_once Include_Filter::file($file2));
         } else {
             if (Builder::isBuilt($class_name)) {
                 $file = 'cache/compiled/' . str_replace(SL, '-', Names::classToPath($class_name));
                 if (file_exists($file)) {
                     /** @noinspection PhpIncludeInspection */
                     $result = (include_once $file);
                 }
             }
             if (!isset($result)) {
                 if (error_reporting()) {
                     trigger_error('Class not found ' . $class_name . ', should be into ' . $file1 . ' or ' . $file2, E_USER_ERROR);
                 }
                 $result = false;
             }
         }
     } else {
         /** @noinspection PhpIncludeInspection */
         $result = (include_once Include_Filter::file($class_name . '.php'));
     }
     // instantiate plugin
     if ($result && class_exists($class_name, false) && is_a($class_name, Plugin::class, true)) {
         if (Session::current()) {
             Session::current()->plugins->get($class_name);
         }
     }
 }
示例#2
0
文件: Main.php 项目: TuxBoy/Demo-saf
 private function includes()
 {
     foreach (glob(__DIR__ . '/../functions/*.php') as $file_name) {
         /** @noinspection PhpIncludeInspection */
         include_once Include_Filter::file($file_name);
     }
 }
示例#3
0
文件: index.php 项目: TuxBoy/Demo-saf
ini_set('max_input_vars', 1000000);
ini_set('memory_limit', '1024M');
ini_set('session.use_cookies', true);
ini_set('xdebug.collect_params', 4);
ini_set('xdebug.max_nesting_level', 255);
//ini_set('xdebug.scream', true);
ini_set('xdebug.var_display_max_children', 10);
ini_set('xdebug.var_display_max_data', 150);
ini_set('xdebug.var_display_max_depth', 3);
set_time_limit(30);
//&XDEBUG_PROFILE=1
// enable running from command line
if (!isset($_SERVER['PATH_INFO'])) {
    $_SERVER['PATH_INFO'] = '/';
}
$_SERVER['CWD'] = getcwd();
// enable cache files for compiled scripts : includes must all use this filter
include_once 'saf/framework/aop/Include_Filter.php';
Include_Filter::register();
// enable autoloader
/** @noinspection PhpIncludeInspection */
include_once Include_Filter::file('saf/framework/Autoloader.php');
(new Autoloader())->register();
// run main controller
echo (new Main())->init()->addTopCorePlugins([new Manager(), new Html_Session(['use_cookie' => true])])->run($_SERVER['PATH_INFO'], $_GET, $_POST, $_FILES);
// Display result on client browser now, as session serialization could take a moment
flush();
// When running php on cgi mode, getcwd() will return '/usr/lib/cgi-bin' on specific serialize()
// calls. This is a php bug, calling session_write_close() here will serialize session variables
// within the correct application environment
session_write_close();
示例#4
0
 /**
  * @param $class_name string
  * @return string
  */
 public function autoload($class_name)
 {
     $file_path = $this->getClassFilename($class_name);
     if ($file_path) {
         /** @noinspection PhpIncludeInspection */
         include_once Include_Filter::file($file_path);
         // if included file does not contain the good class : will need to scan for the right file
         if (!class_exists($class_name) && !interface_exists($class_name) && !trait_exists($class_name)) {
             unset($this->class_paths[$class_name]);
             $file_path = $this->autoload($class_name);
         } elseif (Session::current()->plugins->has($class_name)) {
             Session::current()->plugins->get($class_name);
         }
     }
     return $file_path;
 }