This tool is used to build and maintain browscap files.
$ git clone git://github.com/browscap/browscap.git
$ cd browscap
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar install
- browscap#2535 Added recent new Apple platforms (Mac OS, iOS and iPadOS)
- Interface changed for class \Browscap\Data\Factory\UserAgentFactory
- Strict type hints have been added throughout. This may break some type assumptions made in earlier versions.
- In many classes Setters and Getters have been removed, the parameters have been moved to the class constructor
- Some classes are now
final
- use composition instead of inheritance
- The
grep
command and thediff
command were removed
- The tests for integration testing the source files are split from the other tests
- Tests on travis use the build pipeline now
bin
- Contains executable filesbuild
- Contains various buildsresources
- Files needed to build the various files, also used to validate the capabilitiessrc
- The code of this project lives heretests
- The testing code of this project lives here
There is actually only one cli command available.
This command is used to build a set of defined browscap files.
bin/browscap build [version]
version
(required) the name of the version that should be builtoutput
(optional) the directory where the files should be createdresources
(optional) the directory where the sources for the build are locatedcoverage
(optional) if this option is set, during the build information is added which can be used to generate a coverage reportno-zip
(optional) if this option is set, no zip file is generated during the build
For further documentation on the build
command, see here.
You can export a new set of browscap files:
$ 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.
$
Now you if you look at browscap/browscap.ini
you will see a new INI file has been generated.
This example assumes that you want to build all *php_browscap.ini files.
$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);
If you want to build a custom set of browscap files, you may not use the predefined 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);
If you want to build a custom browscap file you may choose the file name and the fields which are included.
Note: It is not possible to build a custom browscap.ini file with the CLI command.
$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);
Please report your issues and ask for new features on the GitHub Issue Tracker at https://github.com/browscap/browscap/issues
For instructions on how to contribute see the CONTRIBUTE.md file.
See the LICENSE file.