protected function execute() { $pathinfo = pathinfo($this->server->getParam('SCRIPT_NAME')); $basePath = $pathinfo['dirname']; $router = new \AltoRouter(); $router->setBasePath($basePath); $routes = $this->metadata->getMetadata('routes'); foreach ($routes as $route) { $router->map($route['method'], $route['rule'], $route['target']); } $match = $router->match(); if (!empty($match)) { $this->parameters = array_merge($match['target'], $match['params']); } }
<?php require 'vendor/autoload.php'; $router = new AltoRouter(); $router->setBasePath('/alto-app/'); $router->map('GET', '/users/[i:id]/', 'UserController#showDetails'); $match = $router->match(); use App\Auth\User; use App\Orders\User as UserOrder; $u = new User(); $u = new UserOrder(); new App\A\Test(); new App\B\Test();
/** * Constructor. * * @param SessionContract $session */ public function __construct(SessionContract $session) { $this->session = $session; $this->altoRouter = new \AltoRouter(); $this->altoRouter->setBasePath(self::DEFAULT_BASE_PATH); $this->controllerNamespace = self::DEFAULT_CONTROLLER_NAMESPACE; }
/** * The default constructor */ protected function __construct() { $this->altoRouter = new \AltoRouter(); if (isset(Configuration::$config['router.base.path']) && !empty(Configuration::$config['router.base.path'])) { $this->altoRouter->setBasePath(Configuration::$config['router.base.path']); } }
/** * @covers AltoRouter::setBasePath */ public function testSetBasePath() { $basePath = $this->router->setBasePath('/some/path'); $this->assertEquals('/some/path', $this->router->getBasePath()); $basePath = $this->router->setBasePath('/some/path'); $this->assertEquals('/some/path', $this->router->getBasePath()); }
public static function mapAllCTL() { $router = new \AltoRouter(); $basePath = AppConfig::get("route.base_path"); if (!is_null($basePath) && trim($basePath) != "") { $router->setBasePath($basePath); } $ctls = self::readCTL(); foreach ($ctls as $ctl) { $router->map(implode('|', $ctl['methods']), $ctl['uri'], array('c' => $ctl['controller'], 'a' => $ctl['action'])); } return $router; }
<?php require '../../AltoRouter.php'; $router = new AltoRouter(); $router->setBasePath('/AltoRouter/examples/basic'); $router->map('GET|POST', '/', 'home#index', 'home'); $router->map('GET', '/users/', array('c' => 'UserController', 'a' => 'ListAction')); $router->map('GET', '/users/[i:id]', 'users#show', 'users_show'); $router->map('POST', '/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do'); // match current request $match = $router->match(); ?> <h1>AltoRouter</h1> <h3>Current request: </h3> <pre> Target: <?php var_dump($match['target']); ?> Params: <?php var_dump($match['params']); ?> Name: <?php var_dump($match['name']); ?> </pre> <h3>Try these requests: </h3> <p><a href="<?php echo $router->generate('home'); ?>
<?php session_start(); define('BASE_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/SENIOR/frontend/'); require '../backend/classes/AltoRouter.php'; $router = new AltoRouter(); $router->setBasePath('/SENIOR/frontend'); //Index $router->map('GET|POST', '/', 'home.php'); //BACKEND $router->map('GET|POST', '/admin', '../backend/login.php', 'admin'); $router->map('GET|POST', '/G-admin', '../backend/indexBE.php', 'adminLogged'); // Items portfolio $router->map('GET|POST', '/G-admin/portfolio', '../backend/imagenesPortfolio.php', 'portfolio'); $router->map('GET|POST', '/G-admin/alta-item', '../backend/services/itemsPortfolio/altaItemProject.php', 'altaItemProject'); $router->map('GET|POST', '/G-admin/alta-item/subirfoto', '../backend/services/itemsPortfolio/uploads.php', 'subirfotos'); $router->map('GET|POST', '/G-admin/services/listarItems', '../backend/services/itemsPortfolio/listarItems.php', 'listarItems'); $router->map('GET|POST', '/G-admin/portfolio/nuevo', '../backend/services/itemsPortfolio/nuevo.php', 'nuevoItem'); $router->map('GET|POST', '/G-admin/portfolio/[*:titPro]/', '../backend/services/itemsPortfolio/item.php', 'itemPortfolio'); $router->map('GET|POST', '/G-admin/modificar/[*:idItem]/[*:titPro]', '../backend/services/itemsPortfolio/modificarItem.php', 'modificarItem'); $router->map('GET|POST', '/G-admin/modificar/[*:idItem]/[*:titPro]', '../backend/services/itemsPortfolio/borrarItem.php', 'borrarItem'); //$router->map('GET|POST','/G-admin/services/eliminarItems', '../backend/services/itemsPortfolio/eliminar.php', 'eliminarItems'); //$router->map('GET|POST','/G-admin/services/eliminarItems/[i:idItem]', '../backend/services/itemsPortfolio/eliminar.php', 'eliminarItems'); // Páginas $router->map('GET|POST', '/G-admin/paginas', '../backend/services/loadPage.php', 'paginas'); $router->map('GET|POST', '/G-admin/proyectos', '../backend/services/listarProyectos.php', 'proyectos'); $router->map('GET|POST', '/G-admin/nueva-pagina', '../backend/services/newPage.php', 'nuevaPag'); $router->map('GET|POST', '/G-admin/alta-pagina', '../backend/services/altaPag.php', 'altaPag'); // Bloques $router->map('GET|POST', '/G-admin/nuevo-bloque', '../backend/services/newBlock.php', 'nuevoBloque'); $router->map('GET|POST', '/G-admin/alta-bloque', '../backend/services/altaBlock.php', 'altaBlock');
<?php require_once __DIR__ . '/../vendor/autoload.php'; require_once dirname(__FILE__) . '/../config/db.php'; require_once dirname(__FILE__) . '/../src/User.php'; $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DB, DB_PORT); if ($conn->connect_error) { $error = $conn->connect_error . '(' . $conn->connect_errno . ')'; echo $error; } else { $conn->set_charset('utf8'); } //tworzymy nowy obiekt AltoRouter $router = new AltoRouter(); //z db.php bierzemy base_path, ktory jest naszym katalogiem glownym po ktorym bedziemy otrzymywac ladne slashe $router->setBasePath(BASE_PATH); include dirname(__FILE__) . '/../routing.php'; $match = $router->match(); //uruchamia nam nasz router i automatycznie dodaje go do kazdej podstrony if ($match) { require '../' . $match['target']; } else { echo "nie ma strony"; } User::setConnection($conn);
$log->pushHandler(new RotatingFileHandler('logs/errors', 1, Logger::ERROR)); $log->pushProcessor(new IntrospectionProcessor(Logger::ERROR)); // # Get instance and load props $PM = new PropertyManager(); // # DAOConnection instance $DAOConn = new DAOConnection($PM); // # Mailer instance $Mailer = new PHPMailer(); // # ChartsBuilder instance $CB = new ChartsBuilder($PM, $log); // # Initializing router $router = new AltoRouter(); // # This app is deployed in production as a subfolder and not a virtualhost // # so we need to set a basepath for prod environment if ($PM->getproperty('env') == 'prod') { $router->setBasePath('/suncharts/'); } // # $Params default $defaults = array('y' => date('Y'), 'm' => date('m'), 'oTypeID' => 1, 'oID' => 'All', 'techID' => 'All', 'oVendorID' => 'All', 'countryID' => 'IT'); // # Config interface $router->map('GET', '/', function () { // # Shows the page require_once "config.html"; }); // # Cron based call ( all params are set to defaults ) $router->map('GET', 'worker/default', function () use($PM, $DAOConn, $log, $CB, $defaults) { // # Unlink latest charts files $CB->clearPast(); // # Response $SR = new ServiceResponse(); try {
<?php require 'AltoRouter.php'; $router = new AltoRouter(); $router->setBasePath('/AltoRouter'); $router->map('GET|POST', '/', 'home#index', 'home'); $router->map('GET', '/users/', array('c' => 'UserController', 'a' => 'ListAction')); $router->map('GET', '/users/[i:id]', 'users#show', 'users_show'); $router->map('POST', '/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do'); // match current request $match = $router->match(); ?> <h1>AltoRouter</h3> <h3>Current request: </h3> <pre> Target: <?php var_dump($match['target']); ?> Params: <?php var_dump($match['params']); ?> Name: <?php var_dump($match['name']); ?> </pre> <h3>Try these requests: </h3> <p><a href="<?php echo $router->generate('home'); ?>
//Construcción de array para json $data_post[] = array('type' => 'twitter', 'content' => $statuse['text'], 'date' => $date_format, 'likes' => $statuse['favorite_count']); } //fin twitter //Instagram $http = new HttpConnection(); $http->init(); $data_instagram = json_decode($http->get("https://api.instagram.com/v1/tags/meat/media/recent?access_token=44110995.1677ed0.6d87a7ce19f544c99e2912686465de59&count=25"), true); $http->close(); foreach ($data_instagram['data'] as $data) { //Formato a fecha $horas_restantes = 4; $date_format = $data['created_time'] - $horas_restantes * 3600; $date_format = date('d/m/Y H:i:s', $date_format); //Construcción de array para json $data_post[] = array('type' => 'instagram', 'content' => $data['images']['standard_resolution']['url'] . ' ' . $data['caption']['text'], 'date' => $date_format, 'likes' => $data['likes']['count']); } //fin instagram //Router $router = new AltoRouter(); $router->setBasePath(''); $router->map('GET', '/posts', 'posts.php', 'posts'); $router->map('GET', '/posts/likes', 'likes.php', 'likes'); $match = $router->match(); if ($match) { require $match['target']; } else { header("HTTP/1.0 404 Not Found"); require '404.php'; } //fin router
<?php require_once __DIR__ . '/../vendor/autoload.php'; session_start(); // prettry error handler $whoops = new \Whoops\Run(); $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); $whoops->register(); // routing handler $router = new AltoRouter(); $router->setBasePath('/talkingspace/public');
/** * Démarrage de l'application. */ public function run() { $router = new \AltoRouter(); if (isset($_SERVER['BASE'])) { $router->setBasePath($_SERVER['BASE']); } $router->map('GET', '/', function () { $this->startControllerAction('Public', 'index'); }, 'home'); $router->map('GET|POST|PATCH|PUT|DELETE', '/[a:controller]/[a:action]', function ($controller, $action) { $this->startControllerAction(ucfirst($controller), $action); }, 'action'); if (($match = $router->match()) !== false) { call_user_func_array($match['target'], $match['params']); } else { header("{$_SERVER['SERVER_PROTOCOL']} 404 Not Found"); } }
<?php // index.php $executionTimers['wooof_1'][0] = microtime(true); require_once '../setup.inc.php'; $wo = new WOOOF(true, null, null, false); if (!$wo->constructedOk) { $wo->handleShowStopperError("1000 Failed to init WOOOF."); } wooofTimerStop('wooof_1'); $router = new AltoRouter(); $router->setBasePath(substr($wo->getConfigurationFor('siteBaseURL') . $wo->getConfigurationFor('publicSite'), 0, -1)); /*******************************************************************/ // the start/home // $router->map('GET', '/', function () use($wo) { VO_CtrlSite::home($wo); }, 'home'); require_once 'routes/movies.php'; require_once 'routes/profile.php'; require_once 'routes/registration.php'; require_once 'routes/evaluations.php'; /* ========================================================================== */ // Find and follow route based on URL // Handling of no matches, etc. inside the 'run' function. $router->run($wo); /* End of file index.php */
// Include Composer's autoloader require ROOT . '/vendor/autoload.php'; // Include Booya global functions require 'functions.php'; // Handle errors in the framework set_error_handler('errorHandler'); set_exception_handler('exceptionHandler'); register_shutdown_function('shutdownHandler'); // TODO: Move this into a Session class and use a config setting // to decide if sessions are allowed to auto-start. session_start(); // Init (loads application by route) $app_classname = $app_ns . '\\Application'; $app = new $app_classname(); $router = new AltoRouter(); $router->setBasePath($app->config('basepath')); $app->defineRoutes($router); $router_match = $router->match(); if ($router_match && is_callable($router_match['target'])) { $response = call_user_func_array($router_match['target'], $router_match['params'])->getResponse(); } else { throw new Booya\Exception\HttpException('Path ' . $_SERVER['REQUEST_URI'] . ' not found', 404); } } catch (Booya\Exception\HttpException $ex) { http_response_code($ex->getCode()); $response_class = $app->config('response_class'); $response = new $response_class(); $controller = new Booya\ErrorController($app, 'error', $ex->getCode(), $response); $controller->setHttpException($ex); } if (is_object($response) && $response instanceof Booya\Response) {
/** * Map a resource to its corresponding controller * * @since 0.1.0 * @access public * @param array $path URI path array * @param string $method HTTP method * @param array $data Request arguments * @return array Dispatch instruction for Garden. * @static */ public static function map($resource, $class, $path, $method, $data) { $router = new AltoRouter(); $router->setBasePath("/api"); $endpoints = $class->endpoints($data); if ($method == "options") { $supports = strtoupper(implode(", ", $class::supports())); $documentation = []; foreach ($endpoints as $method => $endpoints) { foreach ($endpoints as $endpoint => $data) { $documentation[$method][] = paths($resource, $endpoint); } } $documentation = base64_encode(json_encode($documentation)); return ["application" => "API", "controller" => "API", "method" => "options", "arguments" => [$supports, $documentation], "authenticate" => false]; } else { // Register all endpoints in the router foreach ($endpoints as $method => $endpoints) { foreach ($endpoints as $endpoint => $data) { $endpoint = "/" . $resource . rtrim($endpoint, "/"); $router->map($method, $endpoint, $data); } } $match = $router->match("/" . rtrim(join("/", $path), "/")); if (!$match) { throw new Exception(t("API.Error.MethodNotAllowed"), 405); } $target = val("target", $match); $arguments = array_merge(val("params", $match, []), val("arguments", $target, [])); return ["application" => val("application", $target, false), "controller" => val("controller", $target), "method" => val("method", $target, "index"), "authenticate" => val("authenticate", $target), "arguments" => $arguments]; } }
<?php require_once __DIR__ . '/Config.php'; require_once BASE_PATH . '/vendor/altorouter/altorouter/AltoRouter.php'; require_once BASE_PATH . '/app/Routes.php'; defined('BASE_PATH') or exit('No direct script access allowed'); $router = new AltoRouter(); $Routes = new Routes(); $base_path = str_replace('/web/', '', str_replace('index.php', '', $_SERVER['SCRIPT_NAME'])); if ($base_path) { $router->setBasePath($base_path); } if (count(Routes::$routes) > 0) { if (count(Routes::$match_types) > 0) { $router->addMatchTypes(Routes::$match_types); } $router->addRoutes(Routes::$routes); } $match = $router->match(); if ($match) { require_once BASE_PATH . '/core/Support/InitRouter.php'; $app_init = new InitRouter($match); } else { header('HTTP/1.0 404 Not Found'); echo 'Page Not Found <b>"404 Error"</b>'; }
<?php // loader.php require 'loader.php'; $router = new AltoRouter(); // configure router $router->setBasePath('/words/'); // routes // ->map(Method, Route, Target, Name[Unique]) $router->map('GET', '', 'home', 'indexName'); $match = $router->match(); $name = $match['name']; $target = $match['target']; $params = $match['params']; if ($match) { $wordsApp = new WordsApp(); $wordsApp->{$target}(); } else { header("HTTP/1.0 404 Not Found"); }
<?php /** * write by vyouzhi */ include_once 'bootstrap.php'; $router = new AltoRouter(); $router->setBasePath(ROOT); foreach ($routeMap as $value) { $router->map($value['method'], $value['uri'], $value['params'], $value['module']); } $router->AutoLoad(); $match = $router->match(); $router->httpCode301(); //$router->httpCode404($match); routing($match['action']); if (class_exists($match['action'])) { $show = new $match['action'](); $show->Show(); } else { require_once Lib . '/error/e404.php'; $show = new e404(); $show->Show(); //如果没有就直接 404 //$router->httpCode404(false); } ?>
<?php require 'bakery_tasks.php'; require 'AltoRouter.php'; $router = new AltoRouter(); $router->setBasePath('/assets/web'); $router->map('GET', '/ajax/orders', function () { getOrders(); }); $router->map('PUT', '/ajax/orders/edit/[i:id]', function () { $request_body = file_get_contents('php://input'); $data = json_decode($request_body, true); editOrders($data); }); $router->map('POST', '/ajax/orders/create', function () { $request_body = file_get_contents('php://input'); $data = json_decode($request_body, true); createOrder($data); }); $match = $router->match(); if ($match && is_callable($match['target'])) { call_user_func_array($match['target'], $match['params']); } else { echo 'hi'; }
<?php header('Content-type: application/json'); include_once '../bootstrap.php'; $apiRouter = new AltoRouter(); $apiRouter->setBasePath(substr(Config::get('basedir') . 'api/', 0, -1)); // ROUTER MAPPING // AUTH TOKEN $apiRouter->map('POST', '/app/create', array('c' => 'App', 'a' => 'create', 'authtoken' => false, 'usertoken' => false, 'official' => false)); $apiRouter->map('POST', '/authtoken/create', array('c' => 'AuthToken', 'a' => 'create', 'authtoken' => false, 'usertoken' => false, 'official' => false)); $apiRouter->map('POST', '/usertoken/create', array('c' => 'UserToken', 'a' => 'create', 'authtoken' => true, 'usertoken' => false, 'official' => true)); // USER $apiRouter->map('POST|GET', '/user/hastrained', array('c' => 'User', 'a' => 'hasTrained', 'authtoken' => true, 'usertoken' => true, 'official' => true)); $apiRouter->map('POST|GET', '/user/train', array('c' => 'User', 'a' => 'train', 'authtoken' => true, 'usertoken' => true, 'official' => true)); $apiRouter->map('POST', '/user/create', array('c' => 'User', 'a' => 'create', 'authtoken' => true, 'usertoken' => false, 'official' => true)); $apiRouter->map('GET', '/user/get', array('c' => 'User', 'a' => 'get', 'authtoken' => true, 'usertoken' => true, 'official' => false)); // JOB $apiRouter->map('POST|GET', '/job/get', array('c' => 'Job', 'a' => 'get', 'authtoken' => true, 'usertoken' => true, 'official' => false)); $apiRouter->map('POST|GET', '/job/work', array('c' => 'Job', 'a' => 'work', 'authtoken' => true, 'usertoken' => true, 'official' => true)); // MARKET $apiRouter->map('POST', '/market/job/apply', array('c' => 'JobMarket', 'a' => 'apply', 'authtoken' => true, 'usertoken' => true, 'official' => false)); $apiRouter->map('POST', '/market/job/create', array('c' => 'JobMarket', 'a' => 'create', 'authtoken' => true, 'usertoken' => true, 'official' => true)); $apiRouter->map('POST', '/market/job/offers', array('c' => 'JobMarket', 'a' => 'offers')); // COMPANY $apiRouter->map('POST', '/company/get', array('c' => 'Company', 'a' => 'get', 'authtoken' => true, 'usertoken' => true)); $apiRouter->map('POST', '/company/create', array('c' => 'Company', 'a' => 'create', 'authtoken' => true, 'usertoken' => true, 'official' => true)); $apiRouter->map('POST|GET', '/company/list', array('c' => 'Company', 'a' => 'getList', 'authtoken' => true, 'usertoken' => true)); // RESOURCE $apiRouter->map('GET', '/resource/get', array('c' => 'Resource', 'a' => 'get')); $apiRouter->map('GET', '/resource/list', array('c' => 'Resource', 'a' => 'getList')); $apiRouter->map('POST', '/resource/create', array('c' => 'Resource', 'a' => 'create'));
<?php require 'vendor/autoload.php'; // Import the necessary classes use Illuminate\Database\Capsule\Manager as Capsule; // Include the composer autoload file // Setup a new Eloquent Capsule instance $capsule = new Capsule(); $capsule->addConnection(['driver' => 'mysql', 'host' => '127.0.0.1', 'database' => 'cs', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci']); $capsule->bootEloquent(); $router = new AltoRouter(); $router->setBasePath('/cs'); $router->map('GET|POST', '/', 'home#index', 'home'); $router->map('GET', '/users/', array('c' => 'UserController', 'a' => 'ListAction')); $router->map('GET', '/api/course/all/', 'Api#allCourses'); $router->map('GET', '/api/course/[i:id]/', 'Api#getCourse'); $router->map('GET', '/api/user/all/', 'Api#allUsers'); $router->map('POST', '/api/user/new/', 'Api#newUser'); $router->map('GET', '/api/user/[*:id]/', 'Api#getUser'); $router->map('GET', '/api/cron/', 'Api#cron'); // match current request $match = $router->match(); if ($match) { $path = explode('#', $match['target']); $controller = $path[0]; $method = $path[1]; $params = $match['params']; $object = new $controller(); $object->{$method}($params); } else { (new Controller())->index();
<?php error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('display_errors', 'On'); define("ROOT", dirname(__DIR__)); define("API_VERSION", "apiv2.1"); require ROOT . '/inc/AltoRouter.php'; require ROOT . '/' . API_VERSION . '/MysqliDB.php'; require ROOT . '/' . API_VERSION . '/User.php'; require ROOT . '/' . API_VERSION . '/GlobalFunction.php'; $db = new MysqliDb('localhost', 'kit', 'kit1234', 'fyp'); $router = new AltoRouter(); $router->setBasePath("/apiv2.1"); $router->map('POST', '/login/', 'User::login'); $router->map('POST|GET', '/logout/', 'User::logout'); $router->map('POST|GET', '/compileAndRun/[i:assignment_id]/[:inputs]/', 'Java::compileAndRun'); $router->map('POST', '/testcase/[i:assignment_id]/[save|delete:action]/[i:testcase_id]?/', 'Testcase::manage'); $router->map('GET', '/testcase/[i:assignment_id]/', 'Testcase::get'); $router->map("POST", '/assignment/', 'Assignment::create'); $router->map("GET", '/assignment/[i:assignment_id]?/', 'Assignment::get'); $router->map("PUT", '/assignment/[i:assignment_id]/', 'Assignment::update'); $router->map("DELETE", '/assignment/[i:assignment_id]/', 'Assignment::remove'); $router->map("GET", '/school/[i:school_id]?/', 'School::get'); $router->map("DELETE", '/editor/[i:editor_id]/', 'Editor::remove'); $router->map("GET", '/editor/[i:editor_id]/history/[i:history_id]?/', 'Editor::getHistory'); $router->map("POST", '/samplecode/[i:assignment_id]/', 'SampleCode::create'); $match = $router->match(); //var_dump($match); if ($match) { list($class_name, $method) = explode('::', $match['target']); require_once ROOT . '/' . API_VERSION . '/' . $class_name . ".php";
public function init() { $this->load->helper('url'); if (!file_exists(APPPATH . '/config/database.php')) { redirect('install'); exit; } session_start(); //set the session userdata if non-existant if (!isset($_SESSION['userdata'])) { $_SESSION['userdata'] = []; } //set newFlashdata if non-existent if (!isset($_SESSION['newFlashdata'])) { $_SESSION['newFlashdata'] = []; } //empty out the "oldFlashdata" field $_SESSION['oldFlashdata'] = []; //shift newFlashdata over to oldFlashdata $_SESSION['oldFlashdata'] = $_SESSION['newFlashdata']; $_SESSION['newFlashdata'] = []; //module list $GLOBALS['modules'] = []; if (!file_exists(APPPATH . 'config/manifest.php')) { $this->load->helper('file'); $manifest = "<?php defined('BASEPATH') OR exit('No direct script access allowed');\n//DO NOT EDIT THIS FILE\n\n"; $this->classMap = []; $paths = [FCPATH . 'addons', APPPATH . 'modules', APPPATH . 'libraries', APPPATH . 'core']; $paymentModules = []; $shippingModules = []; $themeShortcodes = []; $routes = []; $modules = []; //just modules $moduleDirectories = [APPPATH . 'modules', FCPATH . 'addons']; foreach ($moduleDirectories as $moduleDirectory) { foreach (array_diff(scandir($moduleDirectory), ['..', '.']) as $availableModule) { if (is_dir($moduleDirectory . '/' . $availableModule)) { //create a codeigniter package path to the module. //$this->load->add_package_path($moduleDirectory.'/'.$availableModule); $modules[] = $moduleDirectory . '/' . $availableModule; } } } foreach ($paths as $path) { $dir_iterator = new RecursiveDirectoryIterator($path); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file) { if (!is_dir($file)) { $ext = pathinfo($file, PATHINFO_EXTENSION); $filename = pathinfo($file, PATHINFO_FILENAME); if ($ext == 'php') { if ($filename == 'manifest') { include $file; } $this->getPhpClasses((string) $file); } } } } $manifest .= '//ClassMap for autoloader' . "\n" . '$classes = ' . var_export($this->classMap, true) . ';'; $manifest .= "\n\n" . '//Available Payment Modules' . "\n" . '$GLOBALS[\'paymentModules\'] =' . var_export($paymentModules, true) . ';'; $manifest .= "\n\n" . '//Available Shipping Modules' . "\n" . '$GLOBALS[\'shippingModules\'] = ' . var_export($shippingModules, true) . ';'; $manifest .= "\n\n" . '//Theme Shortcodes' . "\n" . '$GLOBALS[\'themeShortcodes\'] = ' . var_export($themeShortcodes, true) . ';'; $manifest .= "\n\n" . '//Complete Module List' . "\n" . '$GLOBALS[\'modules\'] = ' . var_export($modules, true) . ';'; $manifest .= "\n\n" . '//Defined Routes' . "\n" . '$routes = ' . var_export($routes, true) . ';'; //generate the autoload file write_file(APPPATH . 'config/manifest.php', $manifest); } require APPPATH . 'config/manifest.php'; //load in the database. $this->load->database(); //set up routing... $router = new \AltoRouter(); $base = trim($_SERVER['BASE'], '/'); if ($base != '') { $router->setBasePath('/' . $base); } //set the homepage route $router->map('GET|POST', '/', 'GoCart\\Controller\\Page#homepage'); //map the routes from the manifest. foreach ($routes as $route) { $router->map($route[0], $route[1], $route[2]); } foreach ($GLOBALS['modules'] as $module) { $this->load->add_package_path($module); } //autoloader for Modules spl_autoload_register(function ($class) use($classes) { if (isset($classes[$class])) { include $classes[$class]; } }); //autoload some libraries here. $this->load->model('Settings'); $this->load->library(['session', 'auth', 'form_validation']); $this->load->helper(['file', 'string', 'html', 'language', 'form', 'formatting']); //get settings from the DB $settings = $this->Settings->get_settings('gocart'); //loop through the settings and set them in the config library foreach ($settings as $key => $setting) { //special for the order status settings if ($key == 'order_statuses') { $setting = json_decode($setting, true); } //other config items get set directly to the config class $this->config->set_item($key, $setting); } date_default_timezone_set(config_item('timezone')); //if SSL is enabled in config force it here. if (config_item('ssl_support') && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')) { $this->config->set_item('base_url', str_replace('http://', 'https://', config_item('base_url'))); redirect(\CI::uri()->uri_string()); } //do we have a dev username & password in place? //if there is a username and password for dev, require them if (config_item('stage_username') != '' && config_item('stage_password') != '') { if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="Login to restricted area"'); header('HTTP/1.0 401 Unauthorized'); echo config_item('company_name') . ' Restricted Location'; exit; } else { if (config_item('stage_username') != $_SERVER['PHP_AUTH_USER'] || config_item('stage_password') != $_SERVER['PHP_AUTH_PW']) { header('WWW-Authenticate: Basic realm="Login to restricted area"'); header('HTTP/1.0 401 Unauthorized'); echo 'Restricted Location'; exit; } } } // lets run the routes $match = $router->match(); // call a closure if ($match && is_callable($match['target'])) { call_user_func_array($match['target'], $match['params']); } elseif ($match && is_string($match['target'])) { $target = explode('#', $match['target']); try { $class = new $target[0](); call_user_func_array([$class, $target[1]], $match['params']); } catch (Exception $e) { var_dump($e); throw_404(); } } else { throw_404(); } }