Passed
Push — main ( 2e91a7...db810f )
by Dimitri
03:15
created

BaseMiddleware::init()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
rs 10
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Middlewares;
13
14
use BlitzPHP\Utilities\String\Text;
15
use Psr\Http\Server\MiddlewareInterface;
16
17
abstract class BaseMiddleware implements MiddlewareInterface
18
{
19
    /**
20
     * Liste des arguments envoyes au middleware
21
     */
22
    protected array $arguments = [];
23
24
    /**
25
     * Chemin url de la requette actuelle
26
     */
27
    protected string $path;
28
29
    public function init(array $arguments = []): self
30
    {
31
        $this->path = $arguments['path'] ?: '/';
32
        unset($arguments['path']);
33
34
        $this->arguments = $arguments;
35
36
        foreach ($this->arguments as $argument => $value) {
37
            $method = Text::camel('set_' . $argument);
38
            if (method_exists($this, $method)) {
39
                call_user_func([$this, $method], $value);
40
            }           
41
        }
42
43
        return $this;
44
    }
45
}
46