Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrycrocodic committed Oct 11, 2020
1 parent 5ddbe7f commit fbae581
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "crocodicstudio/crudbooster",
"description": "CRUDBooster Is CRUD Generator Based On Laravel Easy To Make An Advanced Backend",
"type": "project",
"type": "library",
"license": "MIT",
"keywords":[
"laravel",
Expand Down
8 changes: 0 additions & 8 deletions src/helpers/CB.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<?php
namespace crocodicstudio\crudbooster\helpers;

use Session;
use Request;
use Schema;
use Cache;
use DB;
use Route;
use Validator;

class CB extends CRUDBooster {
//This CB class is for alias of CRUDBooster class

Expand Down
19 changes: 19 additions & 0 deletions src/helpers/CBRouter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


namespace crocodicstudio\crudbooster\helpers;


class CBRouter
{

public static function getCBControllerFiles() {
$controllers = glob(__DIR__.'/../controllers/*.php');
$result = [];
foreach ($controllers as $file) {
$result[] = str_replace('.php', '', basename($file));
}
return $result;
}

}
1 change: 1 addition & 0 deletions src/helpers/CRUDBooster.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private static function resizeImage($fullFilePath, $resize_width = null, $resize
$images_ext = explode(',', $images_ext);

$filename = basename($fullFilePath);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$file_path = trim(str_replace($filename, '', $fullFilePath), '/');

$file_path_thumbnail = 'uploads_thumbnail/'.date('Y-m');
Expand Down
14 changes: 12 additions & 2 deletions src/helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
|
*/

if(!function_exists('db')) {
/**
* @param string $table
* @return \Illuminate\Database\Query\Builder
*/
function db(string $table) {
return \Illuminate\Support\Facades\DB::table($table);
}
}

if(!function_exists('assetThumbnail')) {
function assetThumbnail($path) {
$path = str_replace('uploads/','uploads_thumbnail/',$path);
Expand Down Expand Up @@ -63,8 +73,8 @@ function now() {
|
*/
if(!function_exists('g')) {
function g($name) {
return Request::get($name);
function g($key, $default) {
return request($key, $default);
}
}

Expand Down
28 changes: 13 additions & 15 deletions src/routes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php

/* ROUTER FOR API GENERATOR */

use crocodicstudio\crudbooster\helpers\CBRouter;
use crocodicstudio\crudbooster\helpers\CRUDBooster;
use Illuminate\Support\Facades\Log;

$namespace = '\crocodicstudio\crudbooster\controllers';

Route::group(['middleware' => ['api', '\crocodicstudio\crudbooster\middlewares\CBAuthAPI'], 'namespace' => 'App\Http\Controllers'], function () {
Expand Down Expand Up @@ -68,30 +73,23 @@
], function () {

/* DO NOT EDIT THESE BELLOW LINES */
if (Request::is(config('crudbooster.ADMIN_PATH'))) {
$menus = DB::table('cms_menus')->where('is_dashboard', 1)->first();
if (request()->is(config('crudbooster.ADMIN_PATH'))) {
$menus = db('cms_menus')->where('is_dashboard', 1)->first();
if (! $menus) {
CRUDBooster::routeController('/', 'AdminController', $namespace = '\crocodicstudio\crudbooster\controllers');
}
}

CRUDBooster::routeController('api_generator', 'ApiCustomController', $namespace = '\crocodicstudio\crudbooster\controllers');

try {

$master_controller = glob(__DIR__.'/controllers/*.php');
foreach ($master_controller as &$m) {
$m = str_replace('.php', '', basename($m));
}

$moduls = DB::table('cms_moduls')->whereIn('controller', $master_controller)->get();

foreach ($moduls as $v) {
if (@$v->path && @$v->controller) {
$modules = db('cms_moduls')->whereIn('controller', CBRouter::getCBControllerFiles())->get();
foreach ($modules as $v) {
if (@$v->path && @$v->controller) {
try {
CRUDBooster::routeController($v->path, $v->controller, $namespace = '\crocodicstudio\crudbooster\controllers');
} catch (Exception $e) {
Log::error("Path = ".$v->path."\nController = ".$v->controller."\nError = ".$e->getMessage());
}
}
} catch (Exception $e) {

}
});

0 comments on commit fbae581

Please sign in to comment.