Skip to content

Commit b5cf603

Browse files
committed
Revert controller routing.
1 parent 17f7fa8 commit b5cf603

9 files changed

Lines changed: 292 additions & 262 deletions

File tree

src/Illuminate/Routing/Controllers/Controller.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ public function getControllerFilters()
279279
return $this->filters;
280280
}
281281

282+
/**
283+
* Handle calls to missing methods on the controller.
284+
*
285+
* @param array $parameters
286+
* @return mixed
287+
*/
288+
public function missingMethod($parameters)
289+
{
290+
throw new NotFoundHttpException;
291+
}
292+
282293
/**
283294
* Handle calls to missing methods on the controller.
284295
*
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php namespace Illuminate\Routing\Controllers;
2+
3+
use ReflectionClass;
4+
use ReflectionMethod;
5+
6+
class Inspector {
7+
8+
/**
9+
* An array of HTTP verbs.
10+
*
11+
* @var array
12+
*/
13+
protected $verbs = array(
14+
'any', 'get', 'post', 'put',
15+
'delete', 'head', 'options'
16+
);
17+
18+
/**
19+
* Get the routable methods for a controller.
20+
*
21+
* @param string $controller
22+
* @param string $prefix
23+
* @return array
24+
*/
25+
public function getRoutable($controller, $prefix)
26+
{
27+
$routable = array();
28+
29+
$reflection = new ReflectionClass($controller);
30+
31+
// To get the routable methods, we will simply spin through all methods on the
32+
// controller instance checking to see if it belongs to the given class and
33+
// is a publicly routable method. If so, we will add it to this listings.
34+
foreach ($reflection->getMethods() as $method)
35+
{
36+
if ($this->isRoutable($method, $reflection->name))
37+
{
38+
$data = $this->getMethodData($method, $prefix);
39+
40+
// If the routable method is an index method, we will create a special index
41+
// route which is simply the prefix and the verb and does not contain any
42+
// the wildcard place-holders that each "typical" routes would contain.
43+
if ($data['plain'] == $prefix.'/index')
44+
{
45+
$routable[$method->name][] = $data;
46+
47+
$routable[$method->name][] = $this->getIndexData($data, $prefix);
48+
}
49+
50+
// If the routable method is not a special index method, we will just add in
51+
// the data to the returned results straight away. We do not need to make
52+
// any special routes for this scenario but only just add these routes.
53+
else
54+
{
55+
$routable[$method->name][] = $data;
56+
}
57+
}
58+
}
59+
60+
return $routable;
61+
}
62+
63+
/**
64+
* Determine if the given controller method is routable.
65+
*
66+
* @param ReflectionMethod $method
67+
* @param string $controller
68+
* @return bool
69+
*/
70+
public function isRoutable(ReflectionMethod $method, $controller)
71+
{
72+
if ($method->class == 'Illuminate\Routing\Controllers\Controller') return false;
73+
74+
return $method->isPublic() and starts_with($method->name, $this->verbs);
75+
}
76+
77+
/**
78+
* Get the method data for a given method.
79+
*
80+
* @param ReflectionMethod $method
81+
* @return array
82+
*/
83+
public function getMethodData(ReflectionMethod $method, $prefix)
84+
{
85+
$verb = $this->getVerb($name = $method->name);
86+
87+
$uri = $this->addUriWildcards($plain = $this->getPlainUri($name, $prefix));
88+
89+
return compact('verb', 'plain', 'uri');
90+
}
91+
92+
/**
93+
* Get the routable data for an index method.
94+
*
95+
* @param array $data
96+
* @param string $prefix
97+
* @return array
98+
*/
99+
protected function getIndexData($data, $prefix)
100+
{
101+
return array('verb' => $data['verb'], 'plain' => $prefix, 'uri' => $prefix);
102+
}
103+
104+
/**
105+
* Extract the verb from a controller action.
106+
*
107+
* @param string $name
108+
* @return string
109+
*/
110+
public function getVerb($name)
111+
{
112+
return head(explode('_', snake_case($name)));
113+
}
114+
115+
/**
116+
* Determine the URI from the given method name.
117+
*
118+
* @param string $name
119+
* @param string $prefix
120+
* @return string
121+
*/
122+
public function getPlainUri($name, $prefix)
123+
{
124+
return $prefix.'/'.implode('-', array_slice(explode('_', snake_case($name)), 1));
125+
}
126+
127+
/**
128+
* Add wildcards to the given URI.
129+
*
130+
* @param string $uri
131+
* @return string
132+
*/
133+
public function addUriWildcards($uri)
134+
{
135+
return $uri.'/{v1?}/{v2?}/{v3?}/{v4?}/{v5?}';
136+
}
137+
138+
}

src/Illuminate/Routing/Route.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,6 @@ public function getParameterKeys()
306306
return $this->compile()->getVariables();
307307
}
308308

309-
public function removeParameter($key)
310-
{
311-
$this->getParameters();
312-
313-
unset($this->parsedParameters[$key]);
314-
}
315-
316309
/**
317310
* Force a given parameter to match a regular expression.
318311
*

src/Illuminate/Routing/RouteCollection.php

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)