PHP Classes

File: configuration/setup

Recommend this page to a friend!
  Classes of nvb   PHP Unique Number Repository   configuration/setup   Download  
File: configuration/setup
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: 1,545 bytes
 

Contents

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

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


$usage = 'usage: ' . PHP_EOL .
   
' ' . basename(__FILE__) . ' <authentication token>' . PHP_EOL;

execute(function () use ($values) {

   
throwExceptionIfInvalidNumberOfValuesWasProvided($values, 1);

    list(
$token) = extractValues($values);
   
$tokenAsChecksum = sha1($token);

   
throwExceptionIfValueIsInvalid($token, 'authentication token');

   
$path = __DIR__;
   
$files = array(
       
'client.local.php',
       
'server.local.php'
   
);

    foreach (
$files as $file) {
       
$filePath = $path . '/' . $file;
       
$fileDoesNotExist = (!file_exists($filePath));

        if (
$fileDoesNotExist) {
           
$couldNotCreateFile = (!copy($filePath . '.dist', $filePath));

            if (
$couldNotCreateFile) {
                throw new
Exception(
                   
'could not file "' . $filePath . '"'
               
);
            }
        }

       
$lines = PHP_EOL .
           
'//added on ' . date('Y-m-d H:i:s') . ' by ' . basename(__FILE__) . PHP_EOL .
           
'$token = \'' . $tokenAsChecksum . '\'; //sha1(\'' . $token . '\')';

       
$contentWasAdded = (false !==file_put_contents($filePath, $lines . PHP_EOL, FILE_APPEND));

        if (
$contentWasAdded) {
            echo
$file . ' adapted' . PHP_EOL;
        } else {
            throw new
Exception(
               
'could not write into file "' . $filePath . '"'
           
);
        }
    }

    echo
'done' . PHP_EOL;
},
$usage);