示例#1
0
 /**
  * 应用程序初始化
  */
 public static function start()
 {
     // 注册AUTOLOAD方法
     spl_autoload_register('Think\\Think::autoLoad');
     // 设定错误和异常处理
     register_shutdown_function('Think\\Think::fatalError');
     set_error_handler('Think\\Think::appError');
     set_exception_handler('Think\\Think::appException');
     // 初始化文件存储方式
     Storage::connect(STORAGE_TYPE);
     $runtimeFile = RUNTIME_PATH . APP_MODE . '~runtime.php';
     if (!APP_DEBUG && Storage::has($runtimeFile)) {
         Storage::load($runtimeFile);
     } else {
         $content = '';
         // 读取应用模式
         $mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php');
         // 加载核心文件
         foreach ($mode['core'] as $file) {
             if (is_file($file)) {
                 include $file;
                 if (!APP_DEBUG) {
                     $content .= compile($file);
                 }
             }
         }
         // 加载应用模式配置文件
         foreach ($mode['config'] as $key => $file) {
             is_numeric($key) ? C(load_config($file)) : C($key, load_config($file));
         }
     }
 }
示例#2
0
文件: Think.class.php 项目: dlpc/shop
 /**
  * 应用程序初始化
  * @access public
  * @return void
  */
 public static function start()
 {
     // 注册AUTOLOAD方法
     spl_autoload_register('Think\\Think::autoload');
     // 设定错误和异常处理
     register_shutdown_function('Think\\Think::fatalError');
     set_error_handler('Think\\Think::appError');
     set_exception_handler('Think\\Think::appException');
     // 初始化文件存储方式
     Storage::connect(STORAGE_TYPE);
     $runtimefile = RUNTIME_PATH . APP_MODE . '~runtime.php';
     if (!APP_DEBUG && Storage::has($runtimefile)) {
         Storage::load($runtimefile);
     } else {
         if (Storage::has($runtimefile)) {
             Storage::unlink($runtimefile);
         }
         $content = '';
         // 读取应用模式
         $mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php');
         // 加载核心文件
         foreach ($mode['core'] as $file) {
             if (is_file($file)) {
                 include $file;
                 if (!APP_DEBUG) {
                     $content .= compile($file);
                 }
             }
         }
         // 加载应用模式配置文件
         foreach ($mode['config'] as $key => $file) {
             is_numeric($key) ? C(include $file) : C($key, include $file);
         }
         // 读取当前应用模式对应的配置文件
         if ('common' != APP_MODE && is_file(CONF_PATH . 'config_' . APP_MODE . '.php')) {
             C(include CONF_PATH . 'config_' . APP_MODE . '.php');
         }
         // 加载模式别名定义
         if (isset($mode['alias'])) {
             self::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias']));
         }
         // 加载应用别名定义文件
         if (is_file(CONF_PATH . 'alias.php')) {
             self::addMap(include CONF_PATH . 'alias.php');
         }
         // 加载模式行为定义
         if (isset($mode['tags'])) {
             Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags']));
         }
         // 加载应用行为定义
         if (is_file(CONF_PATH . 'tags.php')) {
             // 允许应用增加开发模式配置定义
             Hook::import(include CONF_PATH . 'tags.php');
         }
         // 加载框架底层语言包
         L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php');
         if (!APP_DEBUG) {
             $content .= "\nnamespace { Think\\Think::addMap(" . var_export(self::$_map, true) . ");";
             $content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(Hook::get(), true) . ');}';
             Storage::put($runtimefile, strip_whitespace('<?php ' . $content));
         } else {
             // 调试模式加载系统默认的配置文件
             C(include THINK_PATH . 'Conf/debug.php');
             // 读取应用调试配置文件
             if (is_file(CONF_PATH . 'debug.php')) {
                 C(include CONF_PATH . 'debug.php');
             }
         }
     }
     // 读取当前应用状态对应的配置文件
     if (APP_STATUS && is_file(CONF_PATH . APP_STATUS . '.php')) {
         C(include CONF_PATH . APP_STATUS . '.php');
     }
     // 设置系统时区
     date_default_timezone_set(C('DEFAULT_TIMEZONE'));
     // 检查应用目录结构 如果不存在则自动创建
     if (C('CHECK_APP_DIR') && !is_dir(LOG_PATH)) {
         // 创建应用目录结构
         require THINK_PATH . 'Common/build.php';
     }
     // 记录加载文件时间
     G('loadTime');
     // 运行应用
     App::run();
 }
示例#3
0
 public static function cleanupFile($file_id)
 {
     // If there are now no links, delete the file
     $r = Dal::query_one("SELECT link_count, storage_backend, local_id FROM files WHERE file_id=?", array($file_id));
     if (empty($r)) {
         throw new PAException(FILE_NOT_FOUND, "Cannot clean up file {$file_id} as it does not exist in the 'files' table");
     }
     list($link_count, $backend_type, $local_id) = $r;
     if (!$link_count) {
         $ctx = Storage::connect($backend_type);
         $ctx->delete($local_id);
         Dal::query("DELETE FROM files WHERE file_id=?", array($file_id));
         return TRUE;
     }
     return FALSE;
 }
