Version 1.0
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use PhpSchool\CliMenu\CliMenu;
|
||||
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
|
||||
|
||||
class GeneratorController {
|
||||
|
||||
//The folder to be created
|
||||
private $name_path = '';
|
||||
//The tables to be created
|
||||
private $tables = Array();
|
||||
|
||||
function menu() {
|
||||
|
||||
$default_behavior = function (CliMenu $clm) {
|
||||
|
||||
};
|
||||
|
||||
$module_name = function(CliMenu $clm) {
|
||||
|
||||
$result = $clm->askText()
|
||||
->setPlaceholderText('Enter something here')
|
||||
->ask();
|
||||
|
||||
$this->name_path = $result->fetch();
|
||||
$clm->getSelectedItem()->showItemExtra();
|
||||
};
|
||||
|
||||
$show_info = function(CliMenu $clm) {
|
||||
$clm->flash('Module name and path \n' . $this->name_path)->display();
|
||||
};
|
||||
|
||||
/* $menu = (new CliMenuBuilder)
|
||||
->setTitle(Lang::get_string('main_title', 'generator'))
|
||||
->addItem(Lang::get_string('name_definition', 'generator'), $module_name)
|
||||
->addItem(Lang::get_string('show_info', 'generator'), $show_info)
|
||||
->setItemExtra('[COMPLETE!]')
|
||||
->addLineBreak('-')
|
||||
->setBorder(1, 2, 'yellow')
|
||||
->setPadding(2, 4)
|
||||
//->setMarginAuto()
|
||||
->build();
|
||||
|
||||
$menu->open(); */
|
||||
/* $menu = (new CliMenuBuilder)
|
||||
->setTitle('CLI Menu')
|
||||
->addItem('First Item', $default_behavior)
|
||||
->addItem('Second Item', $default_behavior)
|
||||
->addLineBreak('-')
|
||||
->addSubMenu('Options', function (CliMenuBuilder $b) {
|
||||
$b->setTitle('CLI Menu > Options')
|
||||
->addItem('First option', function (CliMenu $menu) {
|
||||
echo sprintf('Executing option: %s', $menu->getSelectedItem()->getText());
|
||||
})
|
||||
->addLineBreak('-');
|
||||
})
|
||||
->setWidth(70)
|
||||
->setBackgroundColour('yellow')
|
||||
->build();
|
||||
$menu->open(); */
|
||||
$callable = function (CliMenu $menu) {
|
||||
echo "I'm just a boring selectable item";
|
||||
};
|
||||
|
||||
$menu = (new CliMenuBuilder)
|
||||
->addItem('Normal Item', function(){})
|
||||
->addSubMenu('Super Sub Menu', function (CliMenuBuilder $b) {
|
||||
$b->setTitle('Behold the awesomeness')
|
||||
->addItem('asdasdasdas', function(){});
|
||||
})
|
||||
->build();
|
||||
$menu->open();
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use BBRouter\RouteCollection as RouteCollection;
|
||||
|
||||
|
||||
RouteCollection::add('CLI', '/core/purge', function(){
|
||||
echo "Purging Everything\n";
|
||||
});
|
||||
|
||||
RouteCollection::add('CLI', '/core/purge/[h:module]', function($module){
|
||||
echo "Purgin $module\n";
|
||||
});
|
||||
|
||||
RouteCollection::add('CLI', '/core/routes', function(){
|
||||
foreach(RouteCollection::return_routes() as $route){
|
||||
echo str_pad( implode(',', $route->_verb), 10) . "| $route->_uri \n";
|
||||
}
|
||||
});
|
||||
|
||||
RouteCollection::add('CLI', '/core/generator', function(){
|
||||
|
||||
include_once 'GeneratorController.php';
|
||||
last_class()->menu();
|
||||
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
$string['generator']['module_name'] = 'generator';
|
||||
|
||||
$string['generator']['main_title'] = 'Module Generator';
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
$string['generator']['module_name'] = 'wellcome';
|
||||
|
||||
$string['generator']['main_title'] = 'Gerador de modulos!';
|
||||
|
||||
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use BBRouter\RouteCollection as RouteCollection;
|
||||
use DDLWrapper\Wrapper as Wrapper;
|
||||
|
||||
RouteCollection::add('CLI', 'sanity/install', function() {
|
||||
include_once 'classes/Migrator.class.php';
|
||||
|
||||
global $DB;
|
||||
Wrapper::set_driver($DB);
|
||||
|
||||
Migrator::getInstance()->execute_plan();
|
||||
|
||||
Wrapper::commit();
|
||||
})->middleware_ignore('auth');
|
||||
|
||||
|
||||
RouteCollection::add('*', '*', function() {
|
||||
global $ROUTE;
|
||||
//App need to be installed
|
||||
if (!is_file(DIR_CONFIG . 'modules.ini')) {
|
||||
$ROUTE->do_block()->set_http_error(500);
|
||||
}
|
||||
}, -19)->do_ignore()->middleware_ignore('auth');
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
class Migrator{
|
||||
|
||||
private static $instance;
|
||||
|
||||
private $instaled;
|
||||
private $phisical;
|
||||
|
||||
private $uninstall = Array();
|
||||
private $downgrade = Array();
|
||||
|
||||
private $upgrade = Array();
|
||||
private $install = Array();
|
||||
|
||||
private function __construct(){
|
||||
$this->load_installed_plugins();
|
||||
$this->load_physical_plugins();
|
||||
}
|
||||
|
||||
private static function newObj(){
|
||||
if (!isset( self::$instance )) {
|
||||
self::$instance = new Migrator();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public static function getInstance(){
|
||||
if (!isset(self::$instance)) {
|
||||
return self::newObj();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function save(){
|
||||
$out = '';
|
||||
foreach ($this->instaled as $instaled){
|
||||
$out .= "[$instaled->name]\n";
|
||||
$out .= "name=$instaled->name\n";
|
||||
$out .= "version=$instaled->version\n\n";
|
||||
}
|
||||
file_put_contents(DIR_CONFIG.'/modules.ini', $out);
|
||||
}
|
||||
|
||||
private function is_satisfy($name, $version){
|
||||
if(!isset($this->instaled[$name])){
|
||||
return false;
|
||||
}
|
||||
if($this->instaled[$name]->version >= $version){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function is_satisfy_array($array){
|
||||
foreach ($array as $item){
|
||||
if( !self::is_satisfy($item->name, $item->version) ){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update_plugin_version($name, $version){
|
||||
echo "Atualizando $name para versão $version\n";
|
||||
if( isset($this->instaled[$name]) ){
|
||||
$this->instaled[$name]->version = $version;
|
||||
return;
|
||||
}
|
||||
$this->instaled[$name] = new stdClass();
|
||||
$this->instaled[$name]->name = $name;
|
||||
$this->instaled[$name]->version = $version;
|
||||
}
|
||||
|
||||
private function load_installed_plugins(){
|
||||
$installed = parse_ini_file(DIR_CONFIG.'/modules.ini', true);
|
||||
|
||||
foreach ($installed as $key => $item) {
|
||||
$installed[$key] = (object) $item;
|
||||
}
|
||||
|
||||
return $this->instaled = $installed;
|
||||
}
|
||||
|
||||
private function load_physical_plugins(){
|
||||
$module_configs = Array();
|
||||
$plugins = Array();
|
||||
|
||||
$rdi = new RecursiveDirectoryIterator(DIR_MODULE);
|
||||
|
||||
foreach(new RecursiveIteratorIterator($rdi) as $file){
|
||||
if( strpos($file, 'version.php') ){
|
||||
$module_configs[] = str_replace('version.php','', $file);
|
||||
}
|
||||
}
|
||||
foreach ($module_configs as $module_config) {
|
||||
$plugin = new stdClass();
|
||||
include $module_config . 'version.php';
|
||||
$plugins[$plugin->name] = $plugin;
|
||||
if(is_file( $module_config . 'db/Migrate.php') ){
|
||||
//echo 'aaaaaaaaaaaa';
|
||||
include $module_config . 'db/Migrate.php';
|
||||
}
|
||||
}
|
||||
$this->phisical = $plugins;
|
||||
}
|
||||
|
||||
public function physical_list(){
|
||||
return $this->phisical;
|
||||
}
|
||||
|
||||
public function installed_list(){
|
||||
return $this->instaled;
|
||||
}
|
||||
|
||||
public function instal_list(){
|
||||
return $this->install;
|
||||
}
|
||||
|
||||
public function uninstal_list(){
|
||||
return $this->uninstall;
|
||||
}
|
||||
|
||||
public function sort_plugins(){
|
||||
foreach ($this->phisical as $key => $plugin){
|
||||
if( !isset($this->instaled[$key]) ){
|
||||
$this->install[] = $plugin;
|
||||
continue;
|
||||
}
|
||||
if( $this->instaled[$key]->version < $plugin->version){
|
||||
$this->upgrade[] = $plugin;
|
||||
continue;
|
||||
}
|
||||
if( $this->instaled[$key]->version > $plugin->version){
|
||||
$this->downgrade[] = $plugin;
|
||||
continue;
|
||||
}
|
||||
$this->uninstall[] = $plugin;
|
||||
}
|
||||
}
|
||||
|
||||
public function execute_plan(){
|
||||
$status = false;
|
||||
while(! $status ){
|
||||
$this->sort_plugins();
|
||||
$status = true;
|
||||
|
||||
foreach ($this->install as $key => $item) {
|
||||
if( isset($item->require) ){
|
||||
if( !self::is_satisfy_array($item->require) ){ $status = false; continue; }
|
||||
}
|
||||
if(!self::is_satisfy($item->name, $item->version) ){
|
||||
if(!function_exists($item->name.'_upgrade')){
|
||||
$this->update_plugin_version($item->name, $item->version);
|
||||
$this->upgrade[] = $item;
|
||||
unset($this->install[$key]);
|
||||
continue;
|
||||
}
|
||||
call_user_func($item->name.'_upgrade', 0);
|
||||
$this->upgrade[] = $this->instaled[$item->name];
|
||||
unset($this->install[$key]);
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->upgrade as $item) {
|
||||
if( isset($item->require) ){
|
||||
if( !self::is_satisfy_array($item->require) ){ $status = false; continue; }
|
||||
}
|
||||
if(!self::is_satisfy($item->name, $item->version) ){
|
||||
if(!function_exists($item->name.'_upgrade')){
|
||||
$this->update_plugin_version($item->name, $item->version);
|
||||
continue;
|
||||
}
|
||||
call_user_func($item->name.'_upgrade', $this->instaled[$item->name]->version);
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->save();
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
function core_migrator_upgrade_plugin_version($name, $version){
|
||||
$migrator = Migrator::getInstance();
|
||||
}
|
||||
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
class Output {
|
||||
|
||||
private static $_instance;
|
||||
private $_doctype = "<!DOCTYPE html>";
|
||||
private $_head_items = Array();
|
||||
private $_body = "";
|
||||
private $_content = "";
|
||||
private $_foot_items = Array();
|
||||
private $view = false;
|
||||
|
||||
//SINGLETON==============================================
|
||||
private function __construct() {
|
||||
|
||||
}
|
||||
|
||||
private static function newObj() {
|
||||
if (!isset(self::$_instance)) {
|
||||
self::$_instance = new Output();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public function getInstance() {
|
||||
if (!isset(self::$_instance)) {
|
||||
return self::newObj();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public static function load_view($name, $values = null, $location = null) {
|
||||
if (!$location) {
|
||||
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
|
||||
array_pop($segments);
|
||||
$location = implode('/', $segments) . '/views/';
|
||||
}
|
||||
|
||||
if (is_array($values) && count($values) > 0) {
|
||||
extract($values, EXTR_PREFIX_SAME, 'data');
|
||||
}
|
||||
|
||||
$location .= $name;
|
||||
|
||||
if (strpos('.php', $location) == 0) {
|
||||
$location .= '.php';
|
||||
}
|
||||
|
||||
if (!file_exists($location)) {
|
||||
//return require_once GENERAL_VIEW_FOLDER . 'errors/404.php';
|
||||
}
|
||||
return require_once( $location );
|
||||
}
|
||||
|
||||
private function render_view() {
|
||||
if (is_array($this->view['values']) && count($this->view['values']) > 0) {
|
||||
extract($this->view['values'], EXTR_PREFIX_SAME, 'data');
|
||||
}
|
||||
return require_once( $this->view['location'] );
|
||||
}
|
||||
|
||||
public function set_view($name, $values = null, $location = null) {
|
||||
if (!$location) {
|
||||
$segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
|
||||
array_pop($segments);
|
||||
$location = implode('/', $segments) . '/views/';
|
||||
}
|
||||
|
||||
$location .= $name;
|
||||
|
||||
if (strpos('.php', $location) == 0) {
|
||||
$location .= '.php';
|
||||
}
|
||||
|
||||
$this->view = Array();
|
||||
$this->view['location'] = $location;
|
||||
$this->view['values'] = $values;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
if (is_ajax_request()) {
|
||||
echo $this->_content;
|
||||
if ($this->view) {
|
||||
$this->render_view();
|
||||
}
|
||||
return;
|
||||
}
|
||||
global $DROPDOWN, $SIDEBAR;
|
||||
|
||||
$this->_head_items[] = '<script src="/plugins/jquery/jquery.min.js"></script>';
|
||||
|
||||
$this->_head_items[] = '<script src="/plugins/mousetrap/mousetrap.min.js"></script>';
|
||||
|
||||
$this->_head_items[] = '<script src="/plugins/jquery-mask-plugin/jquery.mask.min.js"></script>';
|
||||
|
||||
$this->_head_items[] = '<link href="/plugins/bootstrap/bootstrap.min.css" rel="stylesheet" />';
|
||||
$this->_head_items[] = '<script src="/plugins/bootstrap/bootstrap.min.js"></script>';
|
||||
|
||||
$this->_head_items[] = '<link href="/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />';
|
||||
|
||||
$this->_head_items[] = '<link href="/plugins/normalize-css/normalize.css" rel="stylesheet">';
|
||||
$this->_head_items[] = '<link href="/dist/style.css" rel="stylesheet">';
|
||||
|
||||
$this->_head_items[] = '<link href="/dist/theme/black_and_white.css" rel="stylesheet">';
|
||||
|
||||
$this->_head_items[] = '<link href="/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">';
|
||||
$this->_head_items[] = '<script src="/plugins/metisMenu/metisMenu.min.js"></script>';
|
||||
|
||||
$this->_head_items[] = '<link href="/plugins/select2/select2.min.css" rel="stylesheet">';
|
||||
$this->_head_items[] = '<script src="/plugins/select2/select2.min.js"></script>';
|
||||
|
||||
$this->_head_items[] = '<link rel="stylesheet" href="/plugins/datatables/dataTables.css">';
|
||||
$this->_head_items[] = '<script src="/plugins/datatables/dataTables.js"></script>';
|
||||
|
||||
$this->_foot_items[] = '<script src="/dist/script.js"></script>';
|
||||
|
||||
$head = "<head>";
|
||||
foreach ($this->_head_items as $head_item) {
|
||||
$head .= $head_item . "\n";
|
||||
}
|
||||
$head .= "</head>";
|
||||
$foot = "";
|
||||
foreach ($this->_foot_items as $foot_item) {
|
||||
$foot .= $foot_item;
|
||||
}
|
||||
|
||||
$header = str_replace("{{usermenu}}", "", file_get_contents(__DIR__ . '/views/header.html'));
|
||||
$sidebar = str_replace("{{elements}}", $SIDEBAR->render(), file_get_contents(__DIR__ . '/views/sidebar.html'));
|
||||
|
||||
$body_first = file_get_contents(__DIR__ . "/views/body.html");
|
||||
$body_first = str_replace("{{header}}", $header, $body_first);
|
||||
$body_first = str_replace("{{sidebar}}", $sidebar, $body_first);
|
||||
$body_first .= $this->_content;
|
||||
|
||||
$foot .= '<div id="modal" class="modal fade" role="dialog"> </div>';
|
||||
|
||||
$body_end = file_get_contents(__DIR__ . "/views/body_section.html");
|
||||
$body_end = str_replace("{{footer}}", $foot, $body_end);
|
||||
|
||||
echo $this->_doctype . "\n";
|
||||
echo "<html> \n";
|
||||
echo $head;
|
||||
echo $body_first;
|
||||
if ($this->view) {
|
||||
$this->render_view();
|
||||
}
|
||||
echo $body_end;
|
||||
echo "</html>";
|
||||
}
|
||||
|
||||
public function set_content($content) {
|
||||
$this->_content = $content;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use BBRouter\RouteCollection as RouteCollection;
|
||||
use MenuBuilder\Menu as Menu;
|
||||
|
||||
RouteCollection::add('GET', '*', function(){
|
||||
|
||||
include_once 'Output.class.php';
|
||||
|
||||
GLOBAL $SIDEBAR, $DROPDOWN, $OUTPUT;
|
||||
|
||||
$SIDEBAR = new Menu( array('id' => 'side-menu', 'class' => "nav") );
|
||||
$DROPDOWN = new Menu( array("class" => 'dropdown-menu') );
|
||||
|
||||
$OUTPUT = Output::getInstance();
|
||||
|
||||
}, -11)->do_ignore();
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<!-- Sidebar -->
|
||||
{{sidebar}}
|
||||
<!-- /#sidebar-wrapper -->
|
||||
|
||||
<!-- Page Content -->
|
||||
<div id="main-page-wrapper">
|
||||
|
||||
{{header}}
|
||||
|
||||
<div id="progress" class="progress hidden" >
|
||||
<div class="progress-bar progress-bar-striped progress-bar-animated active" style="width: 100%;"></div>
|
||||
</div>
|
||||
<!-- BreadCrumbs -->
|
||||
|
||||
<!-- /BreadCrumbs -->
|
||||
|
||||
<div id="page-content-wrapper">
|
||||
<div class="container-fluid" style="height: 1024px;">
|
||||
|
||||
<div class="row">
|
||||
<div id="content" class="col-lg-12">
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- /#page-content-wrapper -->
|
||||
</div>
|
||||
{{footer}}
|
||||
</body>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<header style='min-height: 50px; background-color: #000;'>
|
||||
<ul class="nav navbar-nav navbar-left">
|
||||
<li class="tooltip-sidebar-toggle">
|
||||
<a href="" id="menu-toggle">
|
||||
<i class="fa fa-th-list" aria-hidden="true"></i>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- <ul id='menu-usuario' class="nav navbar-nav navbar-right nav-dropdown">
|
||||
<li class="dropdown">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" data-method="reload">
|
||||
<i class="fa fa-user" aria-hidden="true"></i> <span class="caret"></span>
|
||||
</a>
|
||||
{{usermenu}}
|
||||
</li>
|
||||
</ul> -->
|
||||
</header>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<!-- Sidebar -->
|
||||
<nav id="sidebar-wrapper">
|
||||
<div class="logo" style="">
|
||||
<img src='/media/logo.png' alt="logo" />
|
||||
</div>
|
||||
<!-- <div class="search-nav" style="">
|
||||
<input class="form-control" type="text" placeholder="Busca"/>
|
||||
</div> -->
|
||||
|
||||
<hr />
|
||||
{{elements}}
|
||||
<ul id="side-second-menu" class="hidden nav">
|
||||
</ul>
|
||||
</nav>
|
||||
<!-- /#sidebar-wrapper -->
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
use BBRouter\RouteCollection as RouteCollection;
|
||||
use RequestResponse\Response as Response;
|
||||
|
||||
RouteCollection::add("GET", '/', function() {
|
||||
global $OUTPUT;
|
||||
$OUTPUT->load_view('wellcome');
|
||||
})->middleware_ignore('auth');
|
||||
|
||||
RouteCollection::add("GET", '/wellcome', function() {
|
||||
Response::json('This is an other wellcome message')->send();
|
||||
})->middleware_ignore('auth');
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
$string['wellcome']['module_name'] = 'wellcome';
|
||||
|
||||
$string['wellcome']['wellcome'] = 'Bem-vindo!';
|
||||
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<div style="text-align: center">
|
||||
<img src="media/logo_black.png" />
|
||||
</div>
|
||||
|
||||
Wellcome to hell...
|
||||
<br />
|
||||
I shal be your guide
|
||||
Reference in New Issue
Block a user