PHP Classes

PHP Distribution System: Automate the distribution file archive creation

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 48 All time: 10,653 This week: 94Up
Version License PHP version Categories
distribution 1.0BSD License5PHP 5, Tools, Files and Folders
Description 

Author

This class can be used to automate the distribution file archive creation.

It can recursively traverse the current directory or any other directory for distribution files that contain a list of file names or sub-directories to also be traversed.

The class returns an array of all files that were found in the distribution file lists so it can be used to create distribution archives of test the files in the distribution before they are posted.

Picture of Manuel Lemos
  Performance   Level  
Name: Manuel Lemos is available for providing paid consulting. Contact Manuel Lemos .
Classes: 45 packages by
Country: Portugal Portugal
Age: 55
All time rank: 1
Week rank: 2 Down1 in Portugal Portugal Equal

Example

<?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;
    }
?>


  Files folder image Files  
File Role Description
Plain text file distribution.php Class Distribution class
Accessible without login Plain text file test_distribution.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:48
This week:0
All time:10,653
This week:94Up