Example #1
0
 /**
  * {@inheritdoc}
  */
 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;
 }