Issues (105)

src/RouterAwareTrait.php (1 issue)

1
<?php
2
3
namespace Nip\Router;
4
5
use Nip\Request;
6
7
/**
8
 * Class ConfigAwareTrait
9
 * @package Nip\Router
10
 */
11
trait RouterAwareTrait
12
{
13
    /**
14
     * @var Router|null
15
     */
16
    protected $router = null;
17
18
    /**
19
     * @param bool|Request $request
20
     * @return array
21
     */
22
    public function route($request = false)
23
    {
24
        $request = $request ? $request : $this->getRequest();
25
26
        $router = $this->getRouter();
27
        $router->setContext((new RequestContext())->fromRequest($this->getRequest()));
28
29
        $params = $router->route($request);
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Router\Router::route() has been deprecated: Use matchRequest($request) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

29
        $params = /** @scrutinizer ignore-deprecated */ $router->route($request);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
30
31
        return $params;
32
    }
33
34
    /**
35
     * @return Router
36
     */
37
    public function getRouter()
38
    {
39
        if (!$this->router) {
40
            $this->initRouter();
41
        }
42
43
        return $this->router;
44
    }
45
46
    /**
47
     * @param Router $router
48
     * @return $this
49
     */
50
    public function setRouter($router = false)
51
    {
52
        $this->router = $router;
53
54
        return $this;
55
    }
56
57
    protected function initRouter()
58
    {
59
        $this->setRouter($this->newRouter());
60
    }
61
62
    /**
63
     * @return Router
64
     */
65
    protected function newRouter()
66
    {
67
        return app()->get('router');
68
    }
69
}
70