/** * Add all middleware * @param Slim $application */ public static function middleware(Slim $application) { if (sizeof(Config::get('app.middleware'))) { foreach (Config::get('app.middleware') as $middleware) { $middleware = explode('@', $middleware); $classMiddleware = $middleware[0]; $add = isset($middleware[1]) ? new $classMiddleware(Config::get($middleware[1])) : new $classMiddleware(); $application->add($add); } } }
/** * Check if backend or front end * @return bool */ public function isBackEnd() { $route = $this->app()->request()->getPath() . '/'; if (preg_match('/\\/' . Config::get('app.managerSlugPAth') . '\\//', $route)) { return true; } return false; }
<?php require 'vendor/autoload.php'; require_once \App\Concept\Config::basePath('src') . '/app.php';
/** * set raw script or styles * @param null $content */ public static function raw($content = null) { if (!is_null($content)) { /** * get fullpath */ $fullPath = Config::basePath('http/web/tpl/raw/'); $fullPath .= str_replace('::', '/', $content); $fullPath .= '.tpl'; /** * fetch template */ self::$raw[] = \View::fetch($fullPath); } }
/** * Check if data as posted and validate * fields with rules specified in rules.yml * @param string $rule * @param array $unset * @return array */ public function posts($rule = '', array $unset = []) { if (\Request::isPost()) { $results = ['valid' => false]; /** * get all posts */ $posts = \Request::post(); /** * unset unused fields if * needed */ if (sizeof($unset)) { foreach ($unset as $fields) { unset($posts[$fields]); } } /** * get rules */ $rules = $rule ? Config::get('rules.' . $rule) : []; /** * use GUMP library to validate * and sanitize fields */ $validator = new \GUMP(); $posts = $validator->sanitize($posts); $validator->validation_rules($rules); $validated = $validator->run($posts); /** * check validations result */ if (!$validated) { $results['error'] = $validator->errors(); $results['data'] = $posts; } else { $results['valid'] = true; $results['data'] = $posts; } return $results; } return []; }
<?php use App\Concept\ConceptApp; use App\Concept\Config; $conceptApp = ConceptApp::boot()->app(); require_once Config::basePath('src') . '/routes.php'; App::run();