Overview

Namespaces

  • Evenement
  • None
  • PHP
  • Psr
    • Http
      • Message
  • Ratchet
    • Http
    • RFC6455
      • Handshake
      • Messaging
    • Server
    • Session
      • Serialize
      • Storage
        • Proxy
    • Wamp
    • WebSocket
  • React
    • EventLoop
      • Tick
      • Timer
    • Socket
    • Stream
  • Symfony
    • Component
      • HttpFoundation
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
      • Routing
        • Annotation
        • Exception
        • Generator
          • Dumper
        • Loader
          • DependencyInjection
        • Matcher
          • Dumper
        • Tests
          • Annotation
          • Fixtures
            • AnnotatedClasses
            • OtherAnnotatedClasses
          • Generator
            • Dumper
          • Loader
          • Matcher
            • Dumper

Classes

  • UrlGenerator

Interfaces

  • ConfigurableRequirementsInterface
  • UrlGeneratorInterface
  • Overview
  • Namespace
  • Class
  • Tree

Class UrlGenerator

UrlGenerator can generate a URL or a path for any route in the RouteCollection based on the passed parameters.

Symfony\Component\Routing\Generator\UrlGenerator implements Symfony\Component\Routing\Generator\UrlGeneratorInterface, Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface
Namespace: Symfony\Component\Routing\Generator
Author: Fabien Potencier <fabien@symfony.com>
Author: Tobias Schultze <http://tobion.de>
Located at Generator/UrlGenerator.php
Methods summary
public
# __construct( Symfony\Component\Routing\RouteCollection $routes, Symfony\Component\Routing\RequestContext $context, Psr\Log\LoggerInterface $logger = null )

Constructor.

Constructor.

Parameters

$routes
Symfony\Component\Routing\RouteCollection
$routes A RouteCollection instance
$context
Symfony\Component\Routing\RequestContext
$context The context
$logger
Psr\Log\LoggerInterface|null
$logger A logger instance
public
# setContext( Symfony\Component\Routing\RequestContext $context )

Sets the request context.

Sets the request context.

Parameters

$context
Symfony\Component\Routing\RequestContext
$context The context

Implementation of

Symfony\Component\Routing\RequestContextAwareInterface::setContext()
public Symfony\Component\Routing\RequestContext
# getContext( )

Gets the request context.

Gets the request context.

Returns

Symfony\Component\Routing\RequestContext
The context

Implementation of

Symfony\Component\Routing\RequestContextAwareInterface::getContext()
public
# setStrictRequirements( boolean|null $enabled )

Enables or disables the exception on incorrect parameters. Passing null will deactivate the requirements check completely.

Enables or disables the exception on incorrect parameters. Passing null will deactivate the requirements check completely.

Parameters

$enabled
boolean|null
$enabled

Implementation of

Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface::setStrictRequirements()
public boolean|null
# isStrictRequirements( )

Returns whether to throw an exception on incorrect parameters. Null means the requirements check is deactivated completely.

Returns whether to throw an exception on incorrect parameters. Null means the requirements check is deactivated completely.

Returns

boolean|null

Implementation of

Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface::isStrictRequirements()
public string
# generate( string $name, mixed $parameters = array(), integer $referenceType = Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_PATH )

Generates a URL or path for a specific route based on the given parameters.

Generates a URL or path for a specific route based on the given parameters.

Parameters

$name
string
$name The name of the route
$parameters
mixed
$parameters An array of parameters
$referenceType
integer
$referenceType The type of reference to be generated (one of the constants)

Returns

string
The generated URL

Throws

Symfony\Component\Routing\Exception\RouteNotFoundException
If the named route doesn't exist
Symfony\Component\Routing\Exception\MissingMandatoryParametersException
When some parameters are missing that are mandatory for the route
Symfony\Component\Routing\Exception\InvalidParameterException
When a parameter value for a placeholder is not correct because it does not match the requirement

Implementation of

Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate()
protected
# doGenerate( mixed $variables, mixed $defaults, mixed $requirements, mixed $tokens, mixed $parameters, mixed $name, mixed $referenceType, mixed $hostTokens, array $requiredSchemes = array() )

Throws

Symfony\Component\Routing\Exception\MissingMandatoryParametersException
When some parameters are missing that are mandatory for the route
Symfony\Component\Routing\Exception\InvalidParameterException
When a parameter value for a placeholder is not correct because it does not match the requirement
public static string
# getRelativePath( string $basePath, string $targetPath )

Returns the target path as relative reference from the base path.

Returns the target path as relative reference from the base path.

Only the URIs path component (no schema, host etc.) is relevant and must be given, starting with a slash. Both paths must be absolute and not contain relative parts. Relative URLs from one resource to another are useful when generating self-contained downloadable document archives. Furthermore, they can be used to reduce the link size in documents.

Example target paths, given a base path of "/a/b/c/d":

  • "/a/b/c/d" -> ""
  • "/a/b/c/" -> "./"
  • "/a/b/" -> "../"
  • "/a/b/c/other" -> "other"
  • "/a/x/y" -> "../../x/y"

Parameters

$basePath
string
$basePath The base path
$targetPath
string
$targetPath The target path

Returns

string
The relative target path
Constants inherited from Symfony\Component\Routing\Generator\UrlGeneratorInterface
ABSOLUTE_PATH, ABSOLUTE_URL, NETWORK_PATH, RELATIVE_PATH
Properties summary
protected Symfony\Component\Routing\RouteCollection $routes
#
protected Symfony\Component\Routing\RequestContext $context
#
protected boolean|null $strictRequirements true
#
protected Psr\Log\LoggerInterface|null $logger
#
protected array $decodedChars array( // the slash can be used to designate a hierarchical structure and we want allow using it with this meaning // some webservers don't allow the slash in encoded form in the path for security reasons anyway // see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss '%2F' => '/', // the following chars are general delimiters in the URI specification but have only special meaning in the authority component // so they can safely be used in the path in unencoded form '%40' => '@', '%3A' => ':', // these chars are only sub-delimiters that have no predefined meaning and can therefore be used literally // so URI producing applications can use these chars to delimit subcomponents in a path segment without being encoded for better readability '%3B' => ';', '%2C' => ',', '%3D' => '=', '%2B' => '+', '%21' => '!', '%2A' => '*', '%7C' => '|', )
#

This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL.

This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL.

PHP's rawurlencode() encodes all chars except "a-zA-Z0-9-._~" according to RFC 3986. But we want to allow some chars to be used in their literal form (reasons below). Other chars inside the path must of course be encoded, e.g. "?" and "#" (would be interpreted wrongly as query and fragment identifier), "'" and """ (are used as delimiters in HTML).

Ratchet API documentation generated by ApiGen 2.8.0