Code Monkey home page Code Monkey logo

browscapbundle's Introduction

Browser Capabilities Project

Continuous Integration codecov

This tool is used to build and maintain browscap files.

Installation

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

What's changed in version 6048

  • #2535 Added recent new Apple platforms (Mac OS, iOS and iPadOS)

What's changed in version 6028

BC breaks listed

  • Interface changed for class \Browscap\Data\Factory\UserAgentFactory

What's changed in version 6027

BC breaks listed

  • 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

What's changed in version 6025

BC breaks listed

  • The grep command and the diff command were removed

Changes

  • The tests for integration testing the source files are split from the other tests
  • Tests on travis use the build pipeline now

Directory Structure

  • bin - Contains executable files
  • build - Contains various builds
  • resources - Files needed to build the various files, also used to validate the capabilities
  • src - The code of this project lives here
  • tests - The testing code of this project lives here

the CLI commands

There is actually only one cli command available.

build

This command is used to build a set of defined browscap files.

bin/browscap build [version]

options

  • version (required) the name of the version that should be built
  • output (optional) the directory where the files should be created
  • resources (optional) the directory where the sources for the build are located
  • coverage (optional) if this option is set, during the build information is added which can be used to generate a coverage report
  • no-zip (optional) if this option is set, no zip file is generated during the build

For further documentation on the build command, see here.

CLI Examples

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.

Usage Examples

How to build a standard set of browscap files

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);

How to build a custom set of browscap files

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);

How to build a custom browscap.ini

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);

Issues and feature requests

Please report your issues and ask for new features on the GitHub Issue Tracker at https://github.com/browscap/browscap/issues

Contributing

For instructions on how to contribute see the CONTRIBUTE.md file.

License

See the LICENSE file.

browscapbundle's People

Contributors

asgrim avatar benjaminpaap avatar emmanuelvella avatar joshuaestes avatar mimmi20 avatar smatyas avatar soullivaneuh avatar spomky avatar tobias-nitsche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

browscapbundle's Issues

browscap:update command fail

On local:

$ ./bin/console browscap:update      

                                                        
  [phpbrowscap\Exception]                               
  Bad datetime format from http://browscap.org/version  

Even worse on CI:

$ ./bin/console browscap:update --env=test

                                                              
  [Symfony\Component\Debug\Exception\ContextErrorException]   
  Warning: syntax error, unexpected '}' in Unknown on line 1  

I still have this env from a while:

sullivan@6674077520e8:/code$ composer show | grep browscap
browscap/browscap-bundle                 dev-master 6071708   Allows you to get browser information
browscap/browscap-php                    2.1.1                Standalone replacement for php's native get_browser() function

And didn't have this error before. It seems to be something wrong with browscap.org. Maybe CloudFlare rules?

Regards.

browscap.update_method

Nice bundle. Is browscap.update_method a required parameter, or should the BrowscapBundle be able to deduce this on it's own?

Provide auto-wiring for browscap service

  [Symfony\Component\DependencyInjection\Exception\RuntimeException]                                                                                                                                                                                    
  Cannot autowire service "AppBundle\Manager\BrowserManager": argument "$browscap" of method "__construct()" references class "phpbrowscap\Browscap" but no such service exists. You should maybe alias this class to the existing "browscap" service.  

Workaround:

$container->addAliases([
    \phpbrowscap\Browscap::class => 'browscap',
]);

Create directory is not exists

Actually, if I have this config:

browscap:
    cache_dir:            %kernel.root_dir%/shared/%kernel.environment%/browscap
    lowercase:            true
    do_auto_update:       false

I have this error on update command:

The cache path /[project]/app/shared/dev/browscap is invalid. Are you sure that it exists and that you have permission to access it?

It could be useful to create directory if not exists.

Thanks.

Service issues with Symfony 4.1

The console update command need a service registration and the borwscap service need to be public or autowired (#24)

Current workaround on kernel compilation:

final class Kernel extends BaseKernel implements CompilerPassInterface
{
    use MicroKernelTrait;

    public function process(ContainerBuilder $container): void
    {
        $container->setDefinition(
            \Browscap\BrowscapBundle\Command\UpdateCommand::class,
            (new Definition(\Browscap\BrowscapBundle\Command\UpdateCommand::class))
                ->addTag('console.command')
        );
        $container->getDefinition('browscap')->setPublic(true);
    }

Composer problem

php composer.phar require "browscap/browscap-bundle:1.0.*"                                                                                                                            *[security_plus] 
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package browscap/browscap-bundle could not be found in any version, there may be a typo in the package name.
  Problem 2
    - Installation request for symfony/framework-standard-edition 2.4.x-dev -> satisfiable by symfony/framework-standard-edition[2.4.x-dev].
    - symfony/framework-standard-edition 2.4.x-dev requires browscap/browscap-bundle 1.0.* -> no matching package found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

Incompatible with 3.x namespace change

I got this error on unit tests:

Fatal error: Class 'phpbrowscap\Browscap' not found in /code/vendor/browscap/browscap-bundle/Browscap/BrowscapBundle/Browscap.php on line 10

Installed versions:

$ composer show browscap*
browscap/browscap-bundle dev-master 58e71da Allows you to get browser information
browscap/browscap-php    3.0.0              Standalone replacement for php's native get_browser() function

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.