Ejemplo n.º 1
0
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');
Ejemplo n.º 2
0
Workbench::register('^new ([a-zA-Z0-9\\.\\_]+) (.+?) (.+?)$', function ($argv) {
    // get application name
    $name = $argv[1];
    // get domain and path restrictions
    $domain = $argv[2] === 'any' ? '*' : $argv[2];
    $path = $argv[3] === 'any' ? '*' : $argv[3];
    // check for existance
    if (is_dir($name) || isset(Workbench::get('applications')[$name])) {
        die('This application already exists');
    }
    // get xtend latest release
    $latest_release = file_get_contents('https://xtend.liammartens.com/releases/latest.release');
    // get zip file
    $zip = file_get_contents('https://xtend.liammartens.com/releases/' . $latest_release . '.zip');
    file_put_contents(Workbench::$directory . '/xtend.zip', $zip);
    // 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);
    }
}, 'new');
Ejemplo n.º 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 . ' {
        
    }');
});
Ejemplo n.º 4
0
<?php

namespace Application;

use xTend\Workbench\Workbench;
Workbench::register('^remove ([a-zA-Z0-9\\.\\_]+)$', function ($argv) {
    // do checks
    $name = $argv[1];
    if (!is_dir(Workbench::$directory . '/' . $name) || !isset(Workbench::get('applications')[$name])) {
        die('The application does not exist');
    }
    if ($name == Workbench::get('application')) {
        die('You can\'t remove the currently selected application');
    }
    // remove app dir
    (new Objects\DirectoryHandler\Directory(Workbench::$directory . '/' . $name))->remove();
    // remove from configuration
    Workbench::remove($name);
    //remove from index.php
    $contents = file_get_contents(Workbench::$directory . '/' . Workbench::get('public') . '/index.php');
    $contents = preg_replace('/namespace ' . Workbench::namespace($name) . ' \\{.+?\\}.+?\\}/s', '', $contents);
    file_put_contents(Workbench::$directory . '/' . Workbench::get('public') . '/index.php', trim($contents));
}, 'remove');
Ejemplo n.º 5
0
    } else {
        die("Configuration key not found");
    }
});
/**
 * Sets a configuration value
 */
Workbench::register('^config ([a-zA-Z]+) (.*)$', function ($argv) {
    $key = $argv[1];
    $value = $argv[2];
    $conf = Core\App::config()->file('App.configuration.json');
    $configuration = json_decode($conf->read(), true);
    if (isset($configuration[$key])) {
        if ($value === 'true' || $value === 'false') {
            $value = boolval($value);
        } elseif (is_numeric($value)) {
            $value = intval($value);
        }
        $configuration[$key] = $value;
        $conf->write(json_encode($configuration));
        // if environment changes , update db.yml
        if ($key == 'environment') {
            $db_file = Core\App::config()->file('ORM.db.yml');
            $db = Spyc::YAMLLoad((string) $db_file);
            $db['environments']['default_database'] = $value;
            $db_file->write(Spyc::YAMLDump($db, 4, false, true));
        }
    } else {
        die("Configuration key not found");
    }
});
Ejemplo n.º 6
0
<?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');
Ejemplo n.º 7
0
    class ' . $class_name . ' {

    }');
});
/**
 * Creates a new controller which inherits the RespondController
 */
Workbench::register('^new:controller ([a-zA-Z0-9\\_\\.]+) json$', 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::controllers()->directory(substr($name, 0, $dot_pos));
        if (!$dir->exists()) {
            $dir->create();
        }
        $class_name = substr($name, $dot_pos + 1);
    }
    // create controller file
    $controller = Core\App::controllers()->file($name . '.php');
    $controller->write('<?php
    namespace ' . Workbench::namespace(Workbench::get('application')) . ';
    class ' . $class_name . ' extends Blueprints\\RespondController {
        //The RespondController adds a protected method called respond
        //which you can use to return JSON data with a success parameter (boolean)
        //a status parameter with a code, hex code, status name and status message
        //and a data parameter which you can use to pass extra data
        //all info about the RespondController can be found in the documentation
    }');
});
Ejemplo n.º 8
0
}, 'packagist:autoremove_recursive');
/**
 * Autoremoves a certain package of a certain version (recursive)
 */
Workbench::register('^packagist:autoremove ([a-zA-Z0-9\\-\\_]+)\\/([a-zA-Z0-9\\-\\_]+) (.+) recursive$', function ($argv) {
    $package_name = $argv[1];
    if (Core\PackagistHandler::autoremove($package_name, $argv[2], true)) {
        return "Autoremoved {$package_name}";
    }
    return "Couldn't autoremove {$package_name}";
});
/**
 * Autoremoves a certain package
 */
