Skip to content

Commit

Permalink
Merge pull request #24 from xpanel/main
Browse files Browse the repository at this point in the history
uptdate to mobiledetectlib 4.8
  • Loading branch information
tattali authored Dec 20, 2024
2 parents 5225a11 + b42e6b0 commit 4c90b8e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MobileDetectBundle
==================

Symfony 3.4.x-6.0.x bundle to detect mobile devices, manage mobile view and redirect to the mobile and tablet version.
Symfony 7 bundle to detect mobile devices, manage mobile view and redirect to the mobile and tablet version.

[![Github Actions Status](https://github.com/tattali/MobileDetectBundle/actions/workflows/main.yml/badge.svg?branch=main
)](https://github.com/tattali/MobileDetectBundle/actions/workflows/main.yml?query=branch%3Amain) [![Latest Stable Version](http://poser.pugx.org/tattali/mobile-detect-bundle/v)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![Total Downloads](http://poser.pugx.org/tattali/mobile-detect-bundle/downloads)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![codecov](https://codecov.io/gh/tattali/MobileDetectBundle/branch/main/graph/badge.svg?token=HWV1OYRSD9)](https://codecov.io/gh/tattali/MobileDetectBundle) [![License](http://poser.pugx.org/tattali/mobile-detect-bundle/license)](https://packagist.org/packages/tattali/mobile-detect-bundle) [![PHP Version Require](http://poser.pugx.org/tattali/mobile-detect-bundle/require/php)](https://packagist.org/packages/tattali/mobile-detect-bundle)
Expand Down
32 changes: 16 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@
}
],
"require": {
"php": ">=8.2",
"mobiledetect/mobiledetectlib": "^2.8.15",
"symfony/dependency-injection": "^7.0",
"symfony/event-dispatcher": "^7.0",
"symfony/framework-bundle": "^7.0",
"symfony/yaml": "^7.0",
"twig/twig": "^2.0 || ^3.0"
"php": ">=8.2.9",
"mobiledetect/mobiledetectlib": "^4.8",
"symfony/dependency-injection": "^7.1",
"symfony/event-dispatcher": "^7.1",
"symfony/framework-bundle": "^7.1",
"symfony/yaml": "^7.1",
"twig/twig": "^3.14"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.8",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-nette": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6",
"symfony/dotenv": "^7.0",
"symfony/phpunit-bridge": "^7.0"
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan-nette": "^1.3",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.4",
"squizlabs/php_codesniffer": "^3.10",
"symfony/dotenv": "^7.1",
"symfony/phpunit-bridge": "^7.1"
},
"config": {
"sort-packages": true,
Expand Down
2 changes: 1 addition & 1 deletion src/DataCollector/DeviceDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(DeviceView $deviceView)
public function collect(
Request $request,
Response $response,
\Throwable $exception = null
?\Throwable $exception = null
): void {
$this->data['currentView'] = $this->deviceView->getViewType();
$this->data['views'] = [
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/MobileDetectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Extension\Extension;

class MobileDetectExtension extends Extension
{
Expand Down
3 changes: 2 additions & 1 deletion src/DeviceDetector/MobileDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
*/

namespace MobileDetectBundle\DeviceDetector;
use Detection\MobileDetect;

/**
* @author suncat2000 <nikolay.kotovsky@gmail.com>
*/
class MobileDetector extends \Mobile_Detect implements MobileDetectorInterface
class MobileDetector extends MobileDetect implements MobileDetectorInterface
{
}
54 changes: 27 additions & 27 deletions src/DeviceDetector/MobileDetectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,35 +216,35 @@ interface MobileDetectorInterface
*
* @throws \BadMethodCallException when the method doesn't exist and doesn't start with 'is'
*/
public function __call($name, $arguments);
public function __call(string $name, array $arguments);

/**
* Retrieve the list of known browsers. Specifically, the user agents.
*
* @return array list of browsers / user agents
*/
public static function getBrowsers();
public static function getBrowsers(): array;

/**
* Retrieve the list of mobile operating systems.
*
* @return array the list of mobile operating systems
*/
public static function getOperatingSystems();
public static function getOperatingSystems(): array;

/**
* Retrieve the list of known phone devices.
*
* @return array list of phone devices
*/
public static function getPhoneDevices();
public static function getPhoneDevices(): array;

/**
* Get the properties array.
*
* @return array
*/
public static function getProperties();
public static function getProperties(): array;

/**
* Get the current script version.
Expand All @@ -254,28 +254,28 @@ public static function getProperties();
*
* @return string the version number in semantic version format
*/
public static function getScriptVersion();
//public static function getScriptVersion(): string;

/**
* Retrieve the list of known tablet devices.
*
* @return array list of tablet devices
*/
public static function getTabletDevices();
public static function getTabletDevices(): array;

/**
* Alias for getBrowsers() method.
*
* @return array list of user agents
*/
public static function getUserAgents();
//public static function getUserAgents(): array;

/**
* Retrieve the list of known utilities.
*
* @return array list of utilities
*/
public static function getUtilities();
//public static function getUtilities(): array;

/**
* Check the HTTP headers for signs of mobile.
Expand All @@ -284,14 +284,14 @@ public static function getUtilities();
*
* @return bool
*/
public function checkHttpHeadersForMobile();
public function checkHttpHeadersForMobile(): bool;

/**
* Retrieves the cloudfront headers.
*
* @return array
*/
public function getCfHeaders();
//public function getCfHeaders(): array;

/**
* Set CloudFront headers
Expand All @@ -301,7 +301,7 @@ public function getCfHeaders();
*
* @return bool If there were CloudFront headers to be set
*/
public function setCfHeaders($cfHeaders = null);
//public function setCfHeaders(array $cfHeaders = null): bool;

/**
* Retrieves a particular header. If it doesn't exist, no exception/error is caused.
Expand All @@ -313,43 +313,43 @@ public function setCfHeaders($cfHeaders = null);
*
* @return string|null the value of the header
*/
public function getHttpHeader($header);
public function getHttpHeader(string $header): ?string;

/**
* Retrieves the HTTP headers.
*
* @return array
*/
public function getHttpHeaders();
public function getHttpHeaders(): array;

/**
* Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers.
*
* @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract
* the headers. The default null is left for backwards compatibility.
*/
public function setHttpHeaders($httpHeaders = null);
public function setHttpHeaders(array $httpHeaders = []): void;

public function getMatchesArray();
public function getMatchesArray(): ?array;

public function getMatchingRegex();
public function getMatchingRegex(): ?string;

public function getMobileHeaders();
public function getMobileHeaders(): array;

/**
* Get all possible HTTP headers that
* can contain the User-Agent string.
*
* @return array list of HTTP headers
*/
public function getUaHttpHeaders();
public function getUaHttpHeaders(): array;

/**
* Retrieve the User-Agent.
*
* @return string|null the user agent if it's set
*/
public function getUserAgent();
public function getUserAgent(): ?string;

/**
* Set the User-Agent to be used.
Expand All @@ -358,7 +358,7 @@ public function getUserAgent();
*
* @return string|null
*/
public function setUserAgent($userAgent = null);
public function setUserAgent(string $userAgent): string;

/**
* This method checks for a certain property in the
Expand All @@ -368,23 +368,23 @@ public function setUserAgent($userAgent = null);
*
* @return bool|int|null
*/
public function is($key);
public function is(string $ruleName): bool;

/**
* Check if the device is mobile.
* Returns true if any type of mobile device detected, including special ones.
*
* @return bool
*/
public function isMobile();
public function isMobile(): bool;

/**
* Check if the device is a tablet.
* Return true if any type of tablet device is detected.
*
* @return bool
*/
public function isTablet();
public function isTablet(): bool;

/**
* Some detection rules are relative (not standard),
Expand All @@ -399,7 +399,7 @@ public function isTablet();
*
* @return bool
*/
public function match($regex, $userAgent = null);
public function match(string $regex, string $userAgent): bool;

/**
* Prepare the version number.
Expand All @@ -408,7 +408,7 @@ public function match($regex, $userAgent = null);
*
* @return float
*/
public function prepareVersionNo($ver);
public function prepareVersionNo(string $ver): float;

/**
* Check the version of the given property in the User-Agent.
Expand All @@ -423,5 +423,5 @@ public function prepareVersionNo($ver);
*
* @return string|float the version of the property we are trying to extract
*/
public function version($propertyName, $type = MobileDetector::VERSION_TYPE_STRING);
public function version(string $propertyName, string $type = self::VERSION_TYPE_STRING): float|bool|string;
}
2 changes: 1 addition & 1 deletion src/Helper/DeviceView.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class DeviceView
*/
protected $redirectConfig = [];

public function __construct(RequestStack $requestStack = null)
public function __construct(?RequestStack $requestStack = null)
{
if (!$requestStack || !$this->request = $requestStack->getMainRequest()) {
$this->viewType = self::VIEW_NOT_MOBILE;
Expand Down
8 changes: 7 additions & 1 deletion src/Resources/doc/legacy-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ Installation
Composer
--------

### Latest Symfony >= 5.1 || <= 6.4
### Latest Symfony >=7.0

```sh
composer require tattali/mobile-detect-bundle
```

### Latest Symfony >= 5.1 || <= 6.4

```sh
composer require 'tattali/mobile-detect-bundle:2.2.*'
```

### For Symfony >= 3.4 || <= 4.4

```sh
Expand Down

0 comments on commit 4c90b8e

Please sign in to comment.