protected function loadFastRouteRoutes($path)
{
$routeParser = new \FastRoute\RouteParser\Std();
$dataGenerator = new \FastRoute\DataGenerator\GroupCountBased();
$routeCollector = new \FastRoute\RouteCollector($routeParser, $dataGenerator);
if (!is_readable($path)) {
throw new \InvalidArgumentException('Invalid fast route routes path found: ' . $path);
}
// The included file must return the laravel router
$getRouteCollector = function () use($routeCollector, $path) {
$r = $routeCollector;
include $path;
return $r;
};
$routeCollector = $getRouteCollector();
if (!$routeCollector instanceof \FastRoute\RouteCollector) {
throw new \Exception('Invalid return value from ' . pathinfo($path, PATHINFO_FILENAME) . ' expected instance of RouteCollector');
}
$dispatcher = new \FastRoute\Dispatcher\GroupCountBased($routeCollector->getData());
$router = new \PPI\FastRoute\Wrapper\FastRouteWrapper($dispatcher);
$router->setModuleName($this->getName());
return $router;
}