Coder Social home page Coder Social logo

browscapbundle's Introduction

Browscap/BrowscapBundle

Build Status Scrutinizer Quality Score Code Coverage

This is a service for you that is similar to the php function get_browser(). It uses https://github.com/GaretJax/phpbrowscap project.

Installation

php composer.phar require browscap/browscap-bundle:1.0.*

This will install the current version which is beta and is the master branch. I don't want to say it's stable yet until I have some more tests and real world usage under the belt, but should be good enough to use in a production site.

In your app/AppKernel.php file

public function registerBundles()
{
    ...
    $bundles = array(
        ...
        new Browscap\BrowscapBundle\BrowscapBundle(),
        ...
    );
    ...
}

Configuration

You can see the configuration values and information by running php app/console config:dump-reference BrowscapBundle

browscap:
    remote_ini_url:       http://tempdownloads.browserscap.com/stream.php?BrowsCapINI
    remote_ver_url:       http://tempdownloads.browserscap.com/versions/version-date.php
    cache_dir:            null # If null, use your application cache directory
    timeout:              5
    update_interval:      432000
    error_interval:       7200
    do_auto_update:       true
    update_method:        'cURL' # Supported methods: 'URL-wrapper','socket','cURL' and 'local'.
    local_file:           null # Only if used
    cache_filename:       'cache.php'
    ini_filename:         'browscap.ini'
    lowercase:            false # You need to rebuild the cache if this option is changed
    silent:               false

Usage

In your controller, you will just need to get the browser information via the dependency injection container.

// @var $browscap \Browscap\BrowscapBundle\Browscap
$browscap = $this->container->get('browscap');
$browser = $browscap->getBrowser();

In twig templates, you can call the get_browser function :

{% set browser = get_browser() %}

In the future there might be some more functions.

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

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.

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?

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

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

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',
]);

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.

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.