Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 52561a2

Browse files
wouterjdantleech
authored andcommitted
Improved and fixed normalizePathElements
1 parent 394908e commit 52561a2

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

AutoRoute/PathProvider/ContentDateTimeProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function providePath(RouteStack $routeStack)
5454
throw new \RuntimeException(sprintf('Method %s:%s must return an instance of DateTime.'));
5555
}
5656

57-
$dateString = $date->format($this->dateFormat);
58-
$pathElements = $this->normalizePathElements($dateString);
57+
$string = $date->format($this->dateFormat);
58+
$pathElements = $this->normalizePathElements($string, $object);
5959

6060
$routeStack->addPathElements($pathElements);
6161
}

AutoRoute/PathProvider/ContentMethodProvider.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ public function providePath(RouteStack $routeStack)
6969

7070
$pathElements = $object->$method();
7171

72-
$pathElements = $this->normalizePathElements($pathElements);
72+
$pathElements = $this->normalizePathElements($pathElements, get_class($object).'::'.$method);
7373

7474

7575
// @todo: Validate the validator service.
7676
$routeStack->addPathElements($pathElements);
7777
}
7878

79-
protected function normalizePathElements($pathElements)
79+
protected function normalizePathElements($pathElements, $methodAsString)
8080
{
81-
if (is_string($pathElements)) {
81+
if (is_string($pathElements) || (is_object($pathElements) && method_exists($pathElements, '__toString'))) {
8282
if (substr($pathElements, 0, 1) == '/') {
8383
throw new \RuntimeException('Path must not be absolute.');
8484
}
@@ -88,9 +88,8 @@ protected function normalizePathElements($pathElements)
8888

8989
if (!is_array($pathElements)) {
9090
throw new \RuntimeException(sprintf(
91-
'FromObjectMethodProvider wants %s:%s to return an array of route names.. got "%s"',
92-
get_class($object),
93-
$method,
91+
'FromObjectMethodProvider wants %s to return an array of route names or a string, got "%s"',
92+
$methodAsString,
9493
gettype($pathElements)
9594
));
9695
}

0 commit comments

Comments
 (0)