File: client/check-version

Recommend this page to a friend!
  Classes of nvb  >  PHP Unique Number Repository  >  client/check-version  >  Download  
File: client/check-version
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Unique Number Repository
Maintain repositories of unique numbers via an API
Author: By
Last change:
Date: 1 year ago
Size: 957 bytes
 

Contents

Class file image Download
#!/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);


For more information send a message to info at phpclasses dot org.