#!/usr/bin/env php 
<?php 
 
require_once __DIR__ . '/../bootstrap/client.php'; 
 
const SUPPORTED_VERSION = '1.0.0'; 
 
$usage = 'usage: ' . PHP_EOL . 
    '    ' . basename(__FILE__) . ' <host>' . PHP_EOL; 
 
execute(function () use ($baseUrl, $command, $values) { 
 
    throwExceptionIfInvalidNumberOfValuesWasProvided($values, 1); 
 
    list($host) = extractValues($values); 
 
    throwExceptionIfValueIsInvalid($host, 'host'); 
 
    $url                = '/version'; 
    $lines              = $command->get($host, $url); 
    $versionAvailable   = (count($lines) > 0); 
 
    if ($versionAvailable) { 
        $version            = json_decode($lines[0]); 
        $isSupportedVersion = ($version === SUPPORTED_VERSION); 
 
        if ($isSupportedVersion) { 
            echo 'ok' . PHP_EOL; 
        } else { 
            echo var_export($version, true) . ' is not supported' . PHP_EOL; 
        } 
    } else { 
        echo 'no version returned' . PHP_EOL; 
    } 
}, $usage); 
 
 |