Skip to content

Commit

Permalink
change method name and return type
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias De Vos committed Jan 24, 2018
1 parent c36bf10 commit 42856ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/Routing/Router.php
Expand Up @@ -686,9 +686,7 @@ public static function url($url = null, $full = false)
/**
* Finds URL for specified action.
*
* Returns a URL pointing to a combination of controller and action.
*
* If the url doesn't exist returns null
* Returns a bool if the url exists
*
* ### Usage
*
Expand All @@ -700,14 +698,15 @@ public static function url($url = null, $full = false)
* string.
* @param bool $full If true, the full base URL will be prepended to the result.
* Default is false.
* @return string Full translated URL with base path or null if url does not exist
* @return bool
*/
public static function urlOrNull($url = null, $full = false)
public static function routeExists($url = null, $full = false)
{
try {
return static::url($url, $full);
$route = static::url($url, $full);
return true;
} catch (MissingRouteException $e) {
return null;
return false;
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -130,16 +130,16 @@ public function testRouteDefaultParams()
}

/**
* testRouteUrlOrNull method
* testRouteExists method
*
* @return void
*/
public function testRouteUrlOrNull()
public function testRouteExists()
{
Router::connect('/:controller/:action', ['controller' => 'posts']);
$this->assertEquals(Router::urlOrNull(['action' => 'view']), '/view');
$this->assertTrue(Router::routeExists(['action' => 'view']));

$this->assertNull(Router::urlOrNull(['action' => 'view', 'controller' => 'users', 'plugin' => 'test']));
$this->assertFalse(Router::routeExists(['action' => 'view', 'controller' => 'users', 'plugin' => 'test']));
}

/**
Expand Down

0 comments on commit 42856ff

Please sign in to comment.