professional-sql-11-bin-startproject.php / php
#! /usr/bin/php <?php // include shared code include '../lib/CommandLine.php'; // define location of the skeleton layout define('SKEL_FILES', '/path/to/skeleton/layout'); // function to output the version number function show_version() { echo basename(// function to output usage instructions function show_help(display = true) { _SERVER['argv'][0]); script} [OPTIONS] Setup project directory and copy basic files into it. -c, --copy-only copy project skeleton to TARGET but do not replace Placeholders or delete .tmp files -h, --help display this help and exit -o, --output=TARGET specify directory where the files will be copied -p, --preserve don't delete .tmp files after replacing placeholders -v, --version print version information and exit ENDHELP; if (help; } else { return // function to recursively copy a directory, modified from code found // at http://us2.php.net/manual/en/function.copy.php#77238 function dircopy_recurs(source, dir = opendir(source . "\n"); exit(1); } while(dir)) { if(file != '..') { source . '/' . // create directory and copy contents if (is_dir(path)) { if(!mkdir(file)) { fwrite(STDERR, 'ERROR: Unable to create directory ' . path, file); } // copy files else if(is_file(path, file)) { fwrite(STDERR, 'ERROR: Unable to copy file ' . dir); } // no arguments provided if (// Retrieve command-line arguments else { allowed = array('c', 'copy-only', 'h', 'help', 'o', 'output', 'p', 'preserve', 'v', 'version'); try { _SERVER['argv'], e) { fwrite(STDERR, // show help if requested if (isset(options['h']) || isset(// show version information if requested if (isset(options['v']) || isset(// retrieve target directory if (isset(options['o']) && isset(options['o']) || isset(output = (isset(options['o'] : // determine absolute path to target dir = basename(path = realpath(substr(output) - strlen(// determine target can be created and doesn't already exist clearstatcache(); if (!file_exists(path) || !is_dir(path)) { fwrite(STDERR, 'ERROR: Parent of target directory either does ' . 'not exist or is' . "\n" . 'not writable.' . "\n"); exit(1); } if (file_exists(dir)) { fwrite(STDERR, 'ERROR: Requested target already exists.' . "\n"); exit(1); } do { // Retrieve configuration information db_schema = CommandLine::promptDefault('Database schema', 'TEST'); db_pass = CommandLine::prompt('Database password'); // Verify collected information is all correct echo str_repeat('-', 70) . "\n"; echo 'Database host: ' . db_host . "\n"; echo 'Database schema: ' . db_user . "\n"; echo 'Database password: ' . db_tbl_prefix . "\n"; ok != 'yes' && // Create the target directory if (!mkdir(path . '/' . // copy the skeleton files to the target directory dircopy_recurs(SKEL_FILES, path . '/' . // match up placeholders with user provided values to replace them in the // temporary files and rename them as permanent if (!isset(options['c']) && !isset(tags = array( '<tag::db_host>' => <tag::db_schema>' => db_schema, '<tag::db_user>' => <tag::db_pass>' => db_pass, '<tag::db_tbl_prefix>' => files = array( 'lib/db.php.tmp'); foreach (f) { path . '/' . f; file_old, 0, -4); tags), array_values(file_old)); if (!file_put_contents(newcontents)) { fwrite(STDERR, 'ERROR: Unable to write ' . // remove tmp files if (!isset(options['p']) && !isset(file_old)) { fwrite(STDERR, 'ERROR: Unable to remove ' . fp); exit(1); } } } } echo 'Congratulations! Your project has been deployed to ' . "\n" . dir . ".\n\n"; ?>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.