|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Router; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider; |
|
6
|
|
|
use Nip\Router\Generator\UrlGenerator; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class MailServiceProvider |
|
10
|
|
|
* @package Nip\Mail |
|
11
|
|
|
*/ |
|
12
|
|
|
class RouterServiceProvider extends AbstractSignatureServiceProvider |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @inheritdoc |
|
17
|
|
|
*/ |
|
18
|
|
|
public function register() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->registerRouter(); |
|
21
|
|
|
|
|
22
|
|
|
$this->registerUrlGenerator(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
protected function registerRouter() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->getContainer()->share('router', self::newRouter()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return Router |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function newRouter() |
|
34
|
|
|
{ |
|
35
|
|
|
return new Router(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Register the URL generator service. |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function registerUrlGenerator() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->getContainer()->share('url', function () { |
|
46
|
|
|
$routes = app('router')->getRoutes(); |
|
47
|
|
|
|
|
48
|
|
|
// The URL generator needs the route collection that exists on the router. |
|
49
|
|
|
// Keep in mind this is an object, so we're passing by references here |
|
50
|
|
|
// and all the registered routes will be available to the generator. |
|
51
|
|
|
app()->share('routes', $routes); |
|
52
|
|
|
|
|
53
|
|
|
$url = new UrlGenerator( |
|
54
|
|
|
$routes, |
|
55
|
|
|
request() |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
// If the route collection is "rebound", for example, when the routes stay |
|
59
|
|
|
// cached for the application, we will need to rebind the routes on the |
|
60
|
|
|
// URL generator instance so it has the latest version of the routes. |
|
|
|
|
|
|
61
|
|
|
// $app->rebinding('routes', function ($app, $routes) { |
|
62
|
|
|
// $app['url']->setRoutes($routes); |
|
63
|
|
|
// }); |
|
64
|
|
|
return $url; |
|
65
|
|
|
}); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @inheritdoc |
|
70
|
|
|
*/ |
|
71
|
|
|
public function provides() |
|
72
|
|
|
{ |
|
73
|
|
|
return ['router', 'url']; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.