示例#1
0
文件: set.php 项目: liammartens/xtend
namespace Application;

use xTend\Workbench\Workbench;
/**
 * Sets the public directory
 */
Workbench::register('^set:public ([a-zA-Z0-9\\.\\_]+)$', function ($argv) {
    rename(Workbench::$directory . '/' . Workbench::get('public'), Workbench::$directory . '/' . $argv[1]);
    Workbench::set('public', $argv[1]);
    Workbench::save();
}, 'set:public');
/**
 * Sets the workbench application
 */
Workbench::register('^set:application ([a-zA-Z0-9\\.\\_]+)$', function ($argv) {
    $name = $argv[1];
    $namespace = Workbench::namespace($name);
    if (is_dir(Workbench::$directory . '/' . $name) && isset(Workbench::get('applications')[$name])) {
        Workbench::set('application', $name);
        Workbench::save();
        // rename namespaces in commmand files and so on
        $commands = array_diff(scandir(Workbench::$directory . '/CLI/Commands'), ['.', '..']);
        foreach ($commands as $command) {
            Workbench::filespace(Workbench::$directory . '/CLI/Commands/' . $command, 'Application', $namespace);
        }
        Workbench::filespace(Workbench::$directory . '/workbench', 'Application', $namespace);
    } else {
        die('The application \'' . $name . '\' does not exist');
    }
}, 'set:application');
示例#2
0
<?php

namespace {
    use xTend\Workbench\Workbench;
    require_once __DIR__ . '/../CLI/Core/Workbench.php';
    Workbench::configure();
    //first match all
    global $matched_application;
    $matched_application = false;
    foreach (Workbench::get('applications') as $name => $restrictions) {
        if (Workbench::match($restrictions)) {
            $matched_application = $name;
        }
    }
    if ($matched_application !== false) {
        require_once __DIR__ . '/../' . $matched_application . '/Core/App.php';
        $matched_application = Workbench::namespace($matched_application);
    }
}
namespace Application {
    global $matched_application;
    if (__NAMESPACE__ == $matched_application) {
        Core\App::start(__DIR__);
        Core\FileHandler::system('Config.App.App.php')->include();
        Core\App::run();
    }
}
示例#3
0
    $controller = Core\App::models()->file($name . '.php');
    $controller->write('<?php
    namespace ' . Workbench::namespace(Workbench::get('application')) . ';
    class ' . $class_name . ' extends Blueprints\\Model {
        protected static $_table = \'' . str_replace('.', '_', $name) . '\';
        protected static $_id_column = \'id\';
    }');
}, 'new:model');
/**
 * Creates a new model which doesn't inherit the blueprint
 */
Workbench::register('^new:model ([a-zA-Z0-9\\_\\.]+) empty$', function ($argv) {
    $name = $argv[1];
    $class_name = $name;
    $dot_pos = strrpos($name, '.');
    // get and create containing directory + get classname
    if ($dot_pos !== false) {
        $dir = Core\App::models()->directory(substr($name, 0, $dot_pos));
        if (!$dir->exists()) {
            $dir->create();
        }
        $class_name = substr($name, $dot_pos + 1);
    }
    // create controller file
    $controller = Core\App::models()->file($name . '.php');
    $controller->write('<?php
    namespace ' . Workbench::namespace(Workbench::get('application')) . ';
    class ' . $class_name . ' {
        
    }');
});
示例#4
0
文件: new.php 项目: liammartens/xtend
 // extract zip
 $zip = new \ZipArchive();
 $zip->open(Workbench::$directory . '/xtend.zip');
 $zip->extractTo(Workbench::$directory);
 // move application folder
 rename(Workbench::$directory . '/xTend-' . $latest_release . '/dist/Application', Workbench::$directory . '/' . $name);
 // remove directory
 (new Objects\DirectoryHandler\Directory(Workbench::$directory . '/xTend-' . $latest_release))->remove();
 // remove zip file and directory
 unlink(Workbench::$directory . '/xtend.zip');
 // add application to Workbench configuration
 Workbench::new($name, $domain, $path);
 // get namespace from name
 $namespace = Workbench::namespace($name);
 // add to index.php
 file_put_contents(Workbench::$directory . '/' . Workbench::get('public') . '/index.php', '
 namespace ' . $namespace . ' {
     global $matched_application;
     if(__NAMESPACE__==$matched_application) {
         Core\\App::start(__DIR__);
         Core\\FileHandler::system(\'Config.App.App.php\')->include();
         Core\\App::run();
     }
 }', FILE_APPEND);
 // replace old namespaces (default Application)
 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Workbench::$directory . '/' . $name)) as $file) {
     // skip if not file / if not PHP file
     if (!is_file($file) || substr($file, strrpos($file, '.')) !== '.php') {
         continue;
     }
     Workbench::filespace($file, 'Application', $namespace);
示例#5
0
文件: wow.php 项目: liammartens/xtend
<?php

namespace Application;

use xTend\Workbench\Workbench;
/**
 * Sets the wow flavor
 */
Workbench::register('wow:flavor (HTML|AT_SIGN|COMBINED)', function ($argv) {
    $file = Core\App::config()->file('Wow.Flavor.php');
    $file->write('<?php
    /**
    * Sets the current Wow flavor
    * and initializes the Wow engine
    */
    namespace ' . Workbench::namespace(Workbench::get('application')) . ';
    use ' . Workbench::namespace(Workbench::get('application')) . '\\Core\\Wow;
    Wow::flavor(Wow::' . $argv[1] . ');
    Wow::start();');
}, 'wow:flavor');
示例#6
0
namespace Application;

use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
use xTend\Workbench\Workbench;
Workbench::register('^rename ([a-zA-Z0-9\\.\\_]+)$', function ($argv) {
    $name = $argv[1];
    $namespace = Workbench::namespace($name);
    // do check
    if (isset(Workbench::get('applications')[$name])) {
        die('Application name already used');
    }
    // rename
    rename(Workbench::$directory . '/' . Workbench::get('application'), Workbench::$directory . '/' . $name);
    // replace old namespaces (default Application)
    foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Workbench::$directory . '/' . $name)) as $file) {
        // skip if not file / if not PHP file
        if (!is_file($file) || substr($file, strrpos($file, '.')) !== '.php') {
            continue;
        }
        Workbench::filespace($file, 'Application', $namespace);
    }
    // replace in index.php
    Workbench::filespace(Workbench::$directory . '/' . Workbench::get('public') . '/index.php', 'Application', $namespace);
    // rename application in configuration
    $restrictions = Workbench::get('applications')[Workbench::get('application')];
    unset(Workbench::$configuration['applications'][Workbench::get('application')]);
    Workbench::$configuration['applications'][$name] = $restrictions;
    // set application
    Workbench::$commands['set:application']->execute($argv);
}, 'rename');