Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update mobiledetect/mobiledetectlib compatibility version #214

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
3 changes: 0 additions & 3 deletions .gitattributes

This file was deleted.

4 changes: 0 additions & 4 deletions .github/FUNDING.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .gitignore

This file was deleted.

23 changes: 0 additions & 23 deletions .php_cs

This file was deleted.

24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
Agent
=====

[![Latest Stable Version](http://img.shields.io/packagist/v/jenssegers/agent.svg)](https://packagist.org/packages/jenssegers/agent) [![Total Downloads](http://img.shields.io/packagist/dm/jenssegers/agent.svg)](https://packagist.org/packages/jenssegers/agent) [![Build Status](http://img.shields.io/travis/jenssegers/agent.svg)](https://travis-ci.org/jenssegers/agent) [![Coverage Status](http://img.shields.io/coveralls/jenssegers/agent.svg)](https://coveralls.io/r/jenssegers/agent) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers)

A PHP desktop/mobile user agent parser with support for Laravel, based on [Mobile Detect](https://github.com/serbanghita/Mobile-Detect) with desktop support and additional functionality.

<p align="center">
<img src="https://jenssegers.com/static/media/agent.png" height="275">
</p>

Installation
------------

Install using composer:

```bash
composer require jenssegers/agent
composer require al-saloul/agent
```

Laravel (optional)
Expand All @@ -24,13 +19,13 @@ Laravel (optional)
Add the service provider in `config/app.php`:

```php
Jenssegers\Agent\AgentServiceProvider::class,
Alsaloul\Agent\AgentServiceProvider::class,
```

And add the Agent alias to `config/app.php`:

```php
'Agent' => Jenssegers\Agent\Facades\Agent::class,
'Agent' => Alsaloul\Agent\Facades\Agent::class,
```

Basic Usage
Expand All @@ -39,7 +34,7 @@ Basic Usage
Start by creating an `Agent` instance (or use the `Agent` Facade if you are using Laravel):

```php
use Jenssegers\Agent\Agent;
use Alsaloul\Agent\Agent;

$agent = new Agent();
```
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "jenssegers/agent",
"name": "al-saloul/agent",
"description": "Desktop/mobile user agent parser with support for Laravel, based on Mobiledetect",
"keywords": ["laravel", "useragent", "agent", "user agent", "browser", "platform", "mobile", "desktop"],
"homepage": "https://github.com/jenssegers/agent",
"homepage": "https://github.com/fakeeh/agent",
"license" : "MIT",
"authors": [
{
"name": "Jens Segers",
"homepage": "https://jenssegers.com"
},
{
"name": "Mohammed Al Saloul",
"email": "eng.alsaloul.mohammed@gmail.com"
}
],
"require": {
"php": ">=5.6",
"mobiledetect/mobiledetectlib": "^2.7.6",
"jaybizzle/crawler-detect": "^1.2"
},
"require-dev": {
Expand All @@ -21,7 +24,7 @@
},
"autoload": {
"psr-4": {
"Jenssegers\\Agent\\": "src/"
"Alsaloul\\Agent\\": "src/"
}
},
"extra": {
Expand All @@ -30,10 +33,10 @@
},
"laravel": {
"providers": [
"Jenssegers\\Agent\\AgentServiceProvider"
"Alsaloul\\Agent\\AgentServiceProvider"
],
"aliases": {
"Agent": "Jenssegers\\Agent\\Facades\\Agent"
"Agent": "Alsaloul\\Agent\\Facades\\Agent"
}
}
},
Expand Down
24 changes: 0 additions & 24 deletions phpunit.xml

This file was deleted.

79 changes: 70 additions & 9 deletions src/Agent.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<?php

namespace Jenssegers\Agent;
namespace Alsaloul\Agent;

use BadMethodCallException;
use Jaybizzle\CrawlerDetect\CrawlerDetect;
use Mobile_Detect;

class Agent extends Mobile_Detect
class Agent extends MobileDetect
{
/**
* A type for the version() method indicating a string return value.
*/
private const VERSION_TYPE_STRING = 'text';

/**
* A type for the version() method indicating a float return value.
*/
private const VERSION_TYPE_FLOAT = 'float';

/**
* List of desktop devices.
* @var array
Expand Down Expand Up @@ -76,6 +84,7 @@ class Agent extends Mobile_Detect
'Coc Coc' => 'coc_coc_browser/[VER]',
];


/**
* @var CrawlerDetect
*/
Expand Down Expand Up @@ -106,7 +115,7 @@ public static function getDetectionRulesExtended()
return $rules;
}

public function getRules()
public function getRules(): array
{
if ($this->detectionType === static::DETECTION_TYPE_EXTENDED) {
return static::getDetectionRulesExtended();
Expand All @@ -127,22 +136,37 @@ public function getCrawlerDetect()
return static::$crawlerDetect;
}

public static function getBrowsers()
/**
* Returns an array of all known browsers, including any additional browsers that have been defined.
*
* @return array An array of browser detection rules.
*/
public static function getBrowsers(): array
{
return static::mergeRules(
static::$additionalBrowsers,
static::$browsers
);
}

public static function getOperatingSystems()
/**
* Returns an array of all known operating systems, including any additional operating systems that have been defined.
*
* @return array An array of operating system detection rules.
*/
public static function getOperatingSystems(): array
{
return static::mergeRules(
static::$operatingSystems,
static::$additionalOperatingSystems
);
}

/**
* Returns an array of all known operating systems, including any additional operating systems that have been defined.
*
* @return array An array of operating system detection rules.
*/
public static function getPlatforms()
{
return static::mergeRules(
Expand All @@ -151,12 +175,22 @@ public static function getPlatforms()
);
}

/**
* Returns an array of all known desktop devices.
*
* @return array An array of desktop device detection rules.
*/
public static function getDesktopDevices()
{
return static::$desktopDevices;
}

public static function getProperties()
/**
* Returns an array of all known properties, including any additional properties that have been defined.
*
* @return array An array of property detection rules.
*/
public static function getProperties(): array
{
return static::mergeRules(
static::$additionalProperties,
Expand Down Expand Up @@ -331,7 +365,7 @@ public function deviceType($userAgent = null, $httpHeaders = null)
return "other";
}

public function version($propertyName, $type = self::VERSION_TYPE_STRING)
public function version($propertyName, $type = self::VERSION_TYPE_STRING): float
{
if (empty($propertyName)) {
return false;
Expand Down Expand Up @@ -412,4 +446,31 @@ public function __call($name, $arguments)

return $this->matchUAAgainstKey($key);
}

/**
* Some detection rules are relative (not standard),
* because of the diversity of devices, vendors and
* their conventions in representing the User-Agent or
* the HTTP headers.
*
* This method will be used to check custom regexes against
* the User-Agent string.
*
* @param string $regex
* @param string|null $userAgent
* @return bool
*
* @todo: search in the HTTP headers too.
*/
public function match(string $regex, string $userAgent = null): bool
{
$match = (bool) preg_match(sprintf('#%s#is', $regex), $userAgent, $matches);
// If positive match is found, store the results for debug.
if ($match) {
$this->matchingRegex = $regex;
$this->matchesArray = $matches;
}

return $match;
}
}
2 changes: 1 addition & 1 deletion src/AgentServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Jenssegers\Agent;
namespace Alsaloul\Agent;

use Illuminate\Support\ServiceProvider;

Expand Down
2 changes: 1 addition & 1 deletion src/Facades/Agent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Jenssegers\Agent\Facades;
namespace Alsaloul\Agent\Facades;

use Illuminate\Support\Facades\Facade;

Expand Down
Loading