Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Update parameters to accept strings and arrays (cont 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
letrunghieu committed Jul 23, 2016
1 parent b658bec commit e3d972c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
30 changes: 15 additions & 15 deletions src/Active.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ public function checkUri($uris)
/**
* Check if the current URI matches one of specific patterns (using `str_is`)
*
* @param array $patterns
* @param array|string $patterns
*
* @return bool
*/
public function checkUriPattern(array $patterns)
public function checkUriPattern($patterns)
{
if (!$this->request) {
return false;
}

foreach ($patterns as $p) {
foreach ((array)$patterns as $p) {
if (str_is($p, $this->uri)) {
return true;
}
Expand Down Expand Up @@ -193,19 +193,19 @@ public function checkQuery($key, $value)
/**
* Check if the name of the current route matches one of specific values
*
* @param array $routeNames
* @param array|string $routeNames
*
* @return bool
*/
public function checkRoute(array $routeNames)
public function checkRoute($routeNames)
{
if (!$this->route) {
return false;
}

$routeName = $this->route->getName();

if (in_array($routeName, $routeNames)) {
if (in_array($routeName, (array)$routeNames)) {
return true;
}

Expand All @@ -215,19 +215,19 @@ public function checkRoute(array $routeNames)
/**
* Check the current route name with one or some patterns
*
* @param array $patterns
* @param array|string $patterns
*
* @return bool
*/
public function checkRoutePattern(array $patterns)
public function checkRoutePattern($patterns)
{
if (!$this->route) {
return false;
}

$routeName = $this->route->getName();

foreach ($patterns as $p) {
foreach ((array)$patterns as $p) {
if (str_is($p, $routeName)) {
return true;
}
Expand Down Expand Up @@ -256,17 +256,17 @@ public function checkRouteParam($param, $value)
/**
* Return 'active' class if current route action match one of provided action names
*
* @param array $actions
* @param array|string $actions
*
* @return bool
*/
public function checkAction(array $actions)
public function checkAction($actions)
{
if (!$this->action) {
return false;
}

if (in_array($this->action, $actions)) {
if (in_array($this->action, (array)$actions)) {
return true;
}

Expand All @@ -276,17 +276,17 @@ public function checkAction(array $actions)
/**
* Check if the current controller class matches one of specific values
*
* @param array $controllers
* @param array|string $controllers
*
* @return bool
*/
public function checkController(array $controllers)
public function checkController($controllers)
{
if (!$this->controller) {
return false;
}

if (in_array($this->controller, $controllers)) {
if (in_array($this->controller, (array)$controllers)) {
return true;
}

Expand Down
20 changes: 10 additions & 10 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ function if_uri($uris)
/**
* Check if the current URI matches one of specific patterns (using `str_is`)
*
* @param array $patterns
* @param array|string $patterns
*
* @return bool
*/
function if_uri_pattern(array $patterns)
function if_uri_pattern($patterns)
{
return app('active')->checkUriPattern($patterns);
}
Expand Down Expand Up @@ -67,11 +67,11 @@ function if_query($key, $value)
/**
* Check if the name of the current route matches one of specific values
*
* @param array $routeNames
* @param array|string $routeNames
*
* @return bool
*/
function if_route(array $routeNames)
function if_route($routeNames)
{
return app('active')->checkRoute($routeNames);
}
Expand All @@ -81,11 +81,11 @@ function if_route(array $routeNames)
/**
* Check the current route name with one or some patterns
*
* @param array $patterns
* @param array|string $patterns
*
* @return bool
*/
function if_route_pattern(array $patterns)
function if_route_pattern($patterns)
{
return app('active')->checkRoutePattern($patterns);
}
Expand All @@ -110,11 +110,11 @@ function if_route_param($param, $value)
/**
* Return 'active' class if current route action match one of provided action names
*
* @param array $actions
* @param array|string $actions
*
* @return bool
*/
function if_action(array $actions)
function if_action($actions)
{
return app('active')->checkAction($actions);
}
Expand All @@ -124,11 +124,11 @@ function if_action(array $actions)
/**
* Check if the current controller class matches one of specific values
*
* @param array $controllers
* @param array|string $controllers
*
* @return bool
*/
function if_controller(array $controllers)
function if_controller($controllers)
{
return app('active')->checkController($controllers);
}
Expand Down
30 changes: 15 additions & 15 deletions tests/ActiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public function testGetCorrectController(Request $request, $result)

/**
* @param Request $request
* @param array $actions
* @param $actions
* @param $result
*
* @dataProvider provideCheckActionTestData
*/
public function testCheckCurrentAction(Request $request, array $actions, $result)
public function testCheckCurrentAction(Request $request, $actions, $result)
{
app(HttpKernelContract::class)->handle($request);

Expand All @@ -118,12 +118,12 @@ public function testCheckCurrentAction(Request $request, array $actions, $result

/**
* @param Request $request
* @param array $controllers
* @param $controllers
* @param $result
*
* @dataProvider provideCheckControllerTestData
*/
public function testCheckCurrentController(Request $request, array $controllers, $result)
public function testCheckCurrentController(Request $request, $controllers, $result)
{
app(HttpKernelContract::class)->handle($request);

Expand All @@ -134,12 +134,12 @@ public function testCheckCurrentController(Request $request, array $controllers,

/**
* @param Request $request
* @param array $routes
* @param $routes
* @param $result
*
* @dataProvider provideCheckRouteTestData
*/
public function testCheckCurrentRoute(Request $request, array $routes, $result)
public function testCheckCurrentRoute(Request $request, $routes, $result)
{
app(HttpKernelContract::class)->handle($request);

Expand All @@ -150,12 +150,12 @@ public function testCheckCurrentRoute(Request $request, array $routes, $result)

/**
* @param Request $request
* @param array $routes
* @param $routes
* @param $result
*
* @dataProvider provideCheckRoutePatternTestData
*/
public function testCheckCurrentRoutePattern(Request $request, array $routes, $result)
public function testCheckCurrentRoutePattern(Request $request, $routes, $result)
{
app(HttpKernelContract::class)->handle($request);

Expand Down Expand Up @@ -199,12 +199,12 @@ public function testCheckCurrentUri(Request $request, $uri, $result)

/**
* @param Request $request
* @param array $uri
* @param $uri
* @param $result
*
* @dataProvider provideCheckUriPatternTestData
*/
public function testCheckCurrentUriPattern(Request $request, array $uri, $result)
public function testCheckCurrentUriPattern(Request $request, $uri, $result)
{
app(HttpKernelContract::class)->handle($request);

Expand Down Expand Up @@ -288,7 +288,7 @@ public function provideCheckActionTestData()
return [
'match the first inputted actions' => [
Request::create('/foo/bar'),
['\HieuLe\ActiveTest\Http\DumpController@indexMethod'],
'\HieuLe\ActiveTest\Http\DumpController@indexMethod',
true,
],
'match the second inputted actions' => [
Expand All @@ -315,7 +315,7 @@ public function provideCheckControllerTestData()
return [
'match the first inputted controllers' => [
Request::create('/foo/bar'),
['\HieuLe\ActiveTest\Http\DumpController'],
'\HieuLe\ActiveTest\Http\DumpController',
true,
],
'match the second inputted controllers' => [
Expand All @@ -336,7 +336,7 @@ public function provideCheckRouteTestData()
return [
'match the first inputted route names' => [
Request::create('/foo/bar'),
['foo.bar'],
'foo.bar',
true,
],
'match the second inputted route names' => [
Expand Down Expand Up @@ -386,7 +386,7 @@ public function provideCheckRoutePatternTestData()
return [
'match the first inputted route patterns' => [
Request::create('/foo/bar'),
['foo.*'],
'foo.*',
true,
],
'match the second inputted route patterns' => [
Expand Down Expand Up @@ -486,7 +486,7 @@ public function provideCheckUriPatternTestData()
return [
'match the first inputted uri patterns' => [
Request::create('/foo/bar'),
['foo/*'],
'foo/*',
true,
],
'match the second inputted uri patterns' => [
Expand Down

0 comments on commit e3d972c

Please sign in to comment.