<?php use Inphinit\App; use Inphinit\View; use Inphinit\Request; use Inphinit\Routing\Route; App::on('changestatus', function ($status, $msg) { if ($status === 503) { echo 'This site is currently down for maintenance and should be back soon!'; } elseif (in_array($status, array(401, 403, 404, 500, 501))) { View::forceRender(); View::render('httpview', array('title' => $msg ? $msg : 'Página inacessível', 'method' => $_SERVER['REQUEST_METHOD'], 'path' => Request::path(), 'route' => Request::path(true), 'status' => $status)); exit; } }); Route::set('ANY', '/', 'Home:index'); // Navitate to http://[server]/user/[YOUR NAME] like: http://[server]/user/mary Route::set('ANY', 're:#^/user/([a-z0-9_]+)$#', 'Users.Profile:view'); // Navitate to http://[server]/info Route::set('ANY', '/info', 'Examples:info'); // Navitate to http://[server]/closure Route::set('ANY', '/closure', 'Examples:arrayClosure');
public static function exec() { if (self::$initiate) { return null; } self::trigger('init'); self::$initiate = true; if (self::env('maintenance') === true) { self::stop(503); } self::trigger('changestatus', array(\UtilsStatusCode(), null)); $route = Route::get(); if ($route) { $mainController = $route['controller']; $parsed = explode(':', $mainController, 2); $mainController = '\\Controller\\' . strtr($parsed[0], '.', '\\'); $action = $parsed[1]; $run = new $mainController(); call_user_func_array(array($run, $action), is_array($route['args']) ? $route['args'] : array()); $run = null; } else { App::stop(404, 'Invalid route'); } if (class_exists('\\Inphinit\\Response', false)) { Response::dispatchHeaders(); } if (class_exists('\\Inphinit\\View', false)) { View::dispatch(); } self::trigger('ready'); self::trigger('finish'); }
public function prepare() { if ($this->ready) { return null; } $this->ready = true; if (empty($this->classMethods)) { Exception::raise($this->fullController . ' is empty ', 2); } $controller = $this->controller; $classMethods = $this->classMethods; foreach ($classMethods as $value) { $route = $this->getRoute($value); if ($route) { Route::set($route[0], $route[1], $controller . ':' . $value); } } }
public function prepare() { if ($this->ready) { return null; } $this->ready = true; if (empty($this->classMethods)) { Exception::raise($this->fullController . ' is empty ', 2); } $format = $this->format; $controller = $this->controller; $classMethods = $this->classMethods; foreach ($classMethods as $value) { if ($value[1] !== '' && ($format === self::BOTH || $format === self::SLASH)) { Route::set($value[0], '/' . $value[1] . '/', $controller . ':' . $value[2]); } if ($format === self::BOTH || $format === self::NOSLASH) { Route::set($value[0], '/' . $value[1], $controller . ':' . $value[2]); } } $controller = $classMethods = null; }