0

質問はなぜ

$config = array(__DIR__ . '/app/config');
$locator = new Symfony\Component\Config\FileLocator($config);
$loader = new Symfony\Component\Routing\Loader\YamlFileLoader($locator);
$routes_collection = $loader->load('routes.yml');

$routes_collectionはSymfony \Component\Routing\RouteCollectionのインスタンスであり、このコードは正常に動作します。

そしてここ

# config.yml
file_locator:
    class:    Symfony\Component\Config\FileLocator
    arguments:  ['%app_root%/app/config']

route_collection:
    class:    Symfony\Component\Routing\Loader\YamlFileLoader
    arguments: ["@file_locator"]
    calls:
              - [load, ['routes.yml']]

#app.php
$routes_collection = $container->get('route_collection')

$routes_collectionSymfony\Component\Routing\Loader\YamlFileLoaderのインスタンスであり、 Symfony\Component\Routing\Matcher\UrlMatcherで使用すると、次のようになります:

Argument 1 passed to Symfony\Component\Routing\Matcher\UrlMatcher::__construct() must be an instance of Symfony\Component\Routing\RouteCollection, instance of Symfony\Component\Routing\Loader\YamlFileLoader given.

アップデート

@Pazi ツですが、マッチャーでroute_collectionを使用したい場合の方法

matcher:
    class:    Symfony\Component\Routing\Matcher\UrlMatcher
    arguments:  ["@route_collection", "@context"]
4

2 に答える 2