/** * Initialize Application. * * @return void */ protected function init() { parent::init(); $this->router = $this->container->get('Router'); $this->router->addRoutes($this->getConfig('routes')); $session = $this->container->get('Session'); $session->start(); // load providers $this->loadProviders($this->getConfig('http.providers')); // load events $this->loadEvents($this->getConfig('http.events')); }
/** * @covers AltoRouter::addRoutes * @expectedException Exception */ public function testAddRoutesThrowsExceptionOnInvalidArgument() { $this->router->addRoutes(new stdClass()); }
/** * Run this application * * @return mixed */ public function run() { // Collect routes $this->router->addRoutes($this->collectRoutes()); return $this->callController(); }
<?php //-------------------------------------------------------------------------- // Core //-------------------------------------------------------------------------- include '../core/core.php'; include $GLOBALS['core']->getLibrary('AltoRouter'); include $GLOBALS['core']->getLibrary('vendor/autoload'); use Telegram\Bot\Api; $router = new AltoRouter(); $router->addRoutes(array(array('GET', '/telegram/' . $GLOBALS['core']->getTelegram('webhook', 'telegram') . '/', 'webhook'), array('POST', '/telegram/' . $GLOBALS['core']->getTelegram('webhook', 'telegram') . '/', 'telegram'), array('POST', '/telegram/' . $GLOBALS['core']->getTelegram('webhook', 'sendMessage') . '/', 'sendMessage'), array('POST', '/telegram/' . $GLOBALS['core']->getTelegram('webhook', 'github') . '/', 'github'))); $match = $router->match(); $output = array(); if ($match) { // Create the bot $telegram = new Telegram\Bot\Api($GLOBALS['core']->getTelegram('token')); if (file_exists('controllers/' . $match['target'] . '.php')) { include 'controllers/' . $match['target'] . '.php'; } else { $output['status'] = 0; $output['code'] = 'no-controller'; $output['return'] = 'Internal error, unable to find the controller'; } } else { $output['status'] = 0; $output['code'] = 'no-found'; $output['return'] = 'This option cant be found'; } if ($output) { echo json_encode($output); }
<?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>'; }