2017 © Pedro Peláez
 

library user-agent-bundle

bundle to handle header user-agent versions

image

waldemarnt/user-agent-bundle

bundle to handle header user-agent versions

  • Saturday, May 14, 2016
  • by waldemarnt
  • Repository
  • 1 Watchers
  • 3 Stars
  • 173 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

User Agent Version Bundle

Suppose that we have an API or a external connection that needs validation by user-agent, by version, this bundle will fall like a glove in your pretty hands., (*1)

Usage

The list is separated by kind., (*2)

Installation

Add it as dependency in your composer.json, (*3)

    "require": {
        "waldemarnt/user-agent-bundle": "2.*"
    }

Update your AppKernel.php and add this line, (*4)

    new Wneto\UserAgentBundle\WnetoUserAgentBundle(),

Usage

First of all you need understand how this stuff works. For example, a browser request send headers like this:, (*5)

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36

This example was did using POSTMAN, well, lets suppose that i need receive only requests from Mozilla that have version higher than 5.0. What i need to do that? Kepp calm, lets do it! First of all we need the configuration inside the config.yml file, (*6)

# you can found a sample inside Wneto/UserAgentBundle/Resources/samples/config/user_agent.yml
wneto_user_agent:
    validation: true
    type: whitelist # blacklist or whitelist. With whitelist all request will be blocked and accept requests only from the setted patterns
    patterns:
        - { pattern: "Mozilla", version: "5.0", operator: ">" }

Lets understand, pattern is the name of the agent, the name is before the / bar in the agent, allowed is a boolean and the version will be the version that you need set the rule, the operator is used to applicate the rule for example higher than > higher of equals than >= the same in inverse < , <=, (*7)

Ok now in our application we just need add a verification like this one: First inject the service @user_agent.validator.user_agent in your class., (*8)

    public function isDeviceAllowed($request){
        if($this->userAgentValidator->isEnabled()) {
            return $this->userAgentValidator->isAllowed($request->headers->get('user-agent'));
        }

        return true;
    }

Ok, the magic will happen and we will be happy forever., (*9)

The Versions

14/05 2016

dev-master

9999999-dev

bundle to handle header user-agent versions

  Sources   Download

MIT

by Waldemar Neto

02/10 2015

v1.0.6

1.0.6.0

bundle to handle header user-agent versions

  Sources   Download

MIT

by Waldemar Neto

01/10 2015

v1.0.5

1.0.5.0

bundle to handle header user-agent versions

  Sources   Download

MIT

by Waldemar Neto

01/10 2015

v1.0.4

1.0.4.0

bundle to handle header user-agent versions

  Sources   Download

MIT

by Waldemar Neto

01/10 2015

v1.0.3

1.0.3.0

bundle to handle header user-agent versions

  Sources   Download

MIT

by Waldemar Neto

01/10 2015

v1.0.2

1.0.2.0

bundle to handle header user-agent versions

  Sources   Download

MIT

by Waldemar Neto

01/10 2015

v1.0.0

1.0.0.0

bundle to handle header user-agent versions

  Sources   Download

MIT

by Waldemar Neto

01/10 2015

v1.0.1

1.0.1.0

bundle to handle header user-agent versions

  Sources   Download

MIT

by Waldemar Neto