Lumen выбирает определенный файл в качестве маршрутизатора по умолчанию на основе запроса - PullRequest
0 голосов
/ 04 ноября 2018

В моем приложении все работает нормально, но я хочу выбрать файл маршрутизатора по умолчанию на основе объекта запроса Illuminate \ Http \ Request $.

Я сделал для этого 2 файла в папке маршрутов:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$colors = ["Blue", "Red", "Orange", "Black", "White", "Golden",
    "Green", "Purple", "Yellow", "cyan",
    "Gray", "Pink", "Brown", "Sky Blue", "Silver"];
$router->get('/', ["as" => "home", function (\Illuminate\Http\Request $request) use ($colors) {
    if ($request->getHttpHost() === 'color1.tk') {
        $limit = count($colors) - 1;
        return view('index')->with("color", $colors[rand(0, $limit)]);

    }else{
        return "This action is not allowed";
    }
}]);

$router->get('/{color}', function ($color) use ($colors) {
    dd(array_search(strtolower($color), array_map("strtolower", $colors)));
});

web.php:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$colors = ["Blue", "Red", "Orange", "Black", "White", "Golden",
    "Green", "Purple", "Yellow", "cyan",
    "Gray", "Pink", "Brown", "Sky Blue", "Silver"];
$router->get('/', ["as" => "home", function (\Illuminate\Http\Request $request) use ($colors) {
    if ($request->getHttpHost() === 'localhost') {
 return " yayy this is working on localhost "    
}
}]);

это color1.php:

$app->router->group([
    'namespace' => 'App\Http\Controllers',
], function ($router) {
    require __DIR__.'/../routes/web.php';
});
$app->router->group([
    'namespace' => 'App\Http\Controllers',
], function ($router) {
    require __DIR__.'/../routes/color1.php';
});
...