public function __construct(Request $request, array $options) { parent::__construct($request, $options); $this->methods = new Map(); // create routes from db $apis = ApiQuery::create()->joinAction()->useActionQuery()->joinModule()->endUse()->find(); $routes = new RouteCollection(); /* @var $api Api */ foreach ($apis as $api) { $action = $api->getAction(); $module = $action->getModule(); $path = str_replace('//', '/', '/' . $api->getRoute()); $required = $api->getRequiredParams(); $required = is_array($required) ? explode(',', $required) : []; $name = $module->getName() . ':' . $action->getName() . '@' . $api->getMethod(); $route = new Route($path, ['path' => $path, 'action' => $action], $required, [], null, [], [$api->getMethod(), 'options']); // debug: print routes // printf("%s: %s -> %s\n", $api->getMethod(), $path, $module->getName() . ':' . $action->getName()); $routes->add($name, $route); // with params $paramRoute = clone $route; $paramRoute->setPath(sprintf('%s%s{params}', $path, $this->options['param-separator'])); $paramRoute->setRequirement('params', '.+'); $paramName = $name . 'WithParam'; $routes->add($paramName, $paramRoute); if (!$this->methods->has($path)) { $this->methods->set($path, new ArrayList()); } $this->methods->get($path)->add(strtoupper($api->getMethod())); } $this->init($routes); }
public function __construct(array $options) { // options parent::__construct($options); // routes $routes = new RouteCollection(); $routes->add('slug', new Route('/{slug}')); $routes->add('params', new Route(sprintf('/{slug}%s{params}', $this->options['param-separator']))); $this->init($routes); }