简体   繁体   English

Symfony CMF动态路由器“无法匹配”日志

[英]Symfony CMF Dynamic router “was not able to match” logs

I have a Symfony 2.6 application using Symfony CMF routing bundle 1.3 where we use a combination of normal symfony routes and dynamic routes for custom stores (amongst other things, the below example focuses on one of our dynamic routers). 我有一个使用Symfony CMF路由包1.3的Symfony 2.6应用程序,在该应用程序中,我们将常规symfony路由和动态路由结合使用用于自定义存储(此外,以下示例重点介绍了我们的一个动态路由器)。

The problem is that we are getting endless logs about the router not being able to match the dynamic routes when they work just fine. 问题是我们收到无尽的日志,说明路由器在正常工作时无法匹配动态路由。

The most common entry being: 最常见的条目是:

Router Symfony\Bundle\FrameworkBundle\Routing\Router was not able to match, message ""

We occasionally see 我们偶尔看到

Router Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter was not able to match, message ""

Is there a way to disable these logs or change my dynamic router configuration/setup so that these errors only appear when the route actually fails. 有没有办法禁用这些日志或更改我的动态路由器配置/设置,以使这些错误仅在路由实际失败时出现。

Here is my config/setup: 这是我的配置/设置:

# app/config/config.yml

cmf_routing:
    chain:
        routers_by_id:
            router.default:             32
            cmf_routing.dynamic_router: 30
    dynamic:
        enabled:                      true
        route_provider_service_id:    store_router

And the actual dynamic router based on 并基于实际的动态路由器

// StoreBundle/Router/StoreRouter.php

<?php

/**
 * @DI\Service("store_router")
 */
class StoreRouter implements RouteProviderInterface
{
    protected $em;

    /**
     * @DI\InjectParams({
     *      "em" = @DI\Inject("doctrine.orm.entity_manager")
     * })
     */
    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    /**
     * @param Request $request
     * @return RouteCollection
     */
    public function getRouteCollectionForRequest(Request $request)
    {
        $collection = new RouteCollection();

        $store = $this->em->getRepository('StoreBundle:Store')->findOneBySlug(substr($request->getPathInfo(), 1), $request->get('key', null));

        // no store found, return an empty collection
        if (empty($store)) {
            return $collection;
        }

        $route = new Route(
            '/' . $store->getSlug(),
            [
                '_controller' => 'StoreBundle:Store:view',
                'slug' => $stote->getSlug()
            ]
        );

        $collection->add($store->getSlug(), $route);

        return $collection;
    }

    public function getRouteByName($name, $params = [])
    {
    }

    public function getRoutesByNames($names)
    {
    }
}

If theres a better way to use dynamic routes I'd love to hear it :) 如果有更好的方式来使用动态路线,我很想听听:)

The log entries are created at level "debug". 日志条目在“调试”级别创建。 You can set the minimum level of your logger higher. 您可以设置更高的记录器最低级别。 If you need debug logs for other things, you can write a CompilerPass that removes the logger argument on the symfony_cmf.router service. 如果您需要调试日志来执行其他操作,则可以编写CompilerPass来删除symfony_cmf.router服务上的logger参数。

I agree that it would make sense to have the log level configureable, with a false option to completely disable logging. 我同意可以配置日志级别,并使用false选项完全禁用日志记录是有意义的。 If you want this, I am happy to review and merge a pull request on the Routing component for the code and the RoutingBundle to expose the configuration. 如果您愿意,我很乐意在“路由”组件上查看并合并对代码和“路由捆绑”的拉取请求,以公开配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM