Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

New static API #83

Open
gabrielbull opened this issue Apr 12, 2017 · 1 comment
Open

New static API #83

gabrielbull opened this issue Apr 12, 2017 · 1 comment
Milestone

Comments

@gabrielbull
Copy link
Member

It would be easier to have a static API to use. Something like this:

use BrowserDetector\BrowserDetector;

$browser = BrowserDetector::getBrowser();
$os = BrowserDetector::getOs();
$device = BrowserDetector::getDevice();
$language = BrowserDetector::getLanguage();
$scriptedAgent = BrowserDetector::getScriptedAgent();

BrowserDetector::isScriptedAgent();
BrowserDetector::isChromeFrame();
BrowserDetector::isWebkit();
BrowserDetector::isFacebookWebView();
BrowserDetector::isTwitterWebView();
BrowserDetector::isCompatibilityMode();
@gabrielbull gabrielbull added this to the 7.0.0 milestone Apr 12, 2017
@TomMettam
Copy link

TomMettam commented Apr 17, 2017

While I think this is an improvement to the current model, I would like to propose the following:

$detected = BrowserDetector::detect(DETECT_BROWSER | DETECT_OS | DETECT_DEVICE | DETECT_LANGUAGE | DETECT_SCRIPTED_AGENT);

//also DETECT_ALL

$detected is then a class which contains the requested information.

Here is my reasoning:

  • Many of these things are related, and we could avoid parsing the UA multiple times.
  • Allows the user to fine-tune what is detected for performance reasons

I have been working on a new parsing system (maybe a different project than this) which uses a single Regex to break down a user-agent into components, and then adds each component to a key/value store for quick lookup by the analysers. This should provide a significant speed boost as we're indexing rather than performing multiple substring searches.

So working with the flags suggestion above, the process could be like:

  1. Call BrowserDetector::detect($flags = DETECT_ALL)
  2. BrowserDetector splits and indexes the UA into a key/value store
  3. BrowserDetector creates a new object based on some Results class
  4. For each DETECT_ flag, if required, BrowserDetector passes the key/value and Results (byref) objects into each relevant detection class
  5. Results object is modified by each detection class and is eventually returned from the detect function

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants