Пример #1
0
function createView($name)
{
    $view = 'Hello World!';
    mkdir(VIEWS_DIR . $name);
    $handle = fopen(VIEWS_DIR . $name . DIRECTORY_SEPARATOR . 'v_index.php', 'w+');
    fwrite($handle, $view);
    fclose($handle);
}
if ($argc > 1) {
    //Define controller, model, and view directory
    define('CONTROLLERS_DIR', realpath(__DIR__ . '/app/controllers') . DIRECTORY_SEPARATOR);
    define('MODELS_DIR', realpath(__DIR__ . '/app/models') . DIRECTORY_SEPARATOR);
    define('VIEWS_DIR', realpath(__DIR__ . '/app/views') . DIRECTORY_SEPARATOR);
    //User command
    if ($argv[1] == 'controller') {
        createController($argv[2]);
        createView($argv[2]);
        fwrite(STDOUT, 'Controller c_' . $argv[2] . ' and View ' . $argv[2] . '/v_index.php created successfully');
    } else {
        if ($argv[1] == 'model') {
            createModel($argv[2], $argv[3], $argv[4]);
            fwrite(STDOUT, 'Model m_' . $argv[2] . ' created successfully');
        } else {
            fwrite(STDOUT, "Wrong command\n");
            fwrite(STDOUT, "Here the list of command:\n" . "1. controller <name>\n" . "2. model <table-name> <field-list> <primary-key>\n");
        }
    }
} else {
    //Write if user didn't specify arguments
    fwrite(STDOUT, "Please specify the arguments. You can use:\n" . "1. controller <name>\n" . "2. model <table-name> <field-list> <primary-key>\n");
}
Пример #2
0
include_once 'Zend/Console/Getopt.php';
$opts = new Zend_Console_Getopt(array('views|v' => 'Whether views should be generated automatically', 'path|p=s' => 'The location of the application, defaults to the present working dir', 'addtype|t=w' => 'The name of the type to create', 'all|a' => 'Will auto generate views and controllers'));
try {
    $opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
    echo $e->getUsageMessage();
    exit;
}
$path = isset($opts->p) ? $opts->p : getcwd();
$path = rtrim($path, "\\/");
$type = $opts->getOption('t');
$model = $opts->getOption('m');
$views = $opts->getOption('v');
$all = $opts->getOption('a');
if ($all || $type) {
    createController($type, $all || $views);
}
function createController($name, $views)
{
    global $path;
    $model = array('name' => $name);
    $template = APP_DIR . '/templates/controller.php';
    $outputFile = $path . '/controllers/' . $name . 'Controller.php';
    processTemplate($template, $model, $outputFile);
    echo "Creating controller {$name}\n";
    if ($views) {
        $model['modelType'] = strtolower($name);
        $outputFile = $path . '/views/' . $model['modelType'] . '/list.php';
        $template = APP_DIR . '/templates/list.php';
        processTemplate($template, $model, $outputFile);
        $outputFile = $path . '/views/' . $model['modelType'] . '/edit.php';
Пример #3
0
function createModuleController($module, $name)
{
    createController($name, $module);
}
#!/usr/bin/php
<?php 
include_once __DIR__ . DIRECTORY_SEPARATOR . "cli-script-helper-functions.php";
if (!isPhpRunningInCliMode()) {
    echo 'Error: This script should only be run via the command line!!';
} else {
    try {
        createController($argc, $argv);
    } catch (\Exception $e) {
        $msg = 'Exception was thrown in ' . $e->getFile() . ' on line ' . $e->getLine() . PHP_EOL . $e->getMessage() . PHP_EOL . 'Exception Trace:' . PHP_EOL . $e->getTraceAsString() . PHP_EOL . PHP_EOL . 'Please submit a bug report to https://github.com/rotexsoft/slim3-skeleton-mvc-tools/issues if symptoms persist.' . PHP_EOL;
        printError($msg);
    }
}