Skip to content

Commit

Permalink
Add deprecation warnings to Routing features.
Browse files Browse the repository at this point in the history
Make documented deprecations into runtime errors.
  • Loading branch information
markstory committed Nov 1, 2017
1 parent 5661606 commit 2a43409
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Routing/RequestActionTrait.php
Expand Up @@ -101,6 +101,10 @@ trait RequestActionTrait
*/
public function requestAction($url, array $extra = [])
{
deprecationWarning(
'RequestActionTrait::requestAction() is deprecated. ' .
'You should refactor to use View Cells or Components instead.'
);
if (empty($url)) {
return false;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Routing/Route/Route.php
Expand Up @@ -120,8 +120,8 @@ class Route
public function __construct($template, $defaults = [], array $options = [])
{
$this->template = $template;
// @deprecated The `[method]` format should be removed in 4.0.0
if (isset($defaults['[method]'])) {
deprecationWarning('The `[method]` option is deprecated. Use `_method` instead.');
$defaults['_method'] = $defaults['[method]'];
unset($defaults['[method]']);
}
Expand All @@ -141,6 +141,10 @@ public function __construct($template, $defaults = [], array $options = [])
*/
public function extensions($extensions = null)
{
deprecationWarning(
'Route::extensions() is deprecated. ' .
'Use Route::setExtensions()/getExtensions() instead.'
);
if ($extensions === null) {
return $this->_extensions;
}
Expand Down Expand Up @@ -736,6 +740,7 @@ protected function _matchMethod($url)
}
// @deprecated The `[method]` support should be removed in 4.0.0
if (isset($url['[method]'])) {
deprecationWarning('The `[method]` key is deprecated. Use `_method` instead.');
$url['_method'] = $url['[method]'];
}
if (empty($url['_method'])) {
Expand Down
8 changes: 8 additions & 0 deletions src/Routing/RouteBuilder.php
Expand Up @@ -152,6 +152,10 @@ public function __construct(RouteCollection $collection, $path, array $params =
*/
public function routeClass($routeClass = null)
{
deprecationWarning(
'RouteBuilder::routeClass() is deprecated. ' .
'Use RouteBuilder::setRouteClass()/getRouteClass() instead.'
);
if ($routeClass === null) {
return $this->getRouteClass();
}
Expand Down Expand Up @@ -193,6 +197,10 @@ public function getRouteClass()
*/
public function extensions($extensions = null)
{
deprecationWarning(
'RouteBuilder::extensions() is deprecated. ' .
'Use RouteBuilder::setExtensions()/getExtensions() instead.'
);
if ($extensions === null) {
return $this->getExtensions();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Routing/RouteCollection.php
Expand Up @@ -373,6 +373,10 @@ public function named()
*/
public function extensions($extensions = null, $merge = true)
{
deprecationWarning(
'RouteCollection::extensions() is deprecated. ' .
'Use RouteCollection::setExtensions()/getExtensions() instead.'
);
if ($extensions !== null) {
$this->setExtensions((array)$extensions, $merge);
}
Expand Down
16 changes: 16 additions & 0 deletions src/Routing/Router.php
Expand Up @@ -225,6 +225,10 @@ public static function connect($route, $defaults = [], $options = [])
*/
public static function redirect($route, $url, $options = [])
{
deprecationWarning(
'Router::redirect() is deprecated. ' .
'Use Router::scope() and RouteBuilder::redirect() instead.'
);
if (is_string($url)) {
$url = ['redirect' => $url];
}
Expand Down Expand Up @@ -291,6 +295,10 @@ public static function redirect($route, $url, $options = [])
*/
public static function mapResources($controller, $options = [])
{
deprecationWarning(
'Router::mapResources() is deprecated. ' .
'Use Router::scope() and RouteBuilder::resources() instead.'
);
foreach ((array)$controller as $name) {
list($plugin, $name) = pluginSplit($name);

Expand Down Expand Up @@ -344,6 +352,10 @@ public static function mapResources($controller, $options = [])
*/
public static function parse($url, $method = '')
{
deprecationWarning(
'Router::parse() is deprecated. ' .
'Use Router::parseRequest() instead. This will require adopting the Http\Server library.'
);
if (!static::$initialized) {
static::_loadRoutes();
}
Expand Down Expand Up @@ -872,6 +884,10 @@ public static function extensions($extensions = null, $merge = true)
*/
public static function parseNamedParams(ServerRequest $request, array $options = [])
{
deprecationWarning(
'Router::parseNamedParams() is deprecated. ' .
'2.x backwards compatible named parameter support will be removed in 4.0'
);
$options += ['separator' => ':'];
if (empty($request->params['pass'])) {
$request->params['named'] = [];
Expand Down

0 comments on commit 2a43409

Please sign in to comment.