Sulu\Bundle\RouteBundle\Generator\TokenProviderInterface::provide PHP Method

provide() public method

Returns resolved token for entity.
public provide ( mixed $entity, string $name ) : string
$entity mixed
$name string
return string
    public function provide($entity, $name);

Usage Example

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;
 }
TokenProviderInterface