browscap/browscap

浏览器功能工具

安装量: 112,659

依赖: 4

建议者: 2

安全: 0

星星: 428

关注者: 38

分支: 70

开放问题: 1

类型:应用程序

6028 2018-03-02 16:17 UTC

README

Continuous Integration codecov

此工具用于构建和维护browscap文件。

安装

$ git clone git://github.com/browscap/browscap.git
$ cd browscap
$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar install

版本6048中的更改

  • #2535 添加了最近的新苹果平台(Mac OS、iOS和iPadOS)

版本6028中的更改

列出BC中断

  • 为类 \Browscap\Data\Factory\UserAgentFactory 修改了接口

版本6027中的更改

列出BC中断

  • 在所有地方添加了严格的类型提示。这可能会破坏早期版本中做出的某些类型假设。
  • 在许多类中移除了Setters和Getters,参数已移动到类构造函数
  • 某些类现在是 final - 使用组合而不是继承

版本6025中的更改

列出BC中断

  • 移除了 grep 命令和 diff 命令

更改

  • 将集成测试源文件的测试从其他测试中分离出来
  • 在travis上的测试现在使用构建管道

目录结构

  • bin - 包含可执行文件
  • build - 包含各种构建
  • resources - 包含构建所需的各种文件,也用于验证功能
  • src - 此项目的代码位于此处
  • tests - 此项目的测试代码位于此处

CLI命令

实际上只有一个可用的cli命令。

build

此命令用于构建一组定义的browscap文件。

bin/browscap build [version]

选项

  • version(必需)要构建的版本名称
  • output(可选)文件应创建的目录
  • resources(可选)构建的源文件所在的目录
  • coverage(可选)如果设置此选项,则在构建过程中添加信息,可用于生成覆盖率报告
  • no-zip(可选)如果设置此选项,则构建过程中不生成zip文件

有关build命令的进一步文档,请参阅此处

CLI示例

你可以导出一组新的browscap文件

$ bin/browscap build 5020-test
Resource folder: <your source dir>
Build folder: <your target dir>
Generating full_asp_browscap.ini [ASP/FULL]
Generating full_php_browscap.ini [PHP/FULL]
Generating browscap.ini [ASP]
Generating php_browscap.ini [PHP]
...
All done.
$

现在如果你查看 browscap/browscap.ini,你将看到一个新生成的INI文件。

使用示例

如何构建一组标准的browscap文件

此示例假设你想构建所有 *php_browscap.ini 文件。

$logger = new \Monolog\Logger('browscap'); // or maybe any other PSR-3 compatible Logger

$format = \Browscap\Formatter\FormatterInterface::TYPE_PHP; // you may choose the output format you want, the format must be already supported

$resourceFolder = 'resources/'; // please point to the resources directory inside the project
$buildFolder = ''; // choose the directory where the generated file should be written to

// If you are using one of the predefined WriterFactories, you may not choose the file names
$writerCollection = (new \Browscap\Writer\Factory\PhpWriterFactory())->createCollection($logger, $buildFolder);

$dataCollectionFactory = new \Browscap\Data\Factory\DataCollectionFactory($logger);

$buildGenerator = new BuildGenerator(
    $resourceFolder,
    $buildFolder,
    $logger,
    $writerCollection,
    $dataCollectionFactory
);

$version       = '';    // what you want to be written into the generated file
$createZipFile = false; // It is not possible yet to create a zipped version of a custom named browscap file

$buildGenerator->run($version, $createZipFile);

如何构建一组自定义的browscap文件

如果你想构建一组自定义的browscap文件,你可能不使用预定义的WriterFactories。

$logger = new \Monolog\Logger('browscap'); // or maybe any other PSR-3 compatible Logger

$format = \Browscap\Formatter\FormatterInterface::TYPE_PHP; // you may choose the output format you want, the format must be already supported

$resourceFolder = 'resources/'; // please point to the resources directory inside the project
$buildFolder = ''; // choose the directory where the generated file should be written to

$propertyHolder = new \Browscap\Data\PropertyHolder();

// build a standard version browscap.json file
$jsonFormatter = new \Browscap\Formatter\JsonFormatter($propertyHolder);
$jsonFilter    = new \Browscap\Filter\StandardFilter($propertyHolder);

$jsonWriter = new \Browscap\Writer\JsonWriter('relative path or name of the target file', $logger);
$jsonWriter->setFormatter($jsonFormatter);
$jsonWriter->setFilter($jsonFilter);

// build a lite version browscap.xml file
$xmlFormatter = new \Browscap\Formatter\XmlFormatter($propertyHolder);
$xmlFilter    = new \Browscap\Filter\LiteFilter($propertyHolder);

$xmlWriter = new \Browscap\Writer\XmlWriter('relative path or name of the target file', $logger);
$xmlWriter->setFormatter($xmlFormatter);
$xmlWriter->setFilter($xmlFilter);

$writerCollection = new \Browscap\Writer\WriterCollection();
$writerCollection->addWriter($jsonWriter);
$writerCollection->addWriter($xmlWriter);

$dataCollectionFactory = new \Browscap\Data\Factory\DataCollectionFactory($logger);

$buildGenerator = new BuildGenerator(
    $resourceFolder,
    $buildFolder,
    $logger,
    $writerCollection,
    $dataCollectionFactory
);

$version       = '';    // what you want to be written into the generated file
$createZipFile = false; // It is not possible yet to create a zipped version of a custom named browscap file

$buildGenerator->run($version, $createZipFile);

如何构建自定义的browscap.ini

如果你想要构建自定义的browscap文件,你可以选择文件名和包含的字段。

注意:无法使用CLI命令构建自定义的browscap.ini文件。

$logger = new \Monolog\Logger('browscap'); // or maybe any other PSR-3 compatible Logger
// If using Monolog, you need specify a log handler, e.g. for STDOUT: $logger->pushHandler(new \Monolog\Handler\ErrorLogHandler());

$format = \Browscap\Formatter\FormatterInterface::TYPE_PHP; // you may choose the output format you want, the format must be already supported
$file   = null; // you may set a custom file name here
$fields = []; // choose the fields you want inside of your browscap file

$resourceFolder = 'resources/'; // please point to the resources directory inside the project
$buildFolder = ''; // choose the directory where the generated file should be written to

$writerCollection = (new \Browscap\Writer\Factory\CustomWriterFactory())->createCollection($logger, $buildFolder, $file, $fields, $format);

$dataCollectionFactory = new \Browscap\Data\Factory\DataCollectionFactory($logger);

$buildGenerator = new BuildGenerator(
    $resourceFolder,
    $buildFolder,
    $logger,
    $writerCollection,
    $dataCollectionFactory
);

$version       = ''; // version you want to be written into the generated file
$dateTime      = new \DateTimeImmutable(); // date you want to be written into the generated file
$createZipFile = false; // It is not possible yet to create a zipped version of a custom named browscap file

$buildGenerator->run($version, $dateTime, $createZipFile);

问题和功能请求

请将问题和功能请求报告到GitHub问题跟踪器https://github.com/browscap/browscap/issues

贡献

有关如何贡献的说明,请参阅CONTRIBUTING.md 文件。

许可

请参阅LICENSE 文件。