requireFile() public static method

require 引入文件
public static requireFile ( string $file, array $args = [] ) : mixed
$file string 要引入的文件
$args array 要释放的变量
return mixed
Example #1
0
 /**
  * 显示404页面
  *
  * @param string $tpl 模板路径
  *
  * @return void
  */
 public static function show404Page($tpl = null)
 {
     self::sendHttpStatus(404);
     is_null($tpl) && ($tpl = Config::get('404_page'));
     is_file($tpl) && Cml::requireFile($tpl);
     exit;
 }
Example #2
0
 /**
  * 从注释解析生成文档
  *
  */
 public static function parse()
 {
     $result = [];
     $config = Config::load('api', Cml::getApplicationDir('app_controller_path') ? true : false);
     foreach ($config['version'] as $version => $apiList) {
         isset($result[$version]) || ($result[$version] = []);
         foreach ($apiList as $model => $api) {
             $pos = strrpos($api, '\\');
             $controller = substr($api, 0, $pos);
             $action = substr($api, $pos + 1);
             if (class_exists($controller) === false) {
                 continue;
             }
             $annotationParams = self::getAnnotationParams($controller, $action);
             empty($annotationParams) || ($result[$version][$model] = $annotationParams);
         }
     }
     foreach ($result as $key => $val) {
         if (count($val) < 1) {
             unset($result[$key]);
         }
     }
     $systemCode = Cml::requireFile(__DIR__ . DIRECTORY_SEPARATOR . 'resource' . DIRECTORY_SEPARATOR . 'code.php');
     Cml::requireFile(__DIR__ . DIRECTORY_SEPARATOR . 'resource' . DIRECTORY_SEPARATOR . 'doc.html', ['config' => $config, 'result' => $result, 'systemCode' => $systemCode]);
 }
Example #3
0
 /**
  * 静态页面-获取静态页面
  *
  * @param  string  $key  静态页面标识符,可以用id代替
  *
  * @return  bool
  */
 public function get($key)
 {
     $filename = $this->getFilename($key);
     if (!$filename || !is_file($filename)) {
         return false;
     }
     Cml::requireFile($filename);
     return true;
 }
Example #4
0
/**
 * 快速文件数据读取和保存 针对简单类型数据 字符串、数组
 *
 * @param string $name 缓存名称
 * @param mixed $value 缓存值
 * @param string $path 缓存路径
 *
 * @return mixed
 */
function simpleFileCache($name, $value = '', $path = null)
{
    is_null($path) && ($path = Cml::getApplicationDir('global_store_path') . DIRECTORY_SEPARATOR . 'Data');
    static $_cache = [];
    $filename = $path . '/' . $name . '.php';
    if ($value !== '') {
        if (is_null($value)) {
            // 删除缓存
            return false !== @unlink($filename);
        } else {
            if (is_array($value)) {
                // 缓存数据
                $dir = dirname($filename);
                // 目录不存在则创建
                is_dir($dir) || mkdir($dir, 0700, true);
                $_cache[$name] = $value;
                return file_put_contents($filename, "<?php\treturn " . var_export($value, true) . ";?>", LOCK_EX);
            } else {
                return false;
            }
        }
    }
    if (isset($_cache[$name])) {
        return $_cache[$name];
    }
    // 获取缓存数据
    if (is_file($filename)) {
        $value = Cml::requireFile($filename);
        $_cache[$name] = $value;
    } else {
        $value = false;
    }
    return $value;
}
Example #5
0
 /**
  * 程序中并输出调试信息
  *
  */
 public static function cmlStop()
 {
     //输出Debug模式的信息
     if (self::$debug) {
         header('Content-Type:text/html; charset=' . Config::get('default_charset'));
         Debug::stop();
     } else {
         $deBugLogData = dump('', 1);
         if (!empty($deBugLogData)) {
             Config::get('dump_use_php_console') ? dumpUsePHPConsole($deBugLogData) : Cml::requireFile(CML_CORE_PATH . DIRECTORY_SEPARATOR . 'ConsoleLog.php', ['deBugLogData' => $deBugLogData]);
         }
         CML_OB_START && ob_end_flush();
     }
     exit;
 }
