Completed
Pull Request — master (#178)
by Fèvre
03:02
created

Routes::load()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 8.8571
c 1
b 0
f 0
cc 5
eloc 9
nc 4
nop 1
1
<?php
2
namespace App\Routing;
3
4
use App\Routing\Exception\MissingFileException;
5
6
class Routes
7
{
8
    /**
9
     * Load one or more routes files.
10
     *
11
     * ### Usage
12
     *
13
     * Loading one file:
14
     *
15
     * ```
16
     * Routes::load('base');
17
     * ```
18
     *
19
     * Loading many files at once:
20
     *
21
     * ```
22
     * Routes::load(['base', 'blog', 'admin']);
23
     * ```
24
     *
25
     * @param string|array $files The file(s) to load.
26
     *
27
     * @return void
28
     */
29
    public static function load($files = [])
30
    {
31
        foreach ((array)$files as $file) {
32
            if (empty($file) || is_null($file)) {
33
                continue;
34
            }
35
36
            $path = ROUTES . strtolower($file) . '.php';
37
38
            if (!file_exists($path)) {
39
                $msg = sprintf('The Route file "%s" could not be found.', $path);
40
41
                throw new MissingFileException($msg);
42
            }
43
44
            include $path;
45
        }
46
    }
47
}
48