PHP code example of qklin / laravel-auto-router

1. Go to this page and download the library: Download qklin/laravel-auto-router library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

qklin / laravel-auto-router example snippets



// 文件位置:app/config/route.php
// 本文件可配置可不配置,根据需求配置
return [
    "middleware" => [  //中间件,目前只支持
        "controllers" => [ // 路由控制器路径 => 中间件
            "h/module/ctl/action" => ["token", "validate"],
        ],
        "actions"     => [ // 控制器方法 => 中间件
        ]
    ]
];

/**
 * 加载配置文件
 * @param $name
 */
public function configure($name)
{
    if (isset($this->loadedConfigurations[$name])) {
        return;
    }

    $this->loadedConfigurations[$name] = true;

    $path = $this->getConfigurationPath($name);

    if ($path && is_file($path)) {
        $this->make('config')->set($name, . '/../config/')) {
            return $path;
        }
    } else {
        $appConfigPath = $this->basePath('config') . '/' . $name . '.php';

        if (file_exists($appConfigPath)) {
            return $appConfigPath;
        } else if (file_exists($path = __DIR__ . '/../config/' . $name . '.php')) {
            return $path;
        }
    }
}