PHP Classes

File: client/list-repositories

Recommend this page to a friend!
  Classes of nvb   PHP Unique Number Repository   client/list-repositories   Download  
File: client/list-repositories
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: 4 years ago
Size: 905 bytes
 

Contents

Class file image Download
#!/usr/bin/env php
<?php

require_once __DIR__ . '/../bootstrap/client.php';

$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 = $baseUrl;
   
$lines = $command->get($host, $url);
   
$repositoriesAvailable = ((is_array($lines) && (count($lines) > 0)));

    if (
$repositoriesAvailable) {
        foreach (
$lines as $line) {
           
$data = json_decode($line);
            echo
'[name]' . PHP_EOL;
            foreach (
$data as $repository) {
                echo
$repository->name . PHP_EOL;
            }
        }
    } else {
        echo
'no repository available' . PHP_EOL;
    }
},
$usage);