How to insert a file into an array

2

I'm having a hard time and I could not solve it. I have a configuration file in this file I have an array and several arrays inside it and one of those is my array of routes. What I need to do is to include a file inside that array of routes because I have a lot of routes and I want to sort by files for easier maintenance later. well, what I have is this:

routes.php

return array(
    'dependencias' => [
        // array de dependências
    ],

    'routes' => [
        // array de rotas que eu quero inserir
    ]

);

rotas.php

[
'name' => 'home',
'path' => '/',
'middleware' => Site\Action\HomePageAction::class,
'allowed_methods' => ['GET'],
],

What I need is to include the rotas.php file inside the routes array. Has anyone done this or do you know how to do it?

Thankful

    
asked by anonymous 08.09.2016 / 19:23

1 answer

0

Usually includes the file in the array key of the configuration file.

routes.php

return [
    'routes' => [
        'minhasRotas' => require "rotas.php",
    ]
];

Defines that your file will return a array .

rotas.php

return [
    [
        'name' => 'home',
        'path' => '/',
        'middleware' => Site\Action\HomePageAction::class,
        'allowed_methods' => ['GET'],
    ],
    [
        'name' => 'login',
        'path' => '/login',
        'middleware' => Site\Action\LoginAction::class,
        'allowed_methods' => ['GET'],
    ],
    [...],
    [...],
];
    
08.09.2016 / 19:28