From 117aa33979c5f84850ec38b989f9570d9895640e Mon Sep 17 00:00:00 2001 From: Zacchaeus Bolaji Date: Wed, 20 Nov 2019 16:14:01 +0100 Subject: [PATCH 1/3] Added mobile detection --- README.md | 19 +++++++++++++++++++ composer.json | 5 +++-- src/Identify.php | 19 ++++++++++++++++++- tests/IdentifyTest.php | 9 +++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c21caff..6a2c003 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,25 @@ The language method allows you to detect a user's language. Identify::lang()->getLanguage() ``` +## Mobile Detection + +The mobile method allows you to detect if user is on mobile. + +### Usage + +```php +/** + * Returns true if any type of mobile device detected, including special ones + * @return boolean + */ +Identify::mobile()->isMobile() + +/** + * Return true if any type of tablet device is detected. + * @return boolean + */ +Identify::mobile()->isTablet() +``` ## Contributing diff --git a/composer.json b/composer.json index 4b10046..ec0ec50 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,10 @@ "require": { "php": ">=7.1.3", "illuminate/support": "~5.7.0|~5.8.0", - "sinergi/browser-detector": "6.1.*" + "sinergi/browser-detector": "6.1.*", + "mobiledetect/mobiledetectlib": "^2.8" }, - "require-dev": { + "require-dev": { "phpunit/phpunit": "~6.0.0", "mockery/mockery": "0.9.*", "scrutinizer/ocular": "~1.1", diff --git a/src/Identify.php b/src/Identify.php index 4b47f19..63fb908 100644 --- a/src/Identify.php +++ b/src/Identify.php @@ -30,6 +30,12 @@ class Identify { */ protected $language; + /** + * Store the mobile object + * @var object + */ + protected $mobile; + /** * Create an Instance of Browser and Os */ @@ -39,6 +45,7 @@ public function __construct() $this->device = new Device(); $this->browser = new Browser(); $this->language = new Language(); + $this->mobile = new \Mobile_Detect(); } /** @@ -81,4 +88,14 @@ public function lang() : Language return $this->language; } -} \ No newline at end of file + /** + * Get all the methods applicable to Mobile detection + * e.g isMobile() + * @return \Mobile_Detect + */ + public function mobile() : \Mobile_Detect + { + return $this->mobile; + } + +} diff --git a/tests/IdentifyTest.php b/tests/IdentifyTest.php index 805a058..d9c5345 100644 --- a/tests/IdentifyTest.php +++ b/tests/IdentifyTest.php @@ -65,4 +65,13 @@ public function testLanguageIsInitializedOnIdentifyConstruction() { $this->assertInstanceOf(Language::class, $this->identify->lang()); } + + /** + * Test if Mobile returns bool + * + */ + public function testMobileIsInitializedOnIdentifyConstruction() + { + $this->assertInstanceOf(\Mobile_Detect::class, $this->identify->mobile()); + } } From 42d155e7727c403a2e4b2db86796f5d8ca75e2ea Mon Sep 17 00:00:00 2001 From: Zacchaeus Bolaji Date: Wed, 20 Nov 2019 16:15:48 +0100 Subject: [PATCH 2/3] update PHPDoc comment --- .idea/.gitignore | 3 +++ tests/IdentifyTest.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/tests/IdentifyTest.php b/tests/IdentifyTest.php index d9c5345..98d5fc9 100644 --- a/tests/IdentifyTest.php +++ b/tests/IdentifyTest.php @@ -67,7 +67,7 @@ public function testLanguageIsInitializedOnIdentifyConstruction() } /** - * Test if Mobile returns bool + * Test if MobileDetect is constructed on Identify Object created * */ public function testMobileIsInitializedOnIdentifyConstruction() From 2e07b79689c65459febebf5c788138755d607a28 Mon Sep 17 00:00:00 2001 From: Zacchaeus Bolaji Date: Wed, 20 Nov 2019 16:16:09 +0100 Subject: [PATCH 3/3] update PHPDoc comment --- .idea/.gitignore | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 0e40fe8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ - -# Default ignored files -/workspace.xml \ No newline at end of file