/** * Creates operation. * * @param ResourceInterface $resource * @param bool $collection * @param string|array $methods * @param string|null $path * @param null $controller * @param null $routeName * @param array $context * * @return Operation */ private function createOperation(ResourceInterface $resource, $collection, $methods, $path = null, $controller = null, $routeName = null, array $context = []) { $shortName = $resource->getShortName(); if (!isset(self::$inflectorCache[$shortName])) { self::$inflectorCache[$shortName] = Inflector::pluralize(Inflector::tableize($shortName)); } // Populate path if (!$path) { $path = '/' . self::$inflectorCache[$shortName]; if (!$collection) { $path .= '/{id}'; } } // Guess default method if (is_array($methods)) { $defaultMethod = $methods[0]; } else { $defaultMethod = $methods; } // Populate controller if (!$controller) { $defaultAction = strtolower($defaultMethod); if ($collection) { $defaultAction = 'c' . $defaultAction; } $controller = self::DEFAULT_CONTROLLER . ':' . $defaultAction; // Populate route name if (!$routeName) { $routeName = self::$inflectorCache[$shortName] . '_' . $defaultAction; } } $requirements = []; if (strpos($path, '{id}')) { $requirements['id'] = '\\d+'; } if (strpos($path, '{embed}')) { try { $embeds = $this->transformerHelper->getAvailableIncludes($shortName); $requirements['embed'] = implode('|', $embeds); } catch (\Exception $ex) { //commande sfroute symfony } } // $requirements ['"context.getApiVersion() === '".$apiVersion."'"'] return new Operation(new Route($path, ['_controller' => $controller, '_resource' => $shortName], $requirements, [], '', [], $methods), self::ROUTE_NAME_PREFIX . $resource->getVersion() . '_' . $routeName, $context); }