Workbench::register('^packagist:autoremove ([a-zA-Z0-9\\-\\_]+)\\/([a-zA-Z0-9\\-\\_]+)$', function ($argv) {
    $package_name = $argv[1];
    if (Core\PackagistHandler::autoremove($package_name)) {
        return "Autoremoved {$package_name}";
    }
    return "Couldn't autoremove {$package_name}";
}, 'packagist:autoremove');
/**
 * Autoremoves a certain package of a certain version
 */
Workbench::register('^packagist:autoremove ([a-zA-Z0-9\\-\\_]+)\\/([a-zA-Z0-9\\-\\_]+) (.+)$', function ($argv) {
    $package_name = $argv[1];
    if (Core\PackagistHandler::autoremove($package_name, $argv[2])) {
        return "Autoremoved {$package_name}";
    }
    return "Couldn't autoremove {$package_name}";
});
Ejemplo n.º 9
0
Workbench::register('^new:layout ([a-zA-Z0-9\\_\\.]+)$', function ($argv) {
    $name = $argv[1];
    $dot_pos = strrpos($name, '.');
    if ($dot_pos !== false) {
        $dir = Core\App::layouts()->directory(substr($name, 0, $dot_pos));
        if (!$dir->exists()) {
            $dir->create();
        }
    }
    $layout = Core\App::layouts()->file($name . '.wow.php', 2);
    if (Core\Wow::flavor() == Core\Wow::AT_SIGN) {
        $layout->write('<!DOCTYPE html>
<html>
    <head>
        @section:head
    </head>
    <body>
        @section:body
    </body>
</html>');
    } else {
        $layout->write('<!DOCTYPE html>
<html>
    <head>
        <section name="head" />
    </head>
    <body>
        <section name="body" />
    </body>
</html>');
    }
}, 'new:layout');
Ejemplo n.º 10
0
<?php

namespace Application;

use xTend\Workbench\Workbench;
Workbench::register('^init$', function ($argv) {
    $configuration_file = Core\App::config()->file('Sessions.sessions.json');
    $configuration = json_decode($configuration_file->read(), true);
    // set values
    $configuration['sessionName'] = sha1(random_bytes(8));
    $configuration['initiatedKey'] = sha1(random_bytes(8));
    $configuration['userAgentKey'] = sha1(random_bytes(8));
    $configuration['salt'] = sha1(random_bytes(8));
    $configuration['userSessionsKey'] = sha1(random_bytes(8));
    $configuration['userCookiesKey'] = sha1(random_bytes(8));
    // write configuration
    $configuration_file->write(json_encode($configuration));
}, 'init');
Workbench::register('^init show$', function ($argv) {
    $configuration_file = Core\App::config()->file('Sessions.sessions.json');
    $configuration = json_decode($configuration_file->read(), true);
    echo "\n";
    foreach ($configuration as $key => $value) {
        echo str_pad($key, 30) . $value . "\n";
    }
    echo "\n";
}, 'init show');
Ejemplo n.º 11
0
<?php

namespace Application;

use xTend\Workbench\Workbench;
/**
 * Shows the application routes
 * (those not under restrict)
 */
Workbench::register('^routes$', function ($argv) {
    $routes = Core\Router::all();
    foreach ($routes as $route) {
        echo '/' . str_pad($route->handle(), 28) . $route . PHP_EOL;
    }
}, 'routes');
Ejemplo n.º 12
0
use xTend\Workbench\Workbench;
/**
 * Adds an existing app to the project
 *
 * @param $argv array
 */
Workbench::register('^add ([a-zA-Z0-9\\.\\_]+) (.+?) (.+?)$', function ($argv) {
    // get application name
    $name = $argv[1];
    // get domain and path restrictions
    $domain = $argv[2] === 'any' ? '*' : $argv[2];
    $path = $argv[3] === 'any' ? '*' : $argv[3];
    // check for existance
    if (!is_dir($name)) {
        die('Application folder not found');
    }
    // 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);
    // add application to config
    Workbench::new($name, $domain, $path);
});
Ejemplo n.º 13
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');
Ejemplo n.º 14
0
<compile value="change+version" />');
    }
}, 'new:view');
/**
 * Creates a new view which extends a layout
 */
