From f065112a33155673b5ac83a85ec08fa38a6c2861 Mon Sep 17 00:00:00 2001 From: Stanislav Ivanov Date: Sun, 30 Aug 2020 21:40:30 +0300 Subject: [PATCH 1/3] Fix double pipe in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 19b2f69..31c2f6b 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": ">=5.5.9", "symfony/framework-bundle": "~2.7|~3.3|~4.0|~5.0", "mobiledetect/mobiledetectlib": "~2.8", - "twig/twig": "~1.26|~2.0||^3.0" + "twig/twig": "~1.26|~2.0|^3.0" }, "require-dev": { "phpunit/phpunit": "^4.8.35|^5.4.3|^6.0", From e6ee22b11a6e563cc44a32ee7821a7971c382aa3 Mon Sep 17 00:00:00 2001 From: Pierrick Date: Tue, 22 Sep 2020 10:24:28 +0200 Subject: [PATCH 2/3] Add DI with autowire --- DeviceDetector/MobileDetector.php | 2 +- DeviceDetector/MobileDetectorInterface.php | 78 ++++++++++++++++++++++ Resources/config/mobile_detect.xml | 3 +- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 DeviceDetector/MobileDetectorInterface.php diff --git a/DeviceDetector/MobileDetector.php b/DeviceDetector/MobileDetector.php index 759c966..02b00db 100644 --- a/DeviceDetector/MobileDetector.php +++ b/DeviceDetector/MobileDetector.php @@ -19,6 +19,6 @@ * @author suncat2000 * */ -class MobileDetector extends MobileDetect +class MobileDetector extends MobileDetect implements MobileDetectorInterface { } diff --git a/DeviceDetector/MobileDetectorInterface.php b/DeviceDetector/MobileDetectorInterface.php new file mode 100644 index 0000000..468b284 --- /dev/null +++ b/DeviceDetector/MobileDetectorInterface.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SunCat\MobileDetectBundle\DeviceDetector; + +use Detection\MobileDetect; + +/** + * MobileDetector class + * + * @author pierrickmartos + * + */ +interface MobileDetectorInterface +{ + /** + * Check if the device is mobile. + * Returns true if any type of mobile device detected, including special ones + * @param null $userAgent deprecated + * @param null $httpHeaders deprecated + * @return bool + */ + public function isMobile($userAgent = null, $httpHeaders = null); + + /** + * Check if the device is a tablet. + * Return true if any type of tablet device is detected. + * + * @param string $userAgent deprecated + * @param array $httpHeaders deprecated + * @return bool + */ + public function isTablet($userAgent = null, $httpHeaders = null); + + /** + * This method checks for a certain property in the + * userAgent. + * @todo: The httpHeaders part is not yet used. + * + * @param string $key + * @param string $userAgent deprecated + * @param string $httpHeaders deprecated + * @return bool|int|null + */ + public function is($key, $userAgent = null, $httpHeaders = null); + + /** + * 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 $regex + * @param string $userAgent + * @return bool + * + * @todo: search in the HTTP headers too. + */ + public function match($regex, $userAgent = null); + + /** + * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants. + * + * @return string One of the self::MOBILE_GRADE_* constants. + */ + public function mobileGrade(); +} diff --git a/Resources/config/mobile_detect.xml b/Resources/config/mobile_detect.xml index 0311b97..609402f 100644 --- a/Resources/config/mobile_detect.xml +++ b/Resources/config/mobile_detect.xml @@ -14,7 +14,8 @@ - + + From d37e6de159250bb6300cd9155fba6a89353e4886 Mon Sep 17 00:00:00 2001 From: Pierrick Date: Tue, 22 Sep 2020 10:26:08 +0200 Subject: [PATCH 3/3] fix comments --- DeviceDetector/MobileDetectorInterface.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/DeviceDetector/MobileDetectorInterface.php b/DeviceDetector/MobileDetectorInterface.php index 468b284..a743bbb 100644 --- a/DeviceDetector/MobileDetectorInterface.php +++ b/DeviceDetector/MobileDetectorInterface.php @@ -11,10 +11,8 @@ namespace SunCat\MobileDetectBundle\DeviceDetector; -use Detection\MobileDetect; - /** - * MobileDetector class + * MobileDetectorInterface interface * * @author pierrickmartos *