octoper / lighthouse-php
Google Lighthouse 接口
0.0.4
2020-06-24 14:11 UTC
Requires
- php: ^7.4
- symfony/process: ^5.1
Requires (Dev)
- dms/phpunit-arraysubset-asserts: ^0.2.0
- friendsofphp/php-cs-fixer: ^2.16
- pestphp/pest: ^0.1.5
- phpunit/phpunit: ^9.0
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2024-09-09 00:37:18 UTC
README
此包是基于 dzava/lighthouse-php 构建的
此包为 Google Lighthouse 提供PHP接口。
安装
您可以通过composer安装此包
composer require octoper/lighthouse-php
用法
以下是一个示例,将执行默认的Lighthouse审核并将结果存储在 report.json
中(您可以使用Lighthouse Viewer 打开报告)
use Octoper\Lighthouse\Lighthouse; (new Lighthouse()) ->setOutput('report.json') ->accessibility() ->bestPractices() ->performance() ->pwa() ->seo() ->audit('http://example.com');
输出
setOutput
方法接受第二个参数,可以用来指定格式(json,html)。如果省略格式参数,则将使用文件扩展名来确定输出格式。如果文件扩展名没有指定接受的格式,则将使用json。
您可以通过传递数组作为第二个参数来输出json和html报告。对于示例,以下代码将创建两个报告 example.report.html
和 example.report.json
。
use Octoper\Lighthouse\Lighthouse; (new Lighthouse()) ->setOutput('example', ['html', 'json']) ->performance() ->audit('http://example.com');
使用自定义配置
您可以使用withConfig
方法提供自己的配置文件。
use Octoper\Lighthouse\Lighthouse; (new Lighthouse()) ->withConfig('./my-config.js') ->audit('http://example.com');
自定义node和Lighthouse路径
如果您需要手动设置这些路径,可以通过调用setNodeBinary
和setLighthousePath
方法来实现。
use Octoper\Lighthouse\Lighthouse; (new Lighthouse()) ->setNodeBinary('/usr/bin/node') ->setLighthousePath('./lighthouse.js') ->audit('http://example.com');
传递标志到Chrome
使用setChromeFlags
方法向Chrome实例传递任何标志。
use Octoper\Lighthouse\Lighthouse; (new Lighthouse()) // these are the default flags used ->setChromeFlags(['--headless', '--disable-gpu', '--no-sandbox']) ->audit('http://example.com');
测试
composer test
安全性
如果您发现任何安全相关的问题,请通过电子邮件me@octoper.me联系,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。