thinkphp/library/think/console/command/optimize/Route.php

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\console\command\optimize;

use think\console\Command;
use think\console\Input;
use think\console\Output;

class Route extends Command
{
    /** @var  Output */
    protected $output;

    protected function configure()
    {
        $this->setName('optimize:route')
            ->setDescription('Build route cache.');
    }

    protected function execute(Input $input, Output $output)
    {

        if (!is_dir(RUNTIME_PATH)) {
            @mkdir(RUNTIME_PATH, 0755, true);
        }

        file_put_contents(RUNTIME_PATH . 'route.php', $this->buildRouteCache());
        $output->writeln('<info>Succeed!</info>');
    }

    protected function buildRouteCache()
    {
        $files = \think\Config::get('route_config_file');
        foreach ($files as $file) {
            if (is_file(CONF_PATH . $file . CONF_EXT)) {
                $config = include CONF_PATH . $file . CONF_EXT;
                if (is_array($config)) {
                    \think\Route::import($config);
                }
            }
        }
        $rules = \think\Route::rules(true);
        array_walk_recursive($rules, [$this, 'buildClosure']);
        $content = '<?php ' . PHP_EOL . 'return ';
        $content .= var_export($rules, true) . ';';
        $content = str_replace(['\'[__start__', '__end__]\''], '', stripcslashes($content));
        return $content;
    }

    protected function buildClosure(&$value)
    {
        if ($value instanceof \Closure) {
后面还有 15 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。