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

Commit c3c56cf

Browse files
committed
Improved normalize merhtod
1 parent b5f67ef commit c3c56cf

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

AutoRoute/PathProvider/ContentDateTimeProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public function providePath(RouteStack $routeStack)
6363
/**
6464
* {@inheritDoc}
6565
*/
66-
public function normalizePathElements($elements)
66+
public function normalizePathElements($elements, $object)
6767
{
68-
return parent::normalizePathElements(explode('/', $elements));
68+
return parent::normalizePathElements(explode('/', $elements), $object);
6969
}
7070
}

AutoRoute/PathProvider/ContentMethodProvider.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,28 @@ public function providePath(RouteStack $routeStack)
6868
}
6969

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

7473

7574
// @todo: Validate the validator service.
7675
$routeStack->addPathElements($pathElements);
7776
}
7877

79-
protected function normalizePathElements($pathElements, $methodAsString)
78+
/**
79+
* Normalize the given $pathElements variable to an array of path elements,
80+
* accepting either an array or a string.
81+
*
82+
* A string will be converted to an array of elements delimiteed by the
83+
* path separator.
84+
*
85+
* If slugify is enabled, each path element will be slugified.
86+
*
87+
* @param mixed $pathElements Either an array or a string
88+
* @param object $object Used in the case of an exception
89+
*
90+
* @return array
91+
*/
92+
protected function normalizePathElements($pathElements, $object)
8093
{
8194
if (is_string($pathElements) || (is_object($pathElements) && method_exists($pathElements, '__toString'))) {
8295
if (substr($pathElements, 0, 1) == '/') {
@@ -88,8 +101,9 @@ protected function normalizePathElements($pathElements, $methodAsString)
88101

89102
if (!is_array($pathElements)) {
90103
throw new \RuntimeException(sprintf(
91-
'FromObjectMethodProvider wants %s to return an array of route names or a string, got "%s"',
92-
$methodAsString,
104+
'FromObjectMethodProvider wants %s::%s to return an array of route names or a string, got "%s"',
105+
get_class($object),
106+
$this->method,
93107
gettype($pathElements)
94108
));
95109
}

0 commit comments

Comments
 (0)