thadafinser / useragentparser Goto Github PK
View Code? Open in Web Editor NEWUserAgent parsing done right
Home Page: http://useragent.mkf.solutions/
License: MIT License
UserAgent parsing done right
Home Page: http://useragent.mkf.solutions/
License: MIT License
If the running script is placed in a a subdirectory, it will break the loading of the installed providers.
For ex., including autoload like this
require __DIR__.'../vendor/autoload.php';
produce a fatal error:
PHP Fatal error: Uncaught exception 'UserAgentParser\\Exception\\PackageNotLoadedException' with message 'You need to install the package piwik/device-detector to use this provider' in ..
As the title says. If the package is still supported is composer v2 support planned?
To solve the generics problem from ThaDafinser/UserAgentParserComparison#19
we should create something abstract to filter default/generic values.
Currently we have those variations:
https://github.com/ThaDafinser/UserAgentParser/blob/master/src/Provider/AbstractProvider.php
https://github.com/ThaDafinser/UserAgentParser/blob/master/src/Provider/Wurfl.php#L64-L66
https://github.com/ThaDafinser/UserAgentParser/blob/master/src/Provider/BrowscapPhp.php#L103-L115
https://github.com/ThaDafinser/UserAgentParser/blob/master/src/Provider/Wurfl.php#L142-L166
We change the possible values of $defaultValues to
namespace UserAgentParser\Provider;
class PiwikDeviceDetector extends AbstractProvider
{
protected $defaultValues = [
DeviceDetector::UNKNOWN,
// bot names
'Bot',
'Generic Bot',
];
}
namespace UserAgentParser\Provider;
class PiwikDeviceDetector extends AbstractProvider
{
protected $defaultValues = [
'general' => [
'/^' . DeviceDetector::UNKNOWN . '$/'
],
'bot' => [
'name' => [
'/^Bot$/',
'/^Generic Bot$/'
]
]
];
}
This package requires thadafinser/package-info
but does not appear to use it. Am I missing something?
$ composer require thadafinser/user-agent-parser
Using version ^0.1.0 for thadafinser/user-agent-parser
./composer.json has been created
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
- Installation request for thadafinser/user-agent-parser ^0.1.0 -> satisfiable by thadafinser/user-agent-parser[v0.1.0].
- thadafinser/user-agent-parser v0.1.0 requires browscap/browscap-php dev-master -> 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.
The used properties win32
and win64
are true only for Windows. If tyou want to detect also other platforms, use the platform_bits
property.
The platform version can be detected with the platform_version
property.
The device brand can be detected with the device_brand_name
property.
The device model can be detected with the device_name
property.
To detect the device properties you need the full_php_browscap.ini
file.
We have true 100% code coverage in case of unittests, but the providers are all mocked.
So we need to add some tests, which check with the lowest and highest supported version of the provider, if they still work.
Any good ideas, how to implement this right?
BrowscapPhp:
SinergiBrowserDetector:
Wurfl:
It would be great if information about the bit-width of the operating system could be included. Several of the providers give this information, so it shouldn't be too hard to do :)
add integration tests with special characters which cover the escaping works.
Add the type + bot detection
field: user_agent_type
browser
mobile
ebook_reader
crawler
analyser
tool
tv
mediaplayer
gamesystem
library
unknown
I've created a separate Composer package the tests I run for WhichBrowser. The package is called whichbrowser/testrunner
and includes the runner.php script and all the yaml files. It is automatically updated whenever there is a new release of WhichBrowser.
If you want I can probably create a pull request for the actual extracting of the UA strings.
But it is also possible to extract it by using the runner.php script from the command line:
php vendor/whichbrowser/testrunner/runner.php list
or
php vendor/whichbrowser/testrunner/runner.php list television
or
php vendor/whichbrowser/testrunner/runner.php list mobile tablet television gaming
The target of this project is wherever one or more of the following:
...for now it's just a prototype:
php tests/test.php
for the matrix//cc @sgiehl could i use the Piwik-DeviceDetector
fixtures (https://github.com/piwik/device-detector/tree/master/Tests/fixtures) to generate matrix with all provider results?
WhichBrowser adds the nickname of the OS release before the version number. So the version is "Yosemite 10.10" and not just "10.10". UserAgentParser interprets this as "0.10".
This also happens with many other libraries with versions like "XP" for Windows XP. It is interpreted by UserAgentParser as "0".
See for example:
http://useragent.mkf.solutions/?userAgent=Microsoft+Office%2F14.0+%28Windows+NT+5.1%3B+Microsoft+Outlook+14.0.4536%3B+Pro%3B+MSOffice+14%29
The function getParts()
should probably skip over any non digit characters in the version string before splitting it into parts.
Also when setComplete()
is called, it first stores the original string as the $complete
property, then hydrates all the parts. But the hydrateVersionParts()
function calls setMajor()
, setMinor()
and setPatch()
which in turn call calculateComplete()
which overwrites the original $complete
property that was initially set. This means the original string calculated by the parser is lost.
crossjoin/Browscap is a UA parser, who uses the browscap.ini too, but is faster and requires lower amout of RAM. Actually only a file cache is supported. The browscap-php library has adopted a lot of features from it.
Hello @mimmi20 (sorry to ping again)
i start now to finalize the BrowscapPhp provider.
Could you maybe check if i missed here something, or done something wrong in the implementation?
https://github.com/ThaDafinser/UserAgentParser/blob/master/src/Provider/BrowscapPhp.php
For testing i create a small browscap.ini
file and used it in the tests.
https://github.com/ThaDafinser/UserAgentParser/blob/master/tests/fixtures/browscap.ini
Is this fine or do i need to mock i further?
https://github.com/ThaDafinser/UserAgentParser/blob/master/tests/unit/Provider/BrowscapPhpTest.php#L41
Use instead reflection like here: https://github.com/ThaDafinser/UserAgentParser/pull/20/files
Hello,
Thank you for this great package.
I notice one of your dependencies, piwik/device-detector, is abandoned: https://packagist.org/packages/piwik/device-detector
Their maintainer advices to use https://packagist.org/packages/matomo/device-detector instead.
Do you consider update your package with it?
Thank you
Jourdan
Currently requires PHP ~5.6|~7.0
. It'd be nice if we could use this with the latest PHP 8 release. There ain't many breaking changes, shouldn't be complicated (if this project is still alive).
Instead of doing this
if ($this->isRealResult($deviceRaw->model, 'device', 'model') === true) {
$device->setModel($deviceRaw->model);
}
Do this and return null
if it's not a valid value
$device->setModel($this->getRealResult($deviceRaw->model, 'device', 'model'));
There are some providers where the value is not always available - there we still need a isset()
if check before that
@NielsLeenheer i added now unitTests for all providers, but WhichBrowser
fails on PHP7.
I excluded now PHP7 temporary, that the tests can pass here.
Do you have any plans for PHP7 compability?
https://travis-ci.org/ThaDafinser/UserAgentParser/jobs/90565282#L284
Each provider has it's own device types..
https://github.com/browscap/browscap/wiki/Resource:-Device-Database#device_type
Console
TV Device
Tablet
Mobile Phone
Mobile Device
Desktop
Ebook Reader
Car Entertainment System
Digital Camera
https://github.com/piwik/device-detector/blob/master/Parser/Device/DeviceParserAbstract.php#L42-L54
protected static $deviceTypes = array(
'desktop' => self::DEVICE_TYPE_DESKTOP,
'smartphone' => self::DEVICE_TYPE_SMARTPHONE,
'tablet' => self::DEVICE_TYPE_TABLET,
'feature phone' => self::DEVICE_TYPE_FEATURE_PHONE,
'console' => self::DEVICE_TYPE_CONSOLE,
'tv' => self::DEVICE_TYPE_TV,
'car browser' => self::DEVICE_TYPE_CAR_BROWSER,
'smart display' => self::DEVICE_TYPE_SMART_DISPLAY,
'camera' => self::DEVICE_TYPE_CAMERA,
'portable media player' => self::DEVICE_TYPE_PORTABLE_MEDIA_PAYER,
'phablet' => self::DEVICE_TYPE_PHABLET
);
Can be some of those: https://raw.githubusercontent.com/ua-parser/uap-core/master/regexes.yaml
Generic Tablet
Generic Smartphone
Generic Feature Phone
Spider
https://github.com/WhichBrowser/WhichBrowser/blob/master/libraries/whichbrowser.php#L30-L48
define ('TYPE_DESKTOP', 'desktop');
define ('TYPE_MOBILE', 'mobile');
define ('TYPE_DECT', 'dect');
define ('TYPE_TABLET', 'tablet');
define ('TYPE_GAMING', 'gaming');
define ('TYPE_EREADER', 'ereader');
define ('TYPE_MEDIA', 'media');
define ('TYPE_HEADSET', 'headset');
define ('TYPE_WATCH', 'watch');
define ('TYPE_EMULATOR', 'emulator');
define ('TYPE_TELEVISION', 'television');
define ('TYPE_MONITOR', 'monitor');
define ('TYPE_CAMERA', 'camera');
define ('TYPE_SIGNAGE', 'signage');
define ('TYPE_WHITEBOARD', 'whiteboard');
define ('TYPE_GPS', 'gps');
define ('TYPE_CAR', 'car');
define ('TYPE_POS', 'pos');
define ('TYPE_BOT', 'bot');
class DataSet
{
const DATASET_CATEGORY_PC = 'pc';
const DATASET_CATEGORY_SMARTPHONE = 'smartphone';
const DATASET_CATEGORY_MOBILEPHONE = 'mobilephone';
const DATASET_CATEGORY_CRAWLER = 'crawler';
const DATASET_CATEGORY_APPLIANCE = 'appliance';
const DATASET_CATEGORY_MISC = 'misc';
}
form_factor
Desktop
App
Tablet
Smartphone
Feature Phone
Smart-TV
Robot
Other non-Mobile
Other Mobile
https://github.com/yzalis/UAParser/blob/master/src/UAParser/Result/DeviceResult.php#L111-L113
mobile
tablet
desktop
The required vendor section should be moved to optional https://github.com/ThaDafinser/UserAgentParser/blob/master/composer.json#L51
https://github.com/serbanghita/Mobile-Detect
They are working on a complete detection here...wait for this?
https://github.com/serbanghita/Mobile-Detect/tree/devel-3#getting-started
When a UA is tested on the web, the UA is cutted if the UA conains a "
.
Sample UA: Mozilla/5.0 (Linux; Android 5.1; Alba 7" Build/LMY47I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Safari/537.36
Hello together,
i create this prototype project in order to try out the different UserAgent parsers available for PHP.
First i wanted to try if it's currently possible to create an abstract result set, like it's done for GeoIP already https://github.com/geocoder-php/Geocoder
Second i wanted to have a Chain Adapter on top it to get results from different vendors to get better results https://github.com/ThaDafinser/UserAgentParser/blob/master/bin/generateMatrix.php#L45-L53
Last but not least i wanted to compare the different implementations - how complete and good are they?
At this stage the results of the comparison are not completed, since some vendor adapter will be not complete or have errors.
But i still wanted to share those results to you all, to get (hopefully) some feedback about your Adapter implementation and get improvements https://github.com/ThaDafinser/UserAgentParser/tree/master/src/Provider
Download the HTML files from here and open it just in a browser https://github.com/ThaDafinser/UserAgentParser/tree/master/data/results
It should look like this screenshot.
Click on "toggle" to see the original data and the result detail
I currently did not used datasets from each vendor, so the comparison is not fair currently. (and of course missing convertions or errors)
Better would be an additional independent list...need to find a good source first
I hope it's ok to ping you all ...if not just tell me and i wont do it again ๐
@mimmi20
@donatj
@sgiehl
@lstrojny
@NielsLeenheer
@yuya-takeyama
@blaugueux
You can try to add nice dumper (https://packagist.org/packages/raulfraile/ladybug) for your live demonstration: http://useragent.mkf.solutions/
There are a lot of free and paid cloud services around.
Implement at least 1 or 2 of them to get started
In order to be able to deploy the library in various environments, it would be better to check if the primitive functions/classes of the different providers are present instead of checking if the package has been deployed in a specific vendor directory.
Even if it's a best practice to put external libraries in a vendor directory, all projects don't respect it and can't deploy your great library.
I created a pull request for the DonatjUAParser Provider : #60
Let me know if it makes sense to you
We remove currently some generics in various providers, to prevent the user from "false positive" detection results.
This plays also really well with the chain, since only then the next provider has the chance to give "good results"
But maybe some need to disabled this and want the original results at all time?
Is this project still alive? On the test page I see tat the underlying data was not update since over two years... what looks like a "project dead" indicator to me...
Hi,
I a using the latest version of this library. Now theres an issue. Not sure if its a bug.
I already have this library installed PiwikDeviceDetector
but i keep getting the following exception error. You need to install the package piwik/device-detector to use this provider
. I have done all i could to debug but i can seem to find a solution. The only one is to comment out the following:
public function __construct(DeviceDetector $parser = null)
{
if ($parser === null && ! file_exists('vendor/' . $this->getPackageName() . '/composer.json')) {
Icommented this line - // throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider');
}
$this->parser = $parser;
}
I moved the requested library into the vendor/
directory as its supposed to, but it didn't solve either.
I am on windows and it doesn't allow this kind of file naming structure piwik/device-detector
, because i believe this is the directory that is being looked, and since it can not be located, an error is thrown.
Any suggestions?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.