Workbench::register('^new:view ([a-zA-Z0-9\\_\\.]+) ([a-zA-Z0-9\\_\\.]+)$', function ($argv) {
    $name = $argv[1];
    $dot_pos = strrpos($name, '.');
    // get and check layout
    $layout = $argv[2];
    if (!Core\App::layouts()->file($layout . '.wow.php', 2)->exists()) {
        die('Layout does not exist');
    }
    if ($dot_pos !== false) {
        $dir = Core\App::views()->directory(substr($name, 0, $dot_pos));
        if (!$dir->exists()) {
            $dir->create();
        }
    }
    $view = Core\App::views()->file($name . '.wow.php', 2);
    if (Core\Wow::flavor() == Core\Wow::AT_SIGN) {
        $view->write('@version:1
@layout:' . $layout . '
@compile:change+version');
    } else {
        $view->write('<version value="1" />
<layout value="' . $layout . '" />
<compile value="change+version" />');
    }
});
Ejemplo n.º 15
0
/**
 * Executes phinx command
 *
 * @param $argv array
 */
Workbench::register('^phinx', function ($argv) {
    if (count($argv) > 1) {
        $config_param = false;
        foreach ($argv as $arg) {
            if (substr($arg, 0, 16) == '--configuration=' || $arg == '-c' || $arg == '--configuration') {
                $config_param = true;
                break;
            }
        }
        if ($config_param === false) {
            $argv[] = '-c';
            $argv[] = '' . Core\App::config()->file('ORM.db.yml');
        }
    }
    // create directory and exclude file
    $directory = Core\App::config()->directory('ORM.db');
    if (!$directory->exists()) {
        $directory->create();
    }
    $exclude_file = Core\App::config()->file('ORM.db..exclude', 1);
    if (!$exclude_file->exists()) {
        $exclude_file->write("");
    }
    $_SERVER['argv'] = $argv;
    require __DIR__ . '/../Phinx/robmorgan-phinx/bin/phinx';
});
Ejemplo n.º 16
0
use xTend\Workbench\Workbench;
/**
 * Contains help command
 */
Workbench::register('^help$', function ($argv) {
    // contains help information
    $help = ['init' => 'Initializes xTend application with secure keys', 'init show' => 'Shows xTend session configuration', 'routes' => 'Displays the routes of the currently selected application (only those NOT under a restrict)', 'set:public [Name]' => 'Moves the public directory', 'set:application [Name]' => 'Sets the current workbench application', 'new [AppName] [Domain or any] [Path or any]' => 'Creates a new application in the current project by certain domain or path restrictions', 'add [AppName] [Domain or any] [Path or any]' => 'Adds an existing application to the project', 'remove [AppName]' => 'Removes an application', 'rename [AppName]' => 'Renames your application', 'new:controller [ControllerName]' => 'Creates a new default controller', 'new:controller [ControllerName] empty' => 'Creates a new empty controller', 'new:controller [ControllerName] json' => 'Creates a new respond contoller', 'new:model [ModelName]' => 'Creates a new default ORM \'connected\' model', 'new:model [ModelName] empty' => 'Creates a new empty model', 'new:layout [LayoutName]' => 'Creates a new basic layout', 'config' => 'Shows the current application\'s configuration', 'config [Name]' => 'Gets a certain configuration variable from the application\'s configuration', 'config [Name] [Value]' => 'Sets a configuration variable of the current application', 'wow:flavor [HTML,AT_SIGN,COMBINED]' => 'Sets the current WOW flavor', 'packagist:install' => 'Installs packages from packagist.json file', 'packagist:install [Vendor/Package]' => 'Installs a packagist package', 'packagist:update [Vendor/Package]' => 'Updates a packagist package', 'packagist:install [Vendor/Package] [Version]' => 'Installs a packagist package of a specific version', 'packagist:remove [Vendor/Package]' => 'Removes a packagist package', 'packagist:autoremove [Vendor/Package]' => 'Removes the dependencies of a certain package', 'packagist:autoremove [Vendor/Package] [Version]' => 'Removes the dependencies of a certain package of a certain version', 'packagist:autoremove [Vendor/Package] recursive' => 'Removes the dependencies, and the dependencies of the dependencies', 'packagist:autoremove [Vendor/Package] [Version] recursive' => 'Removes the dependencies of a certain package and the dependencies of the dependencies', 'phinx' => 'Show the integrated phinx command line help', 'phinx [Command] ...' => 'Execute phinx command\'s right form the workbench', 'help' => 'Shows information about the workbench\'s commands'];
    // checks for a command similarity match
    $command_match = [];
    $match_percent = 0;
    foreach (Workbench::$commands as $name => $command) {
        similar_text(Workbench::$command, $name, $match_percent);
        if ($match_percent > 50 && $match_percent < 100) {
            $command_match[] = $name;
        }
    }
    // if similarity found or not
    if (count($command_match) > 0) {
        echo "\nDid you mean one of these: \n";
        foreach ($command_match as $command) {
            echo $command . "\n";
        }
    } else {
        echo "xTend CLI\n";
        foreach ($help as $cm => $info) {
            echo "{$cm}\n  {$info}\n\n";
        }
    }
    echo "\n";
}, 'help');