Skip to content

Commit

Permalink
Merge pull request #12222 from cakephp/entity-docs
Browse files Browse the repository at this point in the history
Fix EntityTrait examples and route parsing with brace style routes.
  • Loading branch information
markstory committed Jun 14, 2018
2 parents 79c2a62 + 9d2b24e commit 34e90fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Datasource/EntityTrait.php
Expand Up @@ -934,7 +934,7 @@ public function getError($field)
*
* ```
* // Sets the error messages for multiple fields at once
* $entity->errors(['salary' => ['message'], 'name' => ['another message']);
* $entity->setErrors(['salary' => ['message'], 'name' => ['another message']);
* ```
*
* @param array $fields The array of errors to set.
Expand All @@ -960,7 +960,7 @@ public function setErrors(array $fields, $overwrite = false)
*
* ```
* // Sets the error messages for a single field
* $entity->errors('salary', ['must be numeric', 'must be a positive number']);
* $entity->setError('salary', ['must be numeric', 'must be a positive number']);
* ```
*
* @param string $field The field to get errors for, or the array of errors to set.
Expand Down
4 changes: 4 additions & 0 deletions src/Routing/Route/Route.php
Expand Up @@ -866,6 +866,10 @@ public function staticPath()
if ($routeKey !== false) {
return substr($this->template, 0, $routeKey);
}
$routeKey = strpos($this->template, '{');
if ($routeKey !== false && strpos($this->template, '}') !== false) {
return substr($this->template, 0, $routeKey);
}
$star = strpos($this->template, '*');
if ($star !== false) {
$path = rtrim(substr($this->template, 0, $star), '/');
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -1728,6 +1728,26 @@ public function testStaticPath()
$route = new Route('/:controller/:action/*');
$this->assertEquals('/', $route->staticPath());

$route = new Route('/api/{/:action/*');
$this->assertEquals('/api/{/', $route->staticPath());

$route = new Route('/books/reviews', ['controller' => 'Reviews', 'action' => 'index']);
$this->assertEquals('/books/reviews', $route->staticPath());
}

/**
* Test getting the static path for a route.
*
* @return void
*/
public function testStaticPathBrace()
{
$route = new Route('/pages/{id}/*', ['controller' => 'Pages', 'action' => 'display']);
$this->assertEquals('/pages/', $route->staticPath());

$route = new Route('/{controller}/{action}/*');
$this->assertEquals('/', $route->staticPath());

$route = new Route('/books/reviews', ['controller' => 'Reviews', 'action' => 'index']);
$this->assertEquals('/books/reviews', $route->staticPath());
}
Expand Down

0 comments on commit 34e90fa

Please sign in to comment.