Hi Back from vacation, working on some nice routing for a report tool. I got a Query DTO object, that is passed as a argument. It has a property named “routingParameters” that I’m using in my Routes.yaml like this
I figured that out, and started a exciting journey into the RoutePartHandler thing - and i came out alive
<?php
namespace Vendor\App\Routing;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Routing\DynamicRoutePart;
use Vendor\App\Domain\Dto\Query;
use Vendor\App\Domain\Model\Domain;
/**
* Reporting Route Part
*
* @api
*/
class ReportRoutePartHandler extends DynamicRoutePart
{
const REPORT_PATH_MATCHER = '/(?P<domains>[^\/]*)?\/?(?P<dateRangeStart>\d\d-\d\d-\d{4})?\/?(?P<dateRangeEnd>\d\d-\d\d-\d{4})?\/?(?:(?P<sortingKey>.*):(?P<sortingValue>.*))?/';
/**
* Extracts the node path from the request path.
*
* @param string $requestPath The request path to be matched
* @return string value to match, or an empty string if $requestPath is empty or split string was not found
*/
protected function findValueToMatch($requestPath)
{
if ($this->splitString !== '') {
$splitStringPosition = strpos($requestPath, $this->splitString);
if ($splitStringPosition !== false) {
return substr($requestPath, 0, $splitStringPosition);
}
}
return $requestPath;
}
/**
* Checks whether the current URI section matches the configured RegEx pattern.
*
* @param string $requestPath value to match, the string to be checked
* @return boolean TRUE if value could be matched successfully, otherwise FALSE.
*/
protected function matchValue($requestPath) {
preg_match(self::REPORT_PATH_MATCHER, $requestPath, $matches);
if (!isset($matches['domains']) || strlen($matches['domains']) === 0) {
return false;
}
//$query = new Query();
$query = [];
$query['domains'] = explode(',', $matches['domains']);
if (isset($matches['dateRangeStart'])) {
$query['dateRangeStart'] = $matches['dateRangeStart']; #\DateTime::createFromFormat('d-m-Y', $matches['dateRangeStart']);
}
if (isset($matches['dateRangeEnd'])) {
$query['dateRangeEnd'] = $matches['dateRangeEnd']; #\DateTime::createFromFormat('d-m-Y', $matches['dateRangeEnd']);
}
$this->value = $query;
return TRUE;
}
/**
* Checks whether the route part matches the configured RegEx pattern.
*
* @param Query $value
* @return boolean TRUE if value could be resolved successfully, otherwise FALSE.
*/
protected function resolveValue($value) {
if (!($value instanceof Query)) {
return FALSE;
}
$this->value = implode('/', $value->getRoutingParameters());
return TRUE;
}
}
This property is filled with Domain objects made from the comma-seperated-list since there is a CollectionTypeConverter that can take a comma-separated (made in my route part handler) list and turn it into a Collection