Example #6
0
 /**
  * 检查脚本运气状态
  *
  * @param bool $showInfo 是否直接显示状态
  *
  * @return array|void
  */
 public static function getStatus($showInfo = false)
 {
     self::initEvn();
     $status = is_file(self::$status) ? Cml::requireFile(self::$status) : [];
     if (!$showInfo) {
         return $status;
     }
     if (self::getPid() > 0) {
         self::message('is running');
         self::message('master pid is ' . self::getPid());
         self::message('worker pid is [' . implode($status['pid'], ',') . ']');
         self::message('task nums (' . count($status['task']) . ') list  [' . json_encode($status['task'], JSON_UNESCAPED_UNICODE) . ']');
     } else {
         echo 'not running' . PHP_EOL;
     }
     return null;
 }
Example #7
0
 /**
  * 从文件载入Config
  *
  * @param string $file
  * @param bool $global 是否从全局加载
  *
  * @return array
  */
 public static function load($file, $global = true)
 {
     if (isset(static::$_content[$file])) {
         return static::$_content[$file];
     } else {
         $file = ($global ? Cml::getApplicationDir('global_config_path') : Cml::getApplicationDir('apps_path') . '/' . Cml::getContainer()->make('cml_route')->getAppName() . '/' . Cml::getApplicationDir('app_config_path_name')) . '/' . ($global ? self::$isLocal . DIRECTORY_SEPARATOR : '') . $file . '.php';
         if (!is_file($file)) {
             throw new ConfigNotFoundException(Lang::get('_NOT_FOUND_', $file));
         }
         static::$_content[$file] = Cml::requireFile($file);
         return static::$_content[$file];
     }
 }
Example #8
0
 /**
  * 输出调试消息
  *
  * @return void
  */
 public function stopAndShowDebugInfo()
 {
     if (Request::isAjax()) {
         if (Config::get('dump_use_php_console')) {
             self::$sql && \Cml\dumpUsePHPConsole(self::$sql, 'sql');
             \Cml\dumpUsePHPConsole(self::$tipInfo, 'tipInfo');
             \Cml\dumpUsePHPConsole(self::$includeFile, 'includeFile');
         } else {
             $deBugLogData = ['tipInfo' => self::$tipInfo];
             self::$sql && ($deBugLogData['sql'] = self::$sql);
             if (!empty($deBugLogData)) {
                 Cml::requireFile(CML_CORE_PATH . DIRECTORY_SEPARATOR . 'ConsoleLog.php', ['deBugLogData' => $deBugLogData]);
             }
         }
     } else {
         View::getEngine('html')->assign('includeLib', Debug::getIncludeLib())->assign('includeFile', Debug::getIncludeFiles())->assign('tipInfo', Debug::getTipInfo())->assign('sqls', Debug::getSqls())->assign('usetime', Debug::getUseTime())->assign('usememory', Debug::getUseMemory());
         Cml::showSystemTemplate(Config::get('debug_page'));
     }
 }
Example #9
0
 /**
  * 载入应用单独的路由
  *
  * @param string $app 应用名称
  */
 public static function loadAppRoute($app = 'web')
 {
     static $loaded = [];
     if (isset($loaded[$app])) {
         return;
     }
     $appRoute = Cml::getApplicationDir('apps_path') . DIRECTORY_SEPARATOR . $app . DIRECTORY_SEPARATOR . Cml::getApplicationDir('app_config_path_name') . DIRECTORY_SEPARATOR . 'route.php';
     if (!is_file($appRoute)) {
         throw new \InvalidArgumentException(Lang::get('_NOT_FOUND_', $app . DIRECTORY_SEPARATOR . Cml::getApplicationDir('app_config_path_name') . DIRECTORY_SEPARATOR . 'route.php'));
     }
     $loaded[$app] = 1;
     Cml::requireFile($appRoute);
 }