Exemple #1
0
function remove($argv)
{
    if (!isset($argv[2])) {
        displayHelp();
        exit;
    }
    $name = $argv[2];
    exec('pwd', $info);
    $curPath = $info[0];
    $parentPath = dirname($curPath);
    $projectPath = $parentPath . '/project/' . $name;
    out("确定删除{$name}项目(y/n)", 'info');
    $line = trim(fgets(STDIN));
    if ($line === 'y') {
        if (file_exists($projectPath)) {
            exec("rm -rf {$projectPath}", $info, $ret);
            if (!$ret) {
                out('删除成功', 'success');
            } else {
                out('删除失败', 'error');
            }
        } else {
            out("{$name}不存在", 'error');
        }
    }
}
/**
 * processes the installer
 */
function process($argv)
{
    // Determine ANSI output from --ansi and --no-ansi flags
    setUseAnsi($argv);
    if (in_array('--help', $argv)) {
        displayHelp();
        exit(0);
    }
    $check = in_array('--check', $argv);
    $help = in_array('--help', $argv);
    $force = in_array('--force', $argv);
    $quiet = in_array('--quiet', $argv);
    $channel = in_array('--snapshot', $argv) ? 'snapshot' : (in_array('--preview', $argv) ? 'preview' : 'stable');
    $disableTls = in_array('--disable-tls', $argv);
    $installDir = getOptValue('--install-dir', $argv, false);
    $version = getOptValue('--version', $argv, false);
    $filename = getOptValue('--filename', $argv, 'composer.phar');
    $cafile = getOptValue('--cafile', $argv, false);
    if (!checkParams($installDir, $version, $cafile)) {
        exit(1);
    }
    $ok = checkPlatform($quiet, $disableTls);
    if (true === $disableTls) {
        out("You have instructed the Installer not to enforce SSL/TLS security on remote HTTPS requests.", 'info');
        out("This will leave all downloads during installation vulnerable to Man-In-The-Middle (MITM) attacks.", 'info');
    }
    if ($check) {
        exit($ok ? 0 : 1);
    }
    if ($ok || $force) {
        installComposer($version, $installDir, $filename, $quiet, $disableTls, $cafile, $channel);
        exit(0);
    }
    exit(1);
}
Exemple #3
0
/**
 * processes the installer
 */
function process($argv)
{
    // Determine ANSI output from --ansi and --no-ansi flags
    setUseAnsi($argv);
    if (in_array('--help', $argv)) {
        displayHelp();
        exit(0);
    }
    $check = in_array('--check', $argv);
    $help = in_array('--help', $argv);
    $force = in_array('--force', $argv);
    $quiet = in_array('--quiet', $argv);
    $channel = in_array('--snapshot', $argv) ? 'snapshot' : (in_array('--preview', $argv) ? 'preview' : 'stable');
    $disableTls = in_array('--disable-tls', $argv);
    $installDir = getOptValue('--install-dir', $argv, false);
    $version = getOptValue('--version', $argv, false);
    $filename = getOptValue('--filename', $argv, 'composer.phar');
    $cafile = getOptValue('--cafile', $argv, false);
    if (!checkParams($installDir, $version, $cafile)) {
        exit(1);
    }
    $ok = checkPlatform($warnings, $quiet, $disableTls);
    if ($check) {
        // Only show warnings if we haven't output any errors
        if ($ok) {
            showWarnings($warnings);
            showSecurityWarning($disableTls);
        }
        exit($ok ? 0 : 1);
    }
    if ($ok || $force) {
        installComposer($version, $installDir, $filename, $quiet, $disableTls, $cafile, $channel);
        showWarnings($warnings);
        showSecurityWarning($disableTls);
        exit(0);
    }
    exit(1);
}
Exemple #4
0
/**
 * Parse command line arguments and execute appropriate function when
 * running from the command line.
 *
 * If no arguments are provided, usage information will be provided.
 *
 * @param array $argv The array of command line arguments provided by PHP.
 *          $argv[0] should be the current executable name or '-' if
 *          not available.
 * @param int $argc The size of $argv.
 */
