Skip to content

Commit

Permalink
Merge pull request #10 from SilverEngine/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
SilverEngineTeam authored Jan 7, 2018
2 parents fd7c679 + 3985c2a commit 78a1403
Show file tree
Hide file tree
Showing 22 changed files with 256 additions and 259 deletions.
3 changes: 2 additions & 1 deletion App/Controllers/WelcomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function welcome()

public function demo()
{
return View::make('welcome')->withComponent($data);;
$data = [];
return View::make('welcome')->withComponent($data);
}
}
1 change: 1 addition & 0 deletions App/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
use Silver\Core\Route;

Route::get('/', 'Welcome@welcome', 'home', 'public');
Route::get('/demo', 'Welcome@demo', 'home', 'public');
10 changes: 6 additions & 4 deletions App/Templates/Controller.ghost.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controllers;

use Silver\Core\Controller;
use Silver\Http\View;

/**
* {{{$name}}} controller
Expand All @@ -11,21 +12,22 @@ class {{{ucfirst($name)}}}Controller extends Controller
{
public function get()
{
return "Welcome in {{$name}} controller. This file is on App/Controllers/";
echo "Welcome in {{$name}} controller. This file is on App/Controllers/";
//return View::make('');
}

public function post()
{
echo 'Methode: post';
echo 'Method: post';
}

public function put()
{
echo 'Methode: put';
echo 'Method: put';
}

public function delete()
{
echo 'Methode: delete';
echo 'Method: delete';
}
}
10 changes: 4 additions & 6 deletions App/Templates/View.ghost.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{{ extends('layouts.master') }}






Welcome in {{{$name}}}.
#set[content]
Welcome in {{{$name}}}.
#end
File renamed without changes.
Empty file removed App/Views/errors/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
</head>

<body>
#block(content)
<a href="{{ route('home') }}">welcome</a>
#block(content)

{{ js('app') }}
</body>
</html>
5 changes: 5 additions & 0 deletions App/Views/test2.ghost.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ extends('layouts.master') }}

#set[content]
Welcome to {{ test2 }} page
#end
2 changes: 0 additions & 2 deletions App/Views/welcome.ghost.php → App/Views/welcome.ghost.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{{ extends('layouts.master') }}

#set[content]

Welcome to SilverEngine demo page

#end
3 changes: 0 additions & 3 deletions Database/Migrations/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class Migrations
{

private static $table = 'migrations';

public static function up()
Expand All @@ -29,12 +28,10 @@ public static function up()
$q->varchar('model_name', 100);
$q->datetime("create_at", 255)->default(new Raw('CURRENT_TIMESTAMP'));
})->execute();

}

public static function down()
{
Query::drop(static::$table)->ifExists()->execute();
}

}
2 changes: 1 addition & 1 deletion Database/Migrations/UsersMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class UsersMigrate
{

private static $table = 'users';
protected static $table = 'users';

public static function up()
{
Expand Down
27 changes: 6 additions & 21 deletions Database/Seeds/DefaultSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,26 @@
class DefaultSeed
{

private static $table;
public static $table;

/**
* Run the database seeds.
*
* @return void
*/
public static function run($model, $table = false)
public static function run()
{
if ($model) {
if ($table)
self::$table = $table;
else
self::$table = $model;

self::{$model}();
} else
return false;
self::Users();
}

/**
* Run the database Users seed.
*
* @return void
*/
protected static function users()
public static function Users($table = 'users')
{
Seed::insert(static::$table, [
Seed::insert('users', [
'username' => 'admin',
'password' => md5('admin'),
'salt' => 'ht4h4',
'email' => 'admin@badget.com',
'email' => 'admin@admin.local',
'active' => 1,
])->execute();

}

}
123 changes: 123 additions & 0 deletions System/App/Controllers/MigrationsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

/**
* SilverEngine - PHP MVC framework
*
* @package SilverEngine
* @author SilverEngine Team
* @copyright 2015-2017
* @license MIT
* @link https://github.com/SilverEngine/Framework
*/

namespace System\App\Controllers;

use Silver\Core\Controller;
use Silver\Database\Query as DB;

class MigrationsController extends Controller
{
public function up($modelName = false)
{
if($modelName){
if($modelName == 'migrations')
return 'This is GLOBAL SYSTEM Name!';

if(! is_file(ROOT.'Database'.DS.'Migrations'.DS.$modelName.'Migrate'.EXT))
return "File or namespace in: ".ROOT."Database".DS."Migrations".DS.ucfirst($modelName)."Migrate".EXT." not exists!";

$namespace = "Database\\Migrations\\";
$migrate = $namespace . ucfirst($modelName).'Migrate';
$migrate::up();
$list[] = $modelName;

$model = ucfirst($modelName).'Migrate';
$check = DB::count()
->from('migrations')->where('model_name',$model)->fetch();

if($check->count == 0)
DB::insert('migrations', ['model_name'=> ucfirst($modelName).'Migrate'])->execute();
}
else{
$models = ['UsersMigrate','Migrations'];
$path = ROOT. 'Database/Migrations/';
$files = array_diff(scandir($path), array('.', '..'));

foreach ($files as $row) {
$row = preg_replace('/.php/', '', $row);

if($row != 'Migrations') {
DB::insert('Migrations', ['model_name'=> $row])->execute();
}

$namespace = "Database\\Migrations\\";
$migrate = $namespace . ucfirst($row);
$migrate::up();
$list[] = $row;
}
}
print_r($list);
return '- Migrations created!';
}

public function down($modelName = false)
{
if($modelName){
if($modelName == 'migrations')
return 'This is GLOBAL SYSTEM Name!';

if(! is_file(ROOT.'Database'.DS.'Migrations'.DS.$modelName.'Migrate'.EXT))
return "File or namespace in: ".ROOT."Database".DS."Migrations".DS.ucfirst($modelName)."Migrate".EXT." not exists!";

$namespace = "Database\\Migrations\\";
$migrate = $namespace . ucfirst($modelName).'Migrate';
$migrate::down();
$list[] = $modelName;
}
else{
$path = ROOT. 'Database/Migrations/';
$files = array_diff(scandir($path), array('.', '..'));

foreach ($files as $row) {
$row = preg_replace('/.php/', '', $row);

$namespace = "Database\\Migrations\\";
$migrate = $namespace . ucfirst($row);
$migrate::down();
$list[] = $row;
}
}
print_r($list);
return '- Migrations created!';
}

public function all()
{

$pathMigrations = ROOT. 'Database/Migrations/';
$filesMigrations = array_diff(scandir($pathMigrations), array('.', '..'));

foreach ($filesMigrations as $row) {
$row = preg_replace('/.php/', '', $row);
$namespace = "Database\\Migrations\\";
$migrate = $namespace . ucfirst($row);
$migrate::up();
$list[] = $row;
}

$pathSeeds = ROOT. 'Database/Seeds/';
$filesSeeds = array_diff(scandir($pathSeeds), array('.', '..'));

foreach ($filesSeeds as $row) {
$row = preg_replace('/.php/', '', $row);
$namespace = "Database\\Seeds\\";
$seed = $namespace . ucfirst($row);
$seed::run();
$listSeeds[] = $row;
}

print_r($list);
print_r($listSeeds);
return '- Migrations created!';
}
}
Loading

0 comments on commit 78a1403

Please sign in to comment.