Symfony\Component\Routing\Router::setOptions PHP Method

setOptions() public method

Available options: * cache_dir: The cache directory (or null to disable caching) * debug: Whether to enable debugging or not (false by default) * resource_type: Type hint for the main resource (optional)
public setOptions ( array $options )
$options array An array of options
    public function setOptions(array $options)
    {
        $this->options = array(
            'cache_dir'              => null,
            'debug'                  => false,
            'generator_class'        => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
            'generator_base_class'   => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
            'generator_dumper_class' => 'Symfony\\Component\\Routing\\Generator\\Dumper\\PhpGeneratorDumper',
            'generator_cache_class'  => 'ProjectUrlGenerator',
            'matcher_class'          => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
            'matcher_base_class'     => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
            'matcher_dumper_class'   => 'Symfony\\Component\\Routing\\Matcher\\Dumper\\PhpMatcherDumper',
            'matcher_cache_class'    => 'ProjectUrlMatcher',
            'resource_type'          => null,
        );

        // check option names and live merge, if errors are encountered Exception will be thrown
        $invalid = array();
        $isInvalid = false;
        foreach ($options as $key => $value) {
            if (array_key_exists($key, $this->options)) {
                $this->options[$key] = $value;
            } else {
                $isInvalid = true;
                $invalid[] = $key;
            }
        }

        if ($isInvalid) {
            throw new \InvalidArgumentException(sprintf('The Router does not support the following options: "%s".', implode('\', \'', $invalid)));
        }
    }

Usage Example

示例#1
0
 /**
  * Constructor.
  *
  * @param RequestContext       $requestContext The context
  * @param RouteCollection|null $collection
  * @param array                $options
  * @param LoggerInterface      $logger         A logger instance
  */
 public function __construct(RequestContext $requestContext, RouteCollection $collection = null, array $options = array(), LoggerInterface $logger = null)
 {
     parent::setOptions($options);
     $this->context = $requestContext;
     $this->collection = $collection;
     $this->logger = $logger;
 }