andres-montanez/useragentstring-bundle

此包已被废弃且不再维护。未建议替代包。

Symfony2 扩展,用于集成 UserAgentString

0.2.5 2016-04-07 16:01 UTC

This package is auto-updated.

Last update: 2021-02-19 00:35:20 UTC


README

# UserAgentString

将 User Agent String 项目集成到 Symfony

启用该扩展后,您可以访问 user_agent 服务

<?php
    class HomeController extends Controller
    {
        public function indexAction() {
            $ua = $this->get('user_agent');
            if ($ua->getCurrent()->isMobile()) {
                ...
            } else {
                ...
            }
        }
    }

本扩展受以下库的启发:[http://user-agent-string.info/download](http://user-agent-string.info/download),并使用那里的 XML,因此请保持您的更新!

您可以在 config.yml 中指定您的更新版本

andres_montanez_user_agent_string:
    source: "%kernel.root_dir%/Resources/uas_20140211-01.xml"
    robots: true

默认情况下,文件中的 Robots 部分不会被解析或使用。如果您想知道一个用户代理是否是机器人,您必须自己启用它。本扩展专注于真实用户的速度,而不是机器人。