/** * Generates a Url for an action. * * @param string $path The path for the resource the action belongs to. * @param \Rested\Definition\ActionDefinitionInterface $action Action to generate a Url for. * * @return string */ protected function generateUrlForAction(ActionDefinitionInterface $action, $path) { $tokens = $action->getTokens(); $components = array_map(function (Parameter $value) { return sprintf('{%s}', $value->getName()); }, $tokens); if ($action->shouldAppendId() === true) { $components[] = $action->getId(); } array_unshift($components, $path); array_unshift($components, $this->urlGenerator->getMountPath()); $u = join('/', $components); $u = preg_replace('/\\/{2,}/', '/', $u); return $u; }
/** * {@inheritdoc} */ public function routeName(ActionDefinitionInterface $action, $prefix) { $components = [$prefix, $action->getId()]; $options = ['delimiter' => '_']; return self::ROUTE_PREFIX . $this->slugFromArray($components, $options); }