Download the PHP package larva/agent without Composer

On this page you can find all versions of the php package larva/agent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package agent

Agent

Tests Latest Stable Version Total Downloads PHP Version

桌面端 / 移动端 User-Agent 解析库,基于 Mobile Detect 扩展了桌面设备识别、浏览器与操作系统识别等能力,并对 Laravel 提供开箱即用的支持。

关于本仓库

本项目 Fork 自 jenssegers/agent。原仓库已停止维护,本仓库在其基础上继续维护,主要变更:

环境要求

安装

Laravel 集成

本包已支持 Laravel 包自动发现,安装后即可直接使用 Agent Facade,无需任何额外配置。

如果你禁用了自动发现,请在 config/app.php 中手动注册:

基本用法

默认会自动从 $_SERVER 读取当前请求的 HTTP 头。在 CLI 脚本或需要解析指定 UA 时,使用 setUserAgent() 或 setHttpHeaders():

如果不希望自动读取 $_SERVER(例如在测试或队列任务中),可以关闭自动初始化:

注意:未设置 User-Agent 就调用 isMobile()、isTablet()、is() 等方法会抛出 Detection\Exception\MobileDetectException。

Mobile Detect 的原生方法依然可用,更多示例见 Mobile Detect Code Examples。

属性判断

检查 User-Agent 是否命中某条规则:

也可以使用等价的魔术方法:

设备类型判断

一次性获取设备类型,返回 desktop / phone / tablet / robot:

正则匹配

扩展功能

以下方法在未识别时统一返回 false。

语言偏好

解析 Accept-Language,按优先级从高到低返回:

设备名称

如 iPhone、iPad、Macintosh、Nexus 等:

操作系统名称

如 Windows、OS X、Ubuntu、AndroidOS、iOS、ChromeOS 等:

浏览器名称

如 Chrome、Firefox、Safari、Edge、Opera、Vivaldi、UCBrowser、IE 等:

爬虫名称

爬虫识别基于 jaybizzle/crawler-detect:

版本号

版本号提取依赖 UA 字符串中的特征片段,部分设备或浏览器可能无法准确返回。

从 jenssegers/agent 迁移

除了替换 composer 依赖和命名空间(Jenssegers\Agent → Larva\Agent),还需注意以下由 Mobile Detect 4.x 引入的破坏性变更:

变更点 旧版本 本版本
构造函数 new Agent($headers, $userAgent) new Agent(?CacheInterface $cache, array $config);HTTP 头改用 setHttpHeaders() 注入
检测方法参数 isMobile($ua, $headers) isMobile() 无参,先 setUserAgent()
isDesktop() / isPhone() / deviceType() 接受 $userAgent、$httpHeaders 参数 均改为无参
match() match($regex, $userAgent = null) match(string $regex, string $userAgent),第二个参数必填
未设置 UA 静默返回 false 抛出 MobileDetectException
扩展规则 setDetectionType() + getDetectionRulesExtended() detection type 机制已移除,getDetectionRulesExtended() 仍保留并自动用于 is() / is*()
deviceType() 返回值 可能返回 other 只返回 desktop / phone / tablet / robot

测试

贡献

欢迎提交 Issue 与 Pull Request。提交 PR 前请确保测试通过,并为新增行为补充对应用例。

许可协议

本项目基于 MIT License 开源。


All versions of agent with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
mobiledetect/mobiledetectlib Version ^4.11
jaybizzle/crawler-detect Version ^1.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package larva/agent contains the following files

Loading the files please wait ...