protected function execute(InputInterface $input, OutputInterface $output) { // Index all files $tasks = array(); foreach (\Stativo\Helpers\File::lists('Migration') as $namespace => $files) { foreach ($files as $file) { $migration = $namespace . '\\Migration\\' . $file; $db_mig = Migration::where('name', '=', $file)->first(); if ($db_mig == null) { $mig_insert = new Migration(); $mig_insert->name = $file; $mig_insert->namespace = $migration; $mig_insert->migrated = 0; $mig_insert->save(); } } } // Migrate all unmagrated migrations foreach (Migration::unmigrated()->get() as $migration) { $run = new $migration->namespace(); if (method_exists($run, 'up')) { $output->writeln('Migrating: ' . $migration->name); $run->pre_up(); $run->up(); } $migration->migrated = 1; $migration->save(); } }
public static function boot(Route $route) { if (!empty($route->middleware())) { foreach ($route->middleware() as $middleware) { self::$name = $middleware; $namespace = File::find($middleware, 'Middleware'); $class = new $namespace(); $call = $class->run(self::$request, self::$response); if (is_subclass_of($call, Middleware::class) !== TRUE) { throw new MiddlewareException("':middleware' does not return instance of Stativo\\App\\Middleware", [':middleware' => $middleware]); } } } return TRUE; }
public function index() { $list = File::lists('', ['Language']); $classList = array(); foreach ($list as $namespace => $classes) { foreach ($classes as $className) { $classList[strtolower($className)] = ['namespace' => $namespace, 'class' => $className]; } } $template = view('Stativo/Guide/index'); $template->with('nav', view('Stativo/Guide/navigation')->withList($list)->with('urlClass', $this->request->params('class'))); if ($this->request->params('class') !== NULL) { $class = $classList[$this->request->params('class')]['namespace'] . '\\' . $classList[$this->request->params('class')]['class']; $reflector = new \ReflectionClass($class); $template->with('page', view('Stativo/Guide/class')->withReflect($reflector)); } else { $template->with('page', view('Stativo/Guide/dashboard')); } $this->response->body($template->render()); }
/** * Language class constructor * * @uses Stativo\Core\Core * @param string $locale locale like en_US */ public function __construct($locale = NULL) { self::$_config = Core::config('app')->get('language'); if ($locale !== NULL) { self::$_config['default'] = $locale; } $language_code = strtolower(self::$_config['default']); self::$_config['path'] = APPPATH . 'Language' . DIRECTORY_SEPARATOR . $language_code . DIRECTORY_SEPARATOR; self::$_language_code = $language_code; $filesList = File::lists('Language' . DIRECTORY_SEPARATOR . self::$_language_code); self::$_language_array = array(); foreach ($filesList as $namespace => $files) { foreach ($files as $file) { self::$_language_array[] = (require self::$_config['path'] . $file . '.php'); } } foreach (self::$_language_array as $inner) { foreach ($inner as $key => $value) { self::$_language[$key] = $value; } } return $this; }
public function run() { $call = explode(':', $this->arg->get('call')); $task = ucfirst($call[0]); if (isset($call[1])) { $method = $call[1]; } else { $method = 'run'; } $tasks = array(); foreach (\Stativo\Helpers\File::lists('Task') as $namespace => $files) { foreach ($files as $file) { $task = $namespace . '\\Task\\' . $file; $tasks[] = new $task(); } } $app = new Application('Stativo CLI', '1.0'); $app->addCommands($tasks); $app->run(); // $call = \Stativo\Helpers\File::find($task, 'Task'); // $call = new $call(); // $call->$method(); }
protected function execute(InputInterface $input, OutputInterface $output) { $name = time() . '_' . $input->getArgument('name'); $view = view('Stativo/Migration/create')->with('name', $name); File::toFile($view, APPPATH . 'Migration' . DIRECTORY_SEPARATOR . $name . '.php'); }
/** * Configuration handler * * Loads configuration from an array file en returns * * @uses Stativo\Helpers\File * @uses Stativo\Helpers\MainException * * @param string $config config file name * @return collection collection of config file */ public static function config($config) { $file = File::find($config, 'Config', true); if (file_exists($file) === false) { throw new \Stativo\Helpers\MainException('Cannot find `:file` config. Path: :path', [':file' => $config, ':path' => $file]); } return collect(include $file); }
/** * Will execute the called request, also checks if the request * parameters are correct (like: Method and Middleware) * * @uses Stativo\Core\Middleware * @uses Stativo\Core\Route * @uses Stativo\Helpers\HttpException * @uses Stativo\Helpers\MiddlewareException * @return this */ public function execute() { self::$_server = $_SERVER; self::$_get = $_GET; self::$_post = $_POST; self::$_put = $_POST; self::$_delete = $_POST; // Check if HTTP methods are set if (isset(self::$_post['__method'])) { // if __method isset, then use them if (strtolower(self::$_post['__method']) == strtolower(Route::PUT) or strtolower(self::$_post['__method']) == strtolower(Route::DELETE)) { self::$_method = self::$_post['__method']; } else { // Use default method self::$_method = $_SERVER['REQUEST_METHOD']; } } else { // Use default method self::$_method = $_SERVER['REQUEST_METHOD']; } unset(self::$_post['__method']); unset(self::$_put['__method']); unset(self::$_delete['__method']); // Match URI's in Stativo\Core\Route $match = $this->process_uri(Request::instance()); // Check matches if ($match === null) { // Throw Stativo\Helpers\HttpException (404) throw new HttpException(404, 'URI /:uri is not found!', array(':uri' => $this->uri())); } else { // Match successful! $controller = ''; $action = 'index'; if (isset($match['params']['directory'])) { $controller .= str_replace('/', '\\', $match['params']['directory'] . '/'); unset($match['params']['directory']); } if (isset($match['params']['controller'])) { $controller .= $match['params']['controller']; unset($match['params']['controller']); } if (isset($match['params']['action'])) { $action = $match['params']['action']; unset($match['params']['action']); } // Get current route $route = Route::current(); // Check methods, if they compare then launch class and action if ($route->_method === Route::ANY or in_array(self::$_method, !is_array($route->_method) ? array($route->_method) : $route->_method)) { if ($middleware = Middleware::boot($route)) { self::$_params = $match['params']; // Find required controller $controller = File::find($controller, 'Controller'); // Call classes $class = new $controller(); $class->{$action}(); \Stativo\Helpers\Power::runOff(); } else { throw new MiddlewareException("':middleware' encountered an error!", [':middleware' => Middleware::$name]); } } else { // Throw Stativo\Helpers\HttpException, method mismatch throw new HttpException(500, 'Route method mismatch, Expected: :method request', [':method' => is_array($route->_method) ? implode(', ', $route->_method) : $route->_method]); } } return Response::instance(); }
/** * Constructing Auth */ public function __construct() { $ns = \Stativo\Helpers\File::find('User', 'Model'); $this->_userModel = new $ns(); $this->_config = config('auth'); }
/** * Returns view rendered by Blade on the View layer * * @param mixed * @return void */ function view($view) { $v = new Blade(File::find($view, 'View', true, true), APPPATH . 'Cache'); return $v->view()->make($view); }