GaretJax/phpbrowscap — pull request #19 by Dinduks (2012-06-21 22:00:24+00:00)
Title: Add an action method to Browscap

Hi,

I added a method called `action` (the name could be improved), that executes a specific action depending on the rules passed to it.

An example would be more explanatory:

Let's say you want to redirect all the visitors whom
* Chrome version is older than 15 on Linux
* Chrome version is older than 20 on all the other platforms
* Firefox version is older than 10

You'd then just create an array containing these rules:

$rules = array(
'Linux' => array(
'Chrome' => 15,
),
'default' => array(
'Chrome' => 20,
'Firefox' => 10,
),
);

And then, in a callback, specify what you want to do (redirecting in this case) if these rules aren't followed:

$callback = function() { header('Location: /update-your-browser'); }

Now all what you have to do is to pass these information to `action()`:

$bc->action($rules, $callback);

You can also ask for the callback to be called when the rules *are met* by passing a *higher than* operator as a third parameter: `$bc->action($rules, $callback, '>');`.

I find this very useful, having my self needed to do different things depending on the user's browser, -- and I think it would be powerful thanks to the complete information this library already provides.

I'll update the documentation when this PR will be merged.

Cheers,
Samy