1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TomHart\Restful\Routing; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\ResourceRegistrar; |
6
|
|
|
use Illuminate\Routing\Route; |
7
|
|
|
use Illuminate\Routing\Router; |
8
|
|
|
|
9
|
|
|
class RestfulResourceRegistrar extends ResourceRegistrar |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
public function __construct(Router $router) |
14
|
|
|
{ |
15
|
|
|
parent::__construct($router); |
16
|
|
|
|
17
|
|
|
$this->resourceDefaults[] = 'showExtra'; |
18
|
|
|
$this->resourceDefaults[] = 'options'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Add the show-extra method for a resourceful route. |
23
|
|
|
* |
24
|
|
|
* @param string $name |
25
|
|
|
* @param string $base |
26
|
|
|
* @param string $controller |
27
|
|
|
* @param mixed[] $options |
28
|
|
|
* @return Route |
29
|
|
|
*/ |
30
|
|
|
protected function addResourceShowExtra($name, $base, $controller, $options) |
31
|
|
|
{ |
32
|
|
|
$uri = $this->getResourceUri($name) . '/{' . $base . '}/{extra}'; |
33
|
|
|
|
34
|
|
|
$action = $this->getResourceAction($name, $controller, 'show', $options); |
35
|
|
|
|
36
|
|
|
$action['as'] .= '.extra'; |
37
|
|
|
|
38
|
|
|
return $this->router->get($uri, $action)->where('extra', '.*'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Add the options method for a resourceful route. |
43
|
|
|
* |
44
|
|
|
* @param string $name |
45
|
|
|
* @param string $base |
46
|
|
|
* @param string $controller |
47
|
|
|
* @param mixed[] $options |
48
|
|
|
* @return Route |
49
|
|
|
*/ |
50
|
|
|
protected function addResourceOptions($name, $base, $controller, $options) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$uri = $this->getResourceUri($name); |
53
|
|
|
|
54
|
|
|
$action = $this->getResourceAction($name, $controller, 'options', $options); |
55
|
|
|
|
56
|
|
|
return $this->router->options($uri, $action); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.