Permalink
Browse files

Update exportToJSON.php (#576)

just a little refactoring using file_put_contents implementation instead
  • Loading branch information...
1 parent ccbd8d4 commit a5d5e10db3c299f3de598e6b11a45c83190959f7 @PabloJoan PabloJoan committed with Nov 10, 2016
Showing with 32 additions and 35 deletions.
  1. +32 −35 export/exportToJSON.php
@@ -26,45 +26,42 @@
$detect = new Mobile_Detect;
$json = array(
- // The current version of Mobile Detect class that
- // is being exported.
- 'version' => $detect->getScriptVersion(),
+ // The current version of Mobile Detect class that
+ // is being exported.
+ 'version' => $detect->getScriptVersion(),
- // All headers that trigger 'isMobile' to be 'true',
- // before reaching the User-Agent match detection.
- 'headerMatch' => $detect->getMobileHeaders(),
+ // All headers that trigger 'isMobile' to be 'true',
+ // before reaching the User-Agent match detection.
+ 'headerMatch' => $detect->getMobileHeaders(),
- // All possible User-Agent headers.
- 'uaHttpHeaders' => $detect->getUaHttpHeaders(),
+ // All possible User-Agent headers.
+ 'uaHttpHeaders' => $detect->getUaHttpHeaders(),
- // All the regexes that trigger 'isMobile' or 'isTablet'
- // to be true.
- 'uaMatch' => array(
- // If match is found, triggers 'isMobile' to be true.
- 'phones' => $detect->getPhoneDevices(),
- // Triggers 'isTablet' to be true.
- 'tablets' => $detect->getTabletDevices(),
- // If match is found, triggers 'isMobile' to be true.
- 'browsers' => $detect->getBrowsers(),
- // If match is found, triggers 'isMobile' to be true.
- 'os' => $detect->getOperatingSystems(),
- // Various utilities. To be further discussed.
- 'utilities' => $detect->getUtilities()
- )
+ // All the regexes that trigger 'isMobile' or 'isTablet'
+ // to be true.
+ 'uaMatch' => array(
+ // If match is found, triggers 'isMobile' to be true.
+ 'phones' => $detect->getPhoneDevices(),
+ // Triggers 'isTablet' to be true.
+ 'tablets' => $detect->getTabletDevices(),
+ // If match is found, triggers 'isMobile' to be true.
+ 'browsers' => $detect->getBrowsers(),
+ // If match is found, triggers 'isMobile' to be true.
+ 'os' => $detect->getOperatingSystems(),
+ // Various utilities. To be further discussed.
+ 'utilities' => $detect->getUtilities()
+ )
+);
- );
-
-$jsonString = function_exists('json_format') ? json_format($json) : json_encode($json);
-
-// Write the JSON file to disk.
-// You can import this file in your app.
$fileName = dirname(__FILE__).'/../Mobile_Detect.json';
-$handle = fopen($fileName, 'w');
-$fwrite = fwrite($handle, $jsonString);
-fclose($handle);
-
-if($fwrite){
+// Write the JSON file to disk.11
+// You can import this file in your app.
+if (file_put_contents(
+ $fileName,
+ function_exists('json_format') ? json_format($json) : json_encode($json)
+)) {
echo 'Done. Check '.realpath($fileName).' file.';
-} else {
+}
+else {
echo 'Failed to write '.realpath($fileName).' to disk.';
-}
+}

0 comments on commit a5d5e10

Please sign in to comment.