Completed
Push — master ( 153345...f1eae3 )
by Iman
09:16
created

RouteAuthorizer::authorizeUrls()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Illuminate\Routing\Events\RouteMatched;
6
use Illuminate\Support\Facades\Route;
7
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager;
8
9
class RouteAuthorizer
10
{
11 87
    public function authorizeMatchedRoutes()
12
    {
13
        Route::matched(function (RouteMatched $eventObj) {
14 44
            $route = $eventObj->route;
15 44
            $this->setGuardFor($eventObj->request->method().$route->uri);
16 44
            $this->setGuardFor($route->getName());
17 44
            $this->setGuardFor($route->getActionName());
18
        });
19
    }
20 28
21 26
    /**
22 87
     * @param $url
23 87
     */
24
    private function setGuardFor($url)
25
    {
26
        $closures = app(RouterEventManager::class)->resolveCallbacks($url);
27
        foreach ($closures as $cb) {
28
            $cb();
29
        }
30 26
    }
31
}
32