1

If I enter in an invalid routing configuration key in a Symfony route, I get a helpful exception message that lists all the valid Symfony routing configuration keys

The routing file "path/to/config/routes.yaml" contains unsupported keys for "route_name": "invalid_key_name". Expected one of: "resource", "type", "prefix", "path", "host", "schemes", "methods", "defaults", "requirements", "options", "condition", "controller", "name_prefix", "trailing_slash_on_root"

Most of these keys are documented somewhere on the Symfony site. However, I have not been able to find documentation for the options key.

Does anyone know what this should (or can) be used for?

6
  • 1
    I think it does as the name says on the tin - an options-type array.. basing assumption (hence, no answer) on: api.symfony.com/2.3/Symfony/Component/Routing/Route.html (skip down to Route: getOptions/setOptions) Commented Mar 11, 2019 at 14:18
  • +1 Useful bit of knowedge @treyBake, thank you! I'm hoping someone with deeper symfony experience than either of us can explain what these options are used for, of if this is just a way to set options that you might fetch later via PHP code. Commented Mar 11, 2019 at 14:20
  • No worries, glad I can help out a vet such as yourself :) I think it's the latter but without fully knowing, I can't speak in absolutes :S however, if someone does come along, let me know, be interested in seeing the answer :) Commented Mar 11, 2019 at 14:21
  • I found one use case in the documentation where options is used to support UTF-8 characters in the route paths, see here. Commented Mar 11, 2019 at 14:34
  • 1
    Until <3.4 the option param was used to define, as example, the utf8 parameter while from >=4.x the utf8 param have its own definition. I guess that the option param was leaved there mostly for compatibility reasons present in the 3.4 version. Commented Mar 11, 2019 at 14:36

1 Answer 1

1

Digging into a route object's class file reveals this

#File: vendor/symfony/routing/Route.php
public function setOptions(array $options)
{
    $this->options = array(
        'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler',
    );

    return $this->addOptions($options);
}

That is -- Symfony sets a compiler_class field on the options array, and it's this options array that the options: configuration key is linked to. Symfony then uses this compiler class option in the same class

#File: vendor/symfony/routing/Route.php
public function compile()
{
    if (null !== $this->compiled) {
        return $this->compiled;
    }

    $class = $this->getOption('compiler_class');

    return $this->compiled = $class::compile($this);
}

So -- probably not something 99% of Symfony devs will need/want to use, but it is still there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.