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');
<?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(); } }
<?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');
$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 . ' { }'); });
<?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');