示例#4
0
 /**
  * 应用程序初始化
  * @access public
  * @return void
  */
 public static function start()
 {
     // 设定错误和异常处理
     register_shutdown_function('Think\\Think::fatalError');
     set_error_handler('Think\\Think::appError');
     set_exception_handler('Think\\Think::appException');
     // 注册AUTOLOAD方法
     spl_autoload_register('Think\\Think::autoload');
     // 初始化文件存储方式
     Storage::connect(STORAGE_TYPE);
     $runtimefile = RUNTIME_PATH . APP_MODE . '~runtime.php';
     if (!APP_DEBUG && Storage::has($runtimefile, 'runtime')) {
         Storage::load($runtimefile, null, 'runtime');
     } else {
         if (Storage::has($runtimefile, 'runtime')) {
             Storage::unlink($runtimefile, 'runtime');
         }
         $content = '';
         // 读取应用模式
         $mode = (include is_file(COMMON_PATH . 'Conf/core.php') ? COMMON_PATH . 'Conf/core.php' : THINK_PATH . 'Conf/Mode/' . APP_MODE . '.php');
         // 加载核心文件
         foreach ($mode['core'] as $file) {
             if (is_file($file)) {
                 include $file;
                 if (!APP_DEBUG) {
                     $content .= compile($file);
                 }
             }
         }
         // 加载配置文件
         foreach ($mode['config'] as $key => $file) {
             is_numeric($key) ? C(include $file) : C($key, include $file);
         }
         // 加载别名定义
         foreach ($mode['alias'] as $alias) {
             self::addMap(is_array($alias) ? $alias : (file_exists($alias) ? include $alias : array()));
         }
         // 加载模式系统行为定义
         if (isset($mode['extends'])) {
             Hook::import(is_array($mode['extends']) ? $mode['extends'] : (include $mode['extends']));
         }
         // 加载应用行为定义
         if (isset($mode['tags'])) {
             if (is_array($mode['tags'])) {
                 $tags = $mode['tags'];
             } else {
                 $tags = file_exists($mode['tags']) ? include $mode['tags'] : array();
             }
             Hook::import($tags);
         }
         // 加载框架底层语言包
         L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php');
         if (!APP_DEBUG) {
             $content .= "\nnamespace { Think\\Think::addMap(" . var_export(self::$_map, true) . ");";
             $content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(Hook::get(), true) . ');}';
             Storage::put($runtimefile, strip_whitespace('<?php ' . $content), 'runtime');
         } else {
             // 调试模式加载系统默认的配置文件
             C(include THINK_PATH . 'Conf/debug.php');
             // 读取调试模式的应用状态
             $status = C('APP_STATUS');
             // 加载对应的项目配置文件
             if (is_file(COMMON_PATH . 'Conf/' . $status . '.php')) {
                 // 允许项目增加开发模式配置定义
                 C(include COMMON_PATH . 'Conf/' . $status . '.php');
             }
         }
     }
     // 设置系统时区
     date_default_timezone_set(C('DEFAULT_TIMEZONE'));
     // 检查项目目录结构 如果不存在则自动创建
     if (C('CHECK_APP_DIR') && !is_dir(LOG_PATH)) {
         // 创建项目目录结构
         require THINK_PATH . 'Common/build.php';
     }
     // 记录加载文件时间
     G('loadTime');
     if (!defined('IsInterface')) {
         // 运行应用
         App::run();
     } else {
         App::init();
     }
 }
 public function getURL()
 {
     $ctx = Storage::connect($this->storage_backend);
     return $ctx->getURL($this->local_id);
 }
 /**
  * 启动模拟应用
  */
 public function start()
 {
     spl_autoload_register('\\Think\\PhpunitHelper::autoload');
     register_shutdown_function('\\Think\\PhpunitHelper::fatalError');
     Storage::connect(STORAGE_TYPE);
     $mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php');
     // 加载核心文件
     foreach ($mode['core'] as $file) {
         if (is_file($file)) {
             if (strpos($file, 'Think/Controller.class.php') !== false || strpos($file, 'Think\\Controller.class.php') !== false || strpos($file, 'Think/View.class.php') !== false || strpos($file, 'Think\\View.class.php') !== false) {
                 // not include
             } else {
                 include_once $file;
             }
         }
     }
     // 加载应用模式配置文件
     foreach ($mode['config'] as $key => $file) {
         is_numeric($key) ? C(load_config($file)) : C($key, load_config($file));
     }
     // 读取当前应用模式对应的配置文件
     if ('common' != APP_MODE && is_file(CONF_PATH . 'config_' . APP_MODE . CONF_EXT)) {
         C(load_config(CONF_PATH . 'config_' . APP_MODE . CONF_EXT));
     }
     // 加载模式别名定义
     if (isset($mode['alias'])) {
         self::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias']));
     }
     // 加载应用别名定义文件
     if (is_file(CONF_PATH . 'alias.php')) {
         self::addMap(include CONF_PATH . 'alias.php');
     }
     // 加载模式行为定义
     if (isset($mode['tags'])) {
         \Think\Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags']));
     }
     // 加载应用行为定义
     if (is_file(CONF_PATH . 'tags.php')) {
         // 允许应用增加开发模式配置定义
         \Think\Hook::import(include CONF_PATH . 'tags.php');
     }
     // 加载框架底层语言包
     L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php');
     // 调试模式加载系统默认的配置文件
     C(include THINK_PATH . 'Conf/debug.php');
     // 读取应用调试配置文件
     if (is_file(CONF_PATH . 'debug' . CONF_EXT)) {
         C(include CONF_PATH . 'debug' . CONF_EXT);
     }
     C('HTML_CACHE_ON', false);
     C('LIMIT_ROBOT_VISIT', false);
     C('LIMIT_PROXY_VISIT', false);
     $this->run();
 }