function runCLIVersion($argv, $argc)
{
    if (isset($argc) && $argc >= 2) {
        # Prepare a server connection
        if ($argc >= 4) {
            try {
                $client = getClientLoginHttpClient($argv[2], $argv[3]);
                $docs = new Zend_Gdata_Docs($client);
            } catch (Zend_Gdata_App_AuthException $e) {
                echo "Error: Unable to authenticate. Please check your";
                echo " credentials.\n";
                exit(1);
            }
        }

        # Dispatch arguments to the desired method
        switch ($argv[1]) {
            case 'retrieveAllDocuments':
                if ($argc >= 4) {
                    retrieveAllDocuments($docs, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password>\n\n";
                    echo "This lists all of the documents in the user's";
                    echo " account.\n";
                }
                break;
            case 'retrieveWPDocs':
                if ($argc >= 4) {
                    //echo "!WP Docs:";
                    //var_dump($docs);
                    retrieveWPDocs($docs, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password>\n\n";
                    echo "This lists all of the word processing documents in";
                    echo " the user's account.\n";
                }
                break;
            case 'retrieveSpreadsheets':
                if ($argc >= 4) {
                    retrieveAllDocuments($docs, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password>\n\n";
                    echo "This lists all of the spreadsheets in the user's";
                    echo " account.\n";
                }
                break;
            case 'fullTextSearch':
                if ($argc >= 4) {
                    // Combine all of the query args into one query string. 
                    // The command line split the query string on space 
                    // characters.
                    $queryString = implode(' ', array_slice($argv, 4));
                    fullTextSearch($docs, false, $queryString);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password> <query string>\n\n";
                    echo "This lists all of the documents which contain the";
                    echo " query string.\n";
                }
                break;
            case 'uploadDocument':
                if ($argc >= 5) {
                    // Pass in the file name of the document to be uploaded. 
                    // Since the document is on this machine, we  do not need
                    // to set the temporary file name. The temp file name is
                    // used only when uploading to a webserver.
                    uploadDocument($docs, false, $argv[4], null);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password> <file_with_path>\n\n";
                    echo "This lists all of the documents which contain the";
                    echo " query string.\n";
                    echo "\nExample: php {$argv[0]} {$argv[1]} <username>";
                    echo " <password> /tmp/testSpreadsheet.ods\n";
                }
                break;
            default:
                // Invalid action entered
                displayHelp($argv[0]);
        // End switch block
        }
    } else {
        // action left unspecified
        displayHelp($argv[0]);
    }
}
Exemple #5
0
function process($argv)
{
    $check = in_array('--check', $argv);
    $help = in_array('--help', $argv);
    $force = in_array('--force', $argv);
    $quiet = in_array('--quiet', $argv);
    $disableTls = in_array('--disable-tls', $argv);
    $installDir = FALSE;
    $version = FALSE;
    $filename = 'slicer.phar';
    $cafile = FALSE;
    // --no-ansi wins over --ansi
    if (in_array('--no-ansi', $argv)) {
        define('USE_ANSI', FALSE);
    } elseif (in_array('--ansi', $argv)) {
        define('USE_ANSI', TRUE);
    } else {
        // On Windows, default to no ANSI, except in ANSICON and ConEmu.
        // Everywhere else, default to ANSI if stdout is a terminal.
        define('USE_ANSI', DIRECTORY_SEPARATOR == '\\' ? FALSE !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') : function_exists('posix_isatty') && posix_isatty(1));
    }
    foreach ($argv as $key => $val) {
        if (0 === strpos($val, '--install-dir')) {
            if (13 === strlen($val) && isset($argv[$key + 1])) {
                $installDir = trim($argv[$key + 1]);
            } else {
                $installDir = trim(substr($val, 14));
            }
        }
        if (0 === strpos($val, '--version')) {
            if (9 === strlen($val) && isset($argv[$key + 1])) {
                $version = trim($argv[$key + 1]);
            } else {
                $version = trim(substr($val, 10));
            }
        }
        if (0 === strpos($val, '--filename')) {
            if (10 === strlen($val) && isset($argv[$key + 1])) {
                $filename = trim($argv[$key + 1]);
            } else {
                $filename = trim(substr($val, 11));
            }
        }
        if (0 === strpos($val, '--cafile')) {
            if (8 === strlen($val) && isset($argv[$key + 1])) {
                $cafile = trim($argv[$key + 1]);
            } else {
                $cafile = trim(substr($val, 9));
            }
        }
    }
    if ($help) {
        displayHelp();
        exit(0);
    }
    $ok = checkPlatform($quiet, $disableTls);
    if (FALSE !== $installDir && !is_dir($installDir)) {
        out("The defined install dir ({$installDir}) does not exist.", 'info');
        $ok = FALSE;
    }
    if (FALSE !== $version && 1 !== preg_match('/^\\d+\\.\\d+\\.\\d+(\\-(alpha|beta)\\d+)*$/', $version)) {
        out("The defined install version ({$version}) does not match release pattern.", 'info');
        $ok = FALSE;
    }
    if (FALSE !== $cafile && (!file_exists($cafile) || !is_readable($cafile))) {
        out("The defined Certificate Authority (CA) cert file ({$cafile}) does not exist or is not readable.", 'info');
        $ok = FALSE;
    }
    if (TRUE === $disableTls) {
        out("You have instructed the Installer not to enforce SSL/TLS security on remote HTTPS requests.", 'info');
        out("This will leave all downloads during installation vulnerable to Man-In-The-Middle (MITM) attacks.", 'info');
    }
    if ($check) {
        exit($ok ? 0 : 1);
    }
    if ($ok || $force) {
        installSlicer($version, $installDir, $filename, $quiet, $disableTls, $cafile);
        exit(0);
    }
    exit(1);
}
/**
 * Parse command line arguments and execute appropriate function when
 * running from the command line.
 *
 * If no arguments are provided, usage information will be provided.
 *
 * @param  array   $argv    The array of command line arguments provided by PHP.
 *                 $argv[0] should be the current executable name or '-' if not available.
 * @param  integer $argc    The size of $argv.
 * @return void
 */
function runCLIVersion($argv, $argc)
{
    if (isset($argc) && $argc >= 2) {
        # Prepare a server connection
        if ($argc >= 5) {
            try {
                $client = getClientLoginHttpClient($argv[2] . '@' . $argv[3], $argv[4]);
                $gapps = new Zend_Gdata_Gapps($client, $argv[3]);
            } catch (Zend_Gdata_App_AuthException $e) {
                echo "Error: Unable to authenticate. Please check your credentials.\n";
                exit(1);
            }
        }
        # Dispatch arguments to the desired method
        switch ($argv[1]) {
            case 'createUser':
                if ($argc == 9) {
                    createUser($gapps, false, $argv[5], $argv[6], $argv[7], $argv[8]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username> <given name> <family name> <user's password>\n\n";
                    echo "This creates a new user with the given username.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe John Doe p4ssw0rd\n";
                }
                break;
            case 'retrieveUser':
                if ($argc == 6) {
                    retrieveUser($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "This retrieves the user with the specified " . "username and displays information about that user.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'retrieveAllUsers':
                if ($argc == 5) {
                    retrieveAllUsers($gapps, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "\n\n";
                    echo "This lists all users on the current domain.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password>\n";
                }
                break;
            case 'updateUserName':
                if ($argc == 8) {
                    updateUserName($gapps, false, $argv[5], $argv[6], $argv[7]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username> <new given name> <new family name>\n\n";
                    echo "Renames an existing user.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe Jane Doe\n";
                }
                break;
            case 'updateUserPassword':
                if ($argc == 7) {
                    updateUserPassword($gapps, false, $argv[5], $argv[6]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username> <new user password>\n\n";
                    echo "Changes the password for an existing user.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe password1\n";
                }
                break;
            case 'suspendUser':
                if ($argc == 6) {
                    suspendUser($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "This suspends the given user.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'restoreUser':
                if ($argc == 6) {
                    restoreUser($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "This restores the given user after being suspended.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'giveUserAdminRights':
                if ($argc == 6) {
                    giveUserAdminRights($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "Give a user admin rights for this domain.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'revokeUserAdminRights':
                if ($argc == 6) {
                    revokeUserAdminRights($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "Remove a user's admin rights for this domain.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'setUserMustChangePassword':
                if ($argc == 6) {
                    setUserMustChangePassword($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "Force a user to change their password at next login.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'clearUserMustChangePassword':
                if ($argc == 6) {
                    clearUserMustChangePassword($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "Clear the flag indicating that a user must change " . "their password at next login.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'deleteUser':
                if ($argc == 6) {
                    deleteUser($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "Delete the user who owns a given username.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'createNickname':
                if ($argc == 7) {
                    createNickname($gapps, false, $argv[5], $argv[6]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username> <nickname>\n\n";
                    echo "Create a new nickname for the specified user.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe johnny\n";
                }
                break;
            case 'retrieveNickname':
                if ($argc == 6) {
                    retrieveNickname($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<nickname>\n\n";
                    echo "Retrieve a nickname and display its ownership " . "information.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "johnny\n";
                }
                break;
            case 'retrieveNicknames':
                if ($argc == 6) {
                    retrieveNicknames($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<user's username>\n\n";
                    echo "Output all nicknames owned by a specific username.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "jdoe\n";
                }
                break;
            case 'retrieveAllNicknames':
                if ($argc == 5) {
                    retrieveAllNicknames($gapps, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "\n\n";
                    echo "Output all registered nicknames on the system.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "\n";
                }
                break;
            case 'deleteNickname':
                if ($argc == 6) {
                    deleteNickname($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<nickname>\n\n";
                    echo "Delete a specific nickname.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "johnny\n";
                }
                break;
            case 'createEmailList':
                if ($argc == 6) {
                    createEmailList($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<email list>\n\n";
                    echo "Create a new email list with the specified name.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "friends\n";
                }
                break;
            case 'retrieveEmailLists':
                if ($argc == 6) {
                    retrieveEmailLists($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<recipient>\n\n";
                    echo "Retrieve all email lists to which the specified " . "address is subscribed.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "johnny@somewhere.com.invalid\n";
                }
                break;
            case 'retrieveAllEmailLists':
                if ($argc == 5) {
                    retrieveAllEmailLists($gapps, false);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "\n\n";
                    echo "Retrieve a list of all email lists on the current " . "domain.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "\n";
                }
                break;
            case 'deleteEmailList':
                if ($argc == 6) {
                    deleteEmailList($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<email list>\n\n";
                    echo "Delete a specified email list.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "friends\n";
                }
                break;
            case 'addRecipientToEmailList':
                if ($argc == 7) {
                    addRecipientToEmailList($gapps, false, $argv[5], $argv[6]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<recipient> <email list>\n\n";
                    echo "Add a recipient to an existing email list.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "johnny@somewhere.com.invalid friends\n";
                }
                break;
            case 'retrieveAllRecipients':
                if ($argc == 6) {
                    retrieveAllRecipients($gapps, false, $argv[5]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<email list>\n\n";
                    echo "Retrieve all recipients for an existing email list.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "friends\n";
                }
                break;
            case 'removeRecipientFromEmailList':
                if ($argc == 7) {
                    removeRecipientFromEmailList($gapps, false, $argv[5], $argv[6]);
                } else {
                    echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "<recipient> <email list>\n\n";
                    echo "Remove an existing recipient from an email list.\n";
                    echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " . "johnny@somewhere.com.invalid friends\n";
                }
                break;
            default:
                // Invalid action entered
                displayHelp($argv[0]);
                // End switch block
        }
    } else {
        // action left unspecified
        displayHelp($argv[0]);
    }
}
Exemple #7
0
<?php

if (php_sapi_name() !== 'cli') {
    exit(1);
}
set_time_limit(0);
ini_set('display_errors', 1);
define('COMPOSER_FILE', 'composer.phar');
define('COMPOSER_SETUP_FILE', 'composer-setup.php');
setUseAnsi($argv);
$argv = is_array($argv) ? $argv : array();
$argv[1] = isset($argv[1]) ? $argv[1] : null;
$argv[2] = isset($argv[2]) ? $argv[2] : null;
if (in_array('--help', $argv) || empty($argv[1])) {
    displayHelp($argv);
    exit(0);
}
if (in_array('-v', $argv) || in_array('--version', $argv)) {
    require __DIR__ . '/src/Eccube/Common/Constant.php';
    echo 'EC-CUBE ' . Eccube\Common\Constant::VERSION . PHP_EOL;
    exit(0);
}
out('EC-CUBE3 installer use database driver of ', null, false);
$database_driver = 'pdo_sqlite';
switch ($argv[1]) {
    case 'mysql':
        $database_driver = 'pdo_mysql';
        break;
    case 'pgsql':
        $database_driver = 'pdo_pgsql';
        break;
/**
 * 
 * 
 * @param int $argc
 * @param array $argv
 * 
 * @return void
 * 
 * @throws \InvalidArgumentException
 * @throws \RuntimeException if this function is called in a script that is not run at the command line.
 */
function createController($argc, array $argv)
{
    //////////////////////////////////////////
    // START: Environment and Args Validation
    //////////////////////////////////////////
    if (!isPhpRunningInCliMode()) {
        $err_msg = '`' . __FUNCTION__ . '($argc, array $argv)` should only be called from within' . ' php scripts that should be run via the command line!!!' . PHP_EOL;
        throw new \RuntimeException($err_msg);
    }
    if (is_string($argc) && is_numeric($argc)) {
        $argc = (int) $argc;
    }
    if (!is_int($argc)) {
        $err_msg = 'The expected value for the first argument to ' . '`' . __FUNCTION__ . '($argc, array $argv)` should be an int.' . ' `' . ucfirst(gettype($argc)) . '` with the value below was supplied:' . PHP_EOL . var_export($argc, true) . PHP_EOL . PHP_EOL . 'Good bye!!!';
        throw new \InvalidArgumentException($err_msg);
    }
    if (count($argv) < 1) {
        $err_msg = 'The expected value for the second argument to ' . '`' . __FUNCTION__ . '($argc, array $argv)` should be an array with at least one element. Empty Array was supplied.' . 'This second argument is expected to be the $argv array passed by PHP to the script calling this function.';
        throw new \InvalidArgumentException($err_msg);
    }
    //////////////////////////////////////////
    // END: Environment and Args Validation
    //////////////////////////////////////////
    //////////////////////////////////
    ///START: COMMAND PROCESSING
    //////////////////////////////////
    $ds = DIRECTORY_SEPARATOR;
    if ($argc < 5 || in_array('--help', $argv) || in_array('-help', $argv) || in_array('-h', $argv) || in_array('-?', $argv)) {
        displayHelp(basename($argv[0]));
    } else {
        if ($argc === 5 && (in_array('--controller-name', $argv) || in_array('-c', $argv)) && (in_array('--path-to-src-folder', $argv) || in_array('-p', $argv)) || $argc >= 7 && (in_array('--controller-name', $argv) || in_array('-c', $argv)) && (in_array('--path-to-src-folder', $argv) || in_array('-p', $argv)) && (in_array('--extends-controller', $argv) || in_array('-e', $argv))) {
            $templates_dir = dirname(__DIR__) . $ds . 'templates' . $ds;
            $controller_name = getOptVal('--controller-name', $argv);
            if ($controller_name === false) {
                $controller_name = getOptVal('-c', $argv);
            }
            $studly_controller_name = \Slim3MvcTools\Functions\Str\dashesToStudly(\Slim3MvcTools\Functions\Str\underToStudly($controller_name));
            $dashed_controller_name = \Slim3MvcTools\Functions\Str\toDashes($controller_name);
            if (!isValidClassName($studly_controller_name)) {
                printError("Invalid controller class name `{$controller_name}` supplied. Goodbye!!");
                return;
            }
            $src_folder_path = getOptVal('--path-to-src-folder', $argv);
            if ($src_folder_path === false) {
                $src_folder_path = getOptVal('-p', $argv);
            }
            $src_folder_path = normalizeFolderPathForOs($src_folder_path);
            if (!file_exists($src_folder_path) || !is_dir($src_folder_path)) {
                printError("The src folder path `{$src_folder_path}` supplied is a non-existent directory. Goodbye!!");
                return;
            }
            ////////////////////////////////////////////////////////////////////////////
            $default_controller_2_extend = '\\Slim3MvcTools\\Controllers\\BaseController';
            $controller_2_extend = getOptVal('--extends-controller', $argv);
            if ($controller_2_extend === false) {
                $controller_2_extend = getOptVal('-e', $argv);
                if ($controller_2_extend !== false) {
                    if (!isValidExtendsClassName($controller_2_extend)) {
                        printError("Invalid controller class name `{$controller_2_extend}` for extension supplied. Goodbye!!");
                        return;
                    }
                } else {
                    //use default controller class to be extended
                    $controller_2_extend = $default_controller_2_extend;
                }
            } else {
                if (!isValidExtendsClassName($controller_2_extend)) {
                    printError("Invalid controller class name `{$controller_2_extend}` for extension supplied. Goodbye!!");
                    return;
                }
            }
            ////////////////////////////////////////////////////////////////////////////
            $namepace_declaration = '';
            //omit namespace declaration by default
            $namepace_4_controller = getOptVal('--namespace-4-controller', $argv);
            if ($namepace_4_controller === false) {
                $namepace_4_controller = getOptVal('-n', $argv);
                if ($namepace_4_controller !== false) {
                    if (!isValidNamespaceName($namepace_4_controller)) {
                        printError("Invalid namespace `{$namepace_4_controller}` supplied. Goodbye!!");
                        return;
                    }
                    //validation passed
                    $namepace_declaration = "namespace {$namepace_4_controller};";
                } else {
                    $namepace_4_controller = '';
                }
            } else {
                if (!isValidNamespaceName($namepace_4_controller)) {
                    printError("Invalid namespace `{$namepace_4_controller}` supplied. Goodbye!!");
                    return;
                }
                //validation passed
                $namepace_declaration = "namespace {$namepace_4_controller};";
            }
            //read template controller and substitute __TEMPLTATE_CONTROLLER__ with given controller name \Slim3MvcTools\Functions\Str\underToStudly(dashesToStudly($controller_name_from_cli))
            //substitute {{TEMPLTATE_CONTROLLER_VIEW_FOLDER}} with the view folder name \Slim3MvcTools\Functions\Str\toDashes($controller_name_from_cli)
            //write processed controller file to S3MVC_APP_ROOT_PATH.$ds.'src'.$ds.'controllers'.$ds
            //make the dir S3MVC_APP_ROOT_PATH.$ds.'src'.$ds.'views'.$ds.\Slim3MvcTools\Functions\Str\toDashes($controller_name_from_cli)
            //read template controller index view and substitute __TEMPLTATE_CONTROLLER__ with given controller name \Slim3MvcTools\Functions\Str\underToStudly(dashesToStudly($controller_name_from_cli))
            //write processed controller file to S3MVC_APP_ROOT_PATH.$ds.'src'.$ds.'views'.$ds.\Slim3MvcTools\Functions\Str\toDashes($controller_name_from_cli)
            $template_controller_file = $templates_dir . 'controller-class-template.php.tpl';
            $dest_controller_class_file_folder = $src_folder_path . 'controllers' . $ds;
            $dest_controller_class_file = $dest_controller_class_file_folder . "{$studly_controller_name}.php";
            if (!file_exists($dest_controller_class_file_folder) && !mkdir($dest_controller_class_file_folder, 0775, true)) {
                printError("Failed to create `{$dest_controller_class_file_folder}`; the folder supposed to contain the controller named `{$studly_controller_name}`. Goodbye!!");
                return;
            }
            $template_view_file = $templates_dir . 'index-view-template.php';
            $dest_view_file_folder = $src_folder_path . 'views' . $ds . "{$dashed_controller_name}{$ds}";
            $dest_view_file = "{$dest_view_file_folder}index.php";
            if (!file_exists($dest_view_file_folder) && !mkdir($dest_view_file_folder, 0775, true)) {
                printError("Failed to create `{$dest_view_file_folder}`; the folder supposed to contain views for the controller named `{$studly_controller_name}`. Goodbye!!");
                return;
            }
            if (file_exists($dest_controller_class_file)) {
                printError("Controller class `{$studly_controller_name}` already exists in `{$dest_controller_class_file}`. Goodbye!!");
                return;
            }
            if (file_exists($dest_view_file)) {
                printError("View file `{$dest_view_file}` already exists for Controller class `{$studly_controller_name}`. Goodbye!!");
                return;
            }
            printInfo("Creating Controller Class `{$studly_controller_name}` in `{$dest_controller_class_file}` ....");
            ////////////////////////////////////////////////////////////////////////////
            $replaces = ['__CONTROLLER_2_EXTEND__' => $controller_2_extend, '__TEMPLTATE_CONTROLLER__' => $studly_controller_name, 'namespace __NAMESPACE_2_REPLACE__;' => $namepace_declaration, '{{TEMPLTATE_CONTROLLER_VIEW_FOLDER}}' => $dashed_controller_name, "'__login_success_redirect_controller__'" => "'{$dashed_controller_name}'"];
            if (processTemplateFile($template_controller_file, $dest_controller_class_file, $replaces) === false) {
                printError("Failed transforming template controller `{$template_controller_file}` to `{$dest_controller_class_file}`. Goodbye!!");
            } else {
                printInfo("Successfully created `{$dest_controller_class_file}` ...." . PHP_EOL);
            }
            printInfo("Creating index view for `{$studly_controller_name}::actionIndex()` in `{$dest_view_file}` ....");
            $replaces['__TEMPLTATE_CONTROLLER__'] = rtrim($namepace_4_controller, '\\') . '\\' . $studly_controller_name;
            if (processTemplateFile($template_view_file, $dest_view_file, $replaces) === false) {
                printError("Failed creating index view for `{$studly_controller_name}::actionIndex()` in `{$dest_view_file}`.");
                printInfo("Deleting `{$dest_controller_class_file}` ....");
                if (!unlink($dest_controller_class_file)) {
                    printInfo("Failed to delete `{$dest_controller_class_file}`. Please delete it manually. Goodbye!!");
                } else {
                    printInfo("Goodbye!!");
                }
                return;
            } else {
                printInfo("Successfully created `{$dest_view_file}` ...." . PHP_EOL);
            }
            printInfo("All done!!");
            if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
                //test if composer is avaliable only if server OS on which this script is being run
                //is not windows
                if (isCommandAvailableOnOs('composer')) {
                    passthru('composer dumpautoload');
                } else {
                    printInfo("Remember to run `composer dumpautoload` so that composer can pick up the newly created controller class `{$studly_controller_name}` in `{$dest_controller_class_file}`.");
                }
            } else {
                printInfo("Remember to run `composer dumpautoload` so that composer can pick up the newly created controller class `{$studly_controller_name}` in `{$dest_controller_class_file}`.");
            }
            //we are done
        } else {
            displayHelp(basename($argv[0]));
        }
    }
    //////////////////////////////////
    ///END: COMMAND PROCESSING
    //////////////////////////////////
}
Exemple #9
0
<?php

/**
* Create a phar
*
* @author Cal Evans <*****@*****.**>
* @author John Douglass <john .douglass@oit.gatech.edu>
*/
$getOptLongArray = array("stub:");
$getOptParams = "s:p:v";
$options = getOpt($getOptParams, $getOptLongArray);
if (!isset($options['s'], $options['p'])) {
    echo "You did not specify either a path or a phar file name.\n";
    displayHelp();
    die(1);
}
/*
 * Set up our environment
 */
$sourceLocation = $options['s'];
$pharFile = $options['p'];
// At this point, we need to check to see if the file exists. If neither exist, throw exception.
if (isset($options['stub'])) {
    $stubFile = $options['stub'];
} else {
    $stubFile = 'stub.php';
}
if (!file_exists($sourceLocation)) {
    echo "ERROR: Source file location does not exist!\nCheck your source and try again.\n";
    displayhelp();
    die(1);
    public function testThatDisplayHelpWorksAsExpected()
    {
        $output = $this->execFuncAndReturnBufferedOutput('displayHelp', ['create-controller.php']);
        $expected_substr = <<<INPUT
This is a script intended for creating a controller class and a default index view file in rotexsoft/slim3-skeleton-mvc-app derived projects.

Usage:
  php create-controller.php [options]

Example:
# either of the commands below will create a controller with the class named `FooBar` in `src/controllers/FooBar.php` (which by default extends `\\Slim3MvcTools\\Controllers\\BaseController`)  and a default view in `src/views/foo-bar/index.php`
    
    php create-controller.php -c foo-bar -p "/var/www/html/my-app/src"
    
    php create-controller.php --controller-name foo-bar --path-to-src-folder "/var/www/html/my-app/src"
  
# either of the commands below will create a controller with the class named `FooBar` in `src/controllers/FooBar.php` (which extends `\\SomeNameSpace\\Controller2Extend`) and a default view in `src/views/foo-bar/index.php`
  
    php create-controller.php -c foo-bar -p "/var/www/html/my-app/src" -e "\\SomeNameSpace\\Controller2Extend"
    
    php create-controller.php --controller-name foo-bar --path-to-src-folder "/var/www/html/my-app/src" --extends-controller "\\SomeNameSpace\\Controller2Extend"

Options:
  -h, -?, -help, --help         Display this help message
    
  -c, --controller-name         The name of the controller class you want to create. The name will be converted to Studly case eg. foo-bar will be changed to FooBar. This option REQUIRES at least the `-p` or `--path-to-src-folder` option to work.
  
  -e, --extends-controller      The name of the controller class (optionally including the name-space prefix) that you want your created controller to extend. `\\Slim3MvcTools\\Controllers\\BaseController` is the default value if this option is not specified. Unlike the value supplied for `--controller-name`, the value supplied for this option will not be converted to Studly case (make sure the value is the correct full class name). This option REQUIRES at least the `-c` (or `--controller-name`) and the `-p` (or `--path-to-src-folder`) options to work.
    
  -n, --namespace-4-controller  The name of the namespace the new controller will belong to. If omitted the namespace declaration will not be present in the new controller class. Unlike the value supplied for `--controller-name`, the value supplied for this option will not be converted to Studly case (make sure the value is a valid name for a php namespace). This option REQUIRES at least the `-c` (or `--controller-name`) and the `-p` (or `--path-to-src-folder`) options to work.
    
  -p, --path-to-src-folder      The absolute path to the `src` folder. Eg. `/var/www/html/my-app/src`. This option REQUIRES at least the `-c` (or `--controller-name`) option to work.
INPUT;
        $this->assertContains($expected_substr, $output);
        ///////////////////////////////////////////
        //Test \InvalidArgumentException messages
        ///////////////////////////////////////////
        $args = array('Integer' => 111, 'Double' => 111.1234, 'Boolean' => true, 'Array' => [], 'Object' => new stdclass(), 'NULL' => null, 'Resource' => tmpfile());
        $function_sig_in_err_msg = 'displayHelp($cur_script)';
        foreach ($args as $arg_type => $arg) {
            try {
                displayHelp($arg);
                $msg = '\\InvalidArgumentException should have been thrown in `' . __FILE__ . '`' . ' on line ' . (__LINE__ - 1);
                static::fail($msg);
            } catch (\InvalidArgumentException $e) {
                $msg_substr = "The expected value for the first argument to `{$function_sig_in_err_msg}`" . " should be a String value. `{$arg_type}` with the value below was supplied:";
                $this->assertContains($msg_substr, $e->getMessage());
            }
        }
        // test the callable type
        try {
            displayHelp(function () {
                echo 'blah';
            });
            $msg = '\\InvalidArgumentException should have been thrown in `' . __FILE__ . '`' . ' on line ' . (__LINE__ - 1);
            static::fail($msg);
        } catch (\InvalidArgumentException $e) {
            $msg_substr = "The expected value for the first argument to `{$function_sig_in_err_msg}`" . " should be a String value. `Object` with the value below was supplied:";
            $this->assertContains($msg_substr, $e->getMessage());
        }
    }
Exemple #11
0
            $conductor->startLaravelApplication();
            $conductor->endWithSuccess();
            break;
        case "stop":
            $conductor->stopLaravelApplication();
            $conductor->endWithSuccess();
            break;
        case "services":
            $conductor->serviceControl($commands[2]);
            $conductor->endWithSuccess();
            break;
        default:
            displayHelp($conductor);
    }
} else {
    displayHelp($conductor);
}
/**
 * The 'help' screen text.
 */
function displayHelp($conductor)
{
    $conductor->writeln();
    $conductor->writeln('Usage: conductor [OPTION]');
    $conductor->writeln();
    $conductor->writeln('Options:');
    $conductor->writeln('  list              List all currently hosted applications');
    $conductor->writeln('  new {name}        Prepares and deploys a new application');
    $conductor->writeln('  destroy {name}    Removes an application from the server');
    $conductor->writeln('  update {name}     Upgrades an application via. Git');
    $conductor->writeln('  rollback {name}   Rolls back the most recent upgrade');