|  | 
| 2 | 2 | 
 | 
| 3 | 3 | namespace DivineOmega\HCLParser; | 
| 4 | 4 | 
 | 
|  | 5 | +/** | 
|  | 6 | + * Class Installer | 
|  | 7 | + * @package DivineOmega\HCLParser | 
|  | 8 | + */ | 
| 5 | 9 | abstract class Installer | 
| 6 | 10 | { | 
|  | 11 | + /** | 
|  | 12 | + * json2hcl Version we want to use | 
|  | 13 | + * @see https://github.com/kvz/json2hcl/releases | 
|  | 14 | + */ | 
|  | 15 | + const JSON2HCL_VERSION = '0.0.6'; | 
|  | 16 | + | 
|  | 17 | + /** | 
|  | 18 | + * Returns the correct binary filename according to the Operating System and Architecture | 
|  | 19 | + */ | 
|  | 20 | + public static function getBinaryFilename() | 
|  | 21 | + { | 
|  | 22 | + # Defaults | 
|  | 23 | + $osString = 'linux'; | 
|  | 24 | + $architecture = 'amd64'; | 
|  | 25 | + | 
|  | 26 | + # Switch architecture if needed | 
|  | 27 | + if (2147483647 == PHP_INT_MAX) { | 
|  | 28 | + $architecture = '386'; | 
|  | 29 | + } | 
|  | 30 | + | 
|  | 31 | + # Switch Operating System if needed | 
|  | 32 | + switch (TRUE) { | 
|  | 33 | + case stristr(PHP_OS, 'DAR'): | 
|  | 34 | + $osString = 'darwin'; | 
|  | 35 | + break; | 
|  | 36 | + case stristr(PHP_OS, 'WIN'): | 
|  | 37 | + $osString = 'windows'; | 
|  | 38 | + break; | 
|  | 39 | + } | 
|  | 40 | + | 
|  | 41 | + return sprintf('json2hcl_v%s_%s_%s',self::JSON2HCL_VERSION, $osString, $architecture); | 
|  | 42 | + } | 
|  | 43 | + | 
| 7 | 44 |  public static function installBinaries() | 
| 8 | 45 |  { | 
| 9 |  | - $binaryUrls = ['https://github.com/kvz/json2hcl/releases/download/v0.0.6/json2hcl_v0.0.6_linux_amd64']; | 
|  | 46 | + $binaryUrls = [ | 
|  | 47 | + sprintf('https://github.com/kvz/json2hcl/releases/download/v%s/%s', self::JSON2HCL_VERSION, self::getBinaryFilename() ) | 
|  | 48 | + ]; | 
| 10 | 49 | 
 | 
| 11 | 50 |  foreach ($binaryUrls as $binaryUrl) { | 
| 12 |  | - $destination = __DIR__.'/../bin/'.basename($binaryUrl); | 
|  | 51 | + $destination = __DIR__ . '/../bin/' . basename($binaryUrl); | 
| 13 | 52 | 
 | 
|  | 53 | + # Skip if file exists | 
| 14 | 54 |  if (file_exists($destination)) { | 
| 15 | 55 |  continue; | 
| 16 | 56 |  } | 
| 17 | 57 | 
 | 
|  | 58 | + # Download | 
| 18 | 59 |  file_put_contents($destination, file_get_contents($binaryUrl)); | 
|  | 60 | + | 
|  | 61 | + # Make executable | 
| 19 | 62 |  chmod($destination, 0755); | 
| 20 | 63 |  } | 
| 21 | 64 |  } | 
|  | 
0 commit comments