Sulu\Bundle\RouteBundle\Generator\RouteGenerator::generate PHP Method

generate() public method

public generate ( $entity, array $options )
$options array
    public function generate($entity, array $options)
    {
        $routeSchema = $options['route_schema'];
        $tokens = [];
        preg_match_all('/{(.*?)}/', $routeSchema, $matches);
        $tokenNames = $matches[1];
        foreach ($tokenNames as $index => $name) {
            $tokenName = '{' . $name . '}';
            $tokenValue = $this->tokenProvider->provide($entity, $name);
            $tokens[$tokenName] = $this->slugifier->slugify($tokenValue);
        }
        $path = strtr($routeSchema, $tokens);
        if (0 !== strpos($path, '/')) {
            throw new \InvalidArgumentException(sprintf('Generated path "%s" for object "%s" has to start with a slash', $path, get_class($entity)));
        }
        return $path;
    }