1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loadsman\LaravelPlugin\Repositories; |
4
|
|
|
|
5
|
|
|
use Loadsman\LaravelPlugin\Collections\RouteCollection; |
6
|
|
|
use Loadsman\LaravelPlugin\Contracts\RouteRepositoryInterface; |
7
|
|
|
use Loadsman\LaravelPlugin\Entities\RouteInfo; |
8
|
|
|
use Dingo\Api\Routing\Router; |
9
|
|
|
use Illuminate\Contracts\Config\Repository as Config; |
10
|
|
|
use Illuminate\Contracts\Foundation\Application; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class RouteDingoRepository |
14
|
|
|
* |
15
|
|
|
* @package \Loadsman\Laravel\Repositories |
16
|
|
|
*/ |
17
|
|
|
class RouteDingoRepository implements RouteRepositoryInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @type \Loadsman\LaravelPlugin\Collections\RouteCollection |
21
|
|
|
*/ |
22
|
|
|
protected $routes; |
23
|
|
|
|
24
|
|
|
public function __construct(RouteCollection $collection, Router $router, Config $config) |
25
|
|
|
{ |
26
|
|
|
$this->routes = $collection; |
27
|
|
|
$standardsTree = $config['api.standardsTree']; |
28
|
|
|
$subtype = $config['api.subtype']; |
29
|
|
|
$defaultFormat = $config['api.defaultFormat']; |
30
|
|
|
|
31
|
|
|
foreach ($router->getAdapterRoutes() as $versionName => $versionGroup) { |
32
|
|
|
foreach ($versionGroup as $route) { |
33
|
|
|
$routeInfo = (new RouteInfo($route, [ |
34
|
|
|
'router' => 'Dingo', |
35
|
|
|
'version' => $versionName, |
36
|
|
|
'headers' => [ |
37
|
|
|
[ |
38
|
|
|
'key' => 'Accept', |
39
|
|
|
'value' => "application/{$standardsTree}.{$subtype}.{$versionName}+{$defaultFormat}" |
40
|
|
|
] |
41
|
|
|
] |
42
|
|
|
]))->toArray(); |
43
|
|
|
$this->routes->push($routeInfo); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param array $match |
50
|
|
|
* @param array $except |
51
|
|
|
* |
52
|
|
|
* @return \Loadsman\LaravelPlugin\Collections\RouteCollection |
53
|
|
|
*/ |
54
|
|
|
public function get($match = [], $except = []) |
55
|
|
|
{ |
56
|
|
|
return $this->routes->filterMatch($match) |
57
|
|
|
->filterExcept($except) |
58
|
|
|
->values(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|