This repository has been archived by the owner on Nov 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve documentation with examples.
Correctly instantiate \HandsetDetection\HD4 singleton.
- Loading branch information
Richard Uren
committed
Jun 7, 2016
1 parent
6edeff6
commit 63a0e39
Showing
2 changed files
with
43 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,53 +2,55 @@ | |
|
||
A minimal service provider to set up and use the Handset Detection 4.x PHP library in Laravel v5.1 LTS. | ||
|
||
## How it works ## | ||
|
||
This package contains a service provider, which binds an instance of an initialized HandsetDetection client to the IoC-container. | ||
You receive the HandsetDetection client through dependency injection. | ||
|
||
## Usage example ## | ||
|
||
class HandsetDetectionManager | ||
{ | ||
protected $handsetdetection; | ||
|
||
/** | ||
* Pull the HandsetDetection-instance from the IoC-container. | ||
*/ | ||
public function __construct(\HandsetDetection $handsetdetection) | ||
{ | ||
$this->handsetdetection = $handsetdetection; | ||
} | ||
|
||
/** | ||
* Access the handsetdetection API | ||
* See this link for more API info https://handsetdetection.readme.io/v4/docs | ||
* | ||
* @param array $headers An assoc array of HTTP headers or device Build Information. | ||
* @param array A device profile on success or null otherwise. | ||
*/ | ||
public function detect($headers) | ||
{ | ||
$reply = null; | ||
try { | ||
$reply = $this->handsetdetection->deviceDetect($headers); | ||
} catch (\Exception $e) { | ||
// do something | ||
} | ||
return $reply; | ||
} | ||
/** | ||
* Where $httpHeaders is a key=>value array of headers, for example : | ||
* array( | ||
* 'user-agent' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; fr_FR) AppleWebKit (KHTML, like Gecko) Mobile" | ||
* ) | ||
**/ | ||
$hd = App('HandsetDetection'); | ||
$hd->deviceDetect($httpHeaders); | ||
|
||
Call any of the Handset Detection 4.x PHP library methods in this same fashion. Additional examples at [PHP APIKit Home](https://github.com/HandsetDetection/php-apikit "Handset Detection PHP APIKit") . | ||
|
||
$hd->deviceVendors(); | ||
$hd->deviceModels('Nokia'); | ||
$hd->deviceWhatHas('network', 'EDGE'); | ||
$hd->deviceFetchArchive(); | ||
$hd->communityFetchArchive(); | ||
|
||
Here's a snippet that ties it all together with a few sample detections. | ||
|
||
$data = array ( | ||
array ( | ||
'user-agent' => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" | ||
), | ||
array ( | ||
'user-agent' => "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; SAMSUNG-SGH-I577 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" | ||
), | ||
array ( | ||
'user-agent' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; fr_FR) AppleWebKit (KHTML, like Gecko) Mobile [FBAN/FBForIPhone;FBAV/4.0.2;FBBV/4020.0;FBDV/iPhone3,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/4.3.3;FBSS/2; FBCR/TELUS;FBID/phone;FBLC/fr_FR;FBSF/2.0]" | ||
), | ||
array ( | ||
'user-agent' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; fr_FR) AppleWebKit (KHTML, like Gecko) Mobile", | ||
'x-local-hardwareinfo' => "480:320:275:200" | ||
) | ||
); | ||
|
||
$hd = App('HandsetDetection'); | ||
foreach ($data as $headers) { | ||
$return = $hd->deviceDetect($headers); | ||
$reply = $hd->getReply(); | ||
$this->info(json_encode($reply)); | ||
} | ||
|
||
Or, manually instantiate the client by using: | ||
|
||
$handsetdetection = app('HandsetDetection'); | ||
|
||
## Setup ## | ||
|
||
### Step 1: Adding the dependency to composer.json ### | ||
|
||
Add this to your composer.json. | ||
Add this to your composer.json. This will also fetch | ||
|
||
"require": { | ||
"handsetdetection/laravel51-provider": "1.*", | ||
|
@@ -72,6 +74,7 @@ This will publish config/handsetdetection.php to your config folder. | |
|
||
Place your Handset Detection access credentials in the config file. | ||
|
||
|
||
Job Done. | ||
|
||
Let us know if you have any hassles : [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters