1 | <?php |
||
2 | |||
3 | namespace Sulao\LRTS\Routing; |
||
4 | |||
5 | use Illuminate\Routing\Matching\UriValidator as LaravelUriValidator; |
||
6 | use Illuminate\Routing\Route; |
||
7 | |||
8 | class RoutingServiceProvider extends \Illuminate\Support\ServiceProvider |
||
9 | { |
||
10 | /** |
||
11 | * Register the application services. |
||
12 | * |
||
13 | * @return void |
||
14 | */ |
||
15 | public function register() |
||
16 | { |
||
17 | $this->app->singleton(Router::class, function ($app) { |
||
18 | return new Router($app['events'], $app); |
||
19 | }); |
||
20 | $this->app->alias(Router::class, 'router'); |
||
21 | |||
22 | $this->app->singleton(UrlGenerator::class, function ($app) { |
||
23 | $routes = $app['router']->getRoutes(); |
||
24 | $app->instance('routes', $routes); |
||
25 | |||
26 | return new UrlGenerator( |
||
27 | $routes, |
||
28 | $app->rebinding('request', function ($app, $request) { |
||
29 | $app['url']->setRequest($request); |
||
30 | }), |
||
31 | $app['config']['app.asset_url'] |
||
0 ignored issues
–
show
|
|||
32 | ); |
||
33 | }); |
||
34 | $this->app->alias(UrlGenerator::class, 'url'); |
||
35 | |||
36 | $this->replaceUriValidator(); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Replace UriValidator |
||
41 | */ |
||
42 | protected function replaceUriValidator() |
||
43 | { |
||
44 | static $replaced; |
||
45 | |||
46 | if ($replaced) { |
||
47 | return; |
||
48 | } |
||
49 | |||
50 | $validators = Route::getValidators(); |
||
51 | foreach ($validators as $key => $validator) { |
||
52 | if ($validator instanceof LaravelUriValidator) { |
||
53 | Route::$validators[$key] = new UriValidator(); |
||
54 | break; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | $replaced = true; |
||
59 | } |
||
60 | } |
||
61 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.