Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Lloople/framework into Ll…
Browse files Browse the repository at this point in the history
…oople-master
  • Loading branch information
taylorotwell committed May 24, 2017
2 parents 199e711 + 0d66555 commit 02abb3a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-5.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,18 @@
- Added a `validate()` macro onto `Request` ([#19063](https://github.com/laravel/framework/pull/19063))
- Added `FormRequest::validated()` method ([#19112](https://github.com/laravel/framework/pull/19112))
- ⚠️ Made `request()` helper and `Request::__get()` consistent ([a6ff272](https://github.com/laravel/framework/commit/a6ff272c54677a9f52718292fc0938ffb1871832))
- Made `request()->routeIs()` work like `request()->fullUrlIs()` ([#19267](https://github.com/laravel/framework/pull/19267))

### Routing
- Support fluent resource options ([#18767](https://github.com/laravel/framework/pull/18767), [bb02fb2](https://github.com/laravel/framework/commit/bb02fb27387a8aeb2a47da1fe5ff2e086920b744))
- Support multiple values in `Router::has()` ([#18758](https://github.com/laravel/framework/pull/18758))
- ⚠️ Bind empty optional route parameter to `null` instead of empty model instance ([#17521](https://github.com/laravel/framework/pull/17521))
- ⚠️ Removed `Controller::missingMethod()` ([bf5d221](https://github.com/laravel/framework/commit/bf5d221037d9857a74020f2623839e282035a420))
- Route `named()` accept patterns ([#19267](https://github.com/laravel/framework/pull/19267))
- Router `is()` and `currentRouteNamed()` accepts patterns ([#19267](https://github.com/laravel/framework/pull/19267))
- Added `domain()` setter/getter to `Route` ([#19245](https://github.com/laravel/framework/pull/19245), [bba04a1](https://github.com/laravel/framework/commit/bba04a1598c44a892e918c4f308407b0d297f217))


### Responses
- ⚠️ Ensure `Arrayable` and `Jsonable` return a `JsonResponse` ([#17875](https://github.com/laravel/framework/pull/17875))
- ⚠️ Ensure `Arrayable` objects are also morphed by `Response` ([#17868](https://github.com/laravel/framework/pull/17868))
Expand Down
7 changes: 3 additions & 4 deletions src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,13 @@ public function is()
}

/**
* Check if the route name matches the given string.
* Determine if the route name matches a pattern.
*
* @param string $name
* @return bool
*/
public function routeIs($name)
public function routeIs()
{
return $this->route() && $this->route()->named($name);
return ($route = $this->route()) && call_user_func_array([$route, 'named'], func_get_args());
}

/**
Expand Down
17 changes: 13 additions & 4 deletions src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,23 @@ public function name($name)
}

/**
* Determine whether the route's name matches the given name.
* Determine whether the route's name matches a pattern.
*
* @param string $name
* @return bool
*/
public function named($name)
public function named()
{
return $this->getName() === $name;
if (is_null($routeName = $this->getName())) {
return false;
}

foreach (func_get_args() as $pattern) {
if (Str::is($pattern, $routeName)) {
return true;
}
}

return false;
}

/**
Expand Down
15 changes: 4 additions & 11 deletions src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -945,24 +945,17 @@ public function currentRouteName()
*/
public function is()
{
foreach (func_get_args() as $pattern) {
if (Str::is($pattern, $this->currentRouteName())) {
return true;
}
}

return false;
return call_user_func_array([$this, 'currentRouteNamed'], func_get_args());
}

/**
* Determine if the current route matches a given name.
* Determine if the current route matches a pattern.
*
* @param string $name
* @return bool
*/
public function currentRouteNamed($name)
public function currentRouteNamed()
{
return $this->current() ? $this->current()->named($name) : false;
return ($route = $this->current()) && call_user_func_array([$route, 'named'], func_get_args());
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public function testRouteIsMethod()
{
$request = Request::create('/foo/bar', 'GET');

$this->assertFalse($request->routeIs('foo.bar'));

$request->setRouteResolver(function () use ($request) {
$route = new Route('GET', '/foo/bar', ['as' => 'foo.bar']);
$route->bind($request);
Expand All @@ -169,6 +171,7 @@ public function testRouteIsMethod()
});

$this->assertTrue($request->routeIs('foo.bar'));
$this->assertTrue($request->routeIs('foo*', '*bar'));
$this->assertFalse($request->routeIs('foo.foo'));
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public function testBasicDispatchingOfRoutes()
$this->assertEquals('fred25', $router->dispatch(Request::create('fred', 'GET'))->getContent());
$this->assertEquals('fred30', $router->dispatch(Request::create('fred/30', 'GET'))->getContent());
$this->assertTrue($router->currentRouteNamed('foo'));
$this->assertTrue($router->currentRouteNamed('fo*'));
$this->assertTrue($router->is('foo'));
$this->assertTrue($router->is('foo', 'bar'));
$this->assertFalse($router->is('bar'));

$router = $this->getRouter();
Expand Down

0 comments on commit 02abb3a

Please sign in to comment.