问题是为什么
$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_collection是Symfony\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 ツ,但是如果我想在matcher中使用route_collection 怎么办
matcher:
class: Symfony\Component\Routing\Matcher\UrlMatcher
arguments: ["@route_collection", "@context"]