PHP Classes

File: test_distribution.php

Recommend this page to a friend!
  Classes of Manuel Lemos   PHP Distribution System   test_distribution.php   Download  
File: test_distribution.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Distribution System
Automate the distribution file archive creation
Author: By
Last change:
Date: 4 years ago
Size: 2,169 bytes
 

Contents

Class file image Download
<?php

/*
 * test_distribution.php
 *
 * Script to test the distribution class.
 *
 * @(#) $Id: test_distribution.php,v 1.1 2020/02/14 07:55:37 mlemos Exp $
 *
 */
 
   
require("distribution.php");

   
$file_list = 'test';
   
$archive_file_name = 'distribution.tar.gz';
   
$php_command = 'php';
   
   
$distribution = new distribution_class;
   
$action = ((IsSet($_SERVER['argv']) && IsSet($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '');
    switch(
$action)
    {
        case
'distribution':
        case
'';
           
$file_list_name=tempnam('','DistributionFileList');
            if(!(
$file_list = fopen($file_list_name, 'w')))
                exit(
'could not open the distribution temporary file list'."\n");
           
$error = $distribution->DumpFileList("./", $file_list, true);
           
fclose($file_list);
            if(
strlen($error))
                exit(
$error."\n");
           
Exec('tar -hcT '.$file_list_name.' | gzip >'.$archive_file_name, $output, $result);
           
unlink($file_list_name);
            if(
$result)
                exit(
'could not make the distribution archive file'."\n");
            break;

        case
'check':
            if(
strlen($error = $distribution->ListFiles('./', $file_list, true)))
                exit(
$error."\n");
           
$missing = $invalid = array();
            foreach(
$file_list as $file_name)
            {
                if(!
file_exists($file_name))
                   
$missing[] = $file_name;
                elseif(
preg_match('/\\.php$/', $file_name))
                {
                   
$output = array();
                   
Exec($php_command.' -l '.$file_name, $output, $result);
                    if(
$result)
                       
$invalid[$file_name] = implode("\n", $output);
                }
            }
            break;

        default:
            exit(
$action.' is not a supported distribution action'."\n");
    }

    switch(
$action)
    {
        case
'distribution':
        case
'':
            echo
'Distribution archive file ', $archive_file_name, ' build ok: ', filesize($archive_file_name), ' bytes.', "\n";
            break;
        case
'check':
            echo
'Total files: ', count($file_list), ' Missing: ', count($missing), ' Invalid: ', count($invalid), "\n";
            if(
count($missing))
            {
                    echo
'Missing files:', "\n";
                    foreach(
$missing as $missing)
                        echo
$missing, "\n";
            }
            if(
count($invalid))
            {
                    echo
'Invalid files:', "\n";
                    foreach(
$invalid as $file_name => $error)
                        echo
$file_name, "\n", $error, "\n";
            }
            break;
    }
?>