/**
  * Add all the routes in the router in parameter
  * @param $router Router
  */
 public function generateRoute(Router $router)
 {
     foreach ($this->classes as $class) {
         $classMethods = get_class_methods($this->namespace . $class . 'Controller');
         $rc = new \ReflectionClass($this->namespace . $class . 'Controller');
         $parent = $rc->getParentClass();
         $parent = get_class_methods($parent->name);
         $className = $this->namespace . $class . 'Controller';
         foreach ($classMethods as $methodName) {
             if (in_array($methodName, $parent) || $methodName == 'index') {
                 continue;
             } else {
                 foreach (Router::getSupportedHttpMethods() as $httpMethod) {
                     if (strstr($methodName, $httpMethod)) {
                         continue 2;
                     }
                     if (in_array($methodName . $httpMethod, $classMethods)) {
                         $router->add('/' . strtolower($class) . '/' . $methodName, new $className(), $methodName . $httpMethod, $httpMethod);
                         unset($classMethods[$methodName . $httpMethod]);
                     }
                 }
                 $router->add('/' . strtolower($class) . '/' . $methodName, new $className(), $methodName);
             }
         }
         $router->add('/' . strtolower($class), new $className(), 'index');
     }
 }
 public function registerProviders($providers)
 {
     foreach ($providers as $provider) {
         $collection = $provider->connect($this);
         /** @var ControllerCollection $collection */
         foreach ($collection->getRoutes() as $route) {
             $this->router->add($route);
         }
         unset($collection);
     }
 }
Exemple #3
0
 public function getRouter()
 {
     $router = new Router();
     foreach ($this->getActionRoutes() as $methodRoute) {
         list($route, $methodName) = $methodRoute;
         $method = new \ReflectionMethod($this, $methodName);
         $httpMethod = 'GET';
         $hasRoute = false;
         if ($comment = $method->getDocComment()) {
             if (preg_match('~^[\\s*]*\\@method\\s([^\\s]+)~im', $comment, $match)) {
                 $httpMethod = trim(strtoupper(array_pop($match)));
             }
             if (preg_match('~^[\\s*]*\\@route\\s([^\\s]+)~im', $comment, $match)) {
                 $route = trim(array_pop($match));
                 $hasRoute = true;
             }
         }
         if (!$hasRoute) {
             foreach ($method->getParameters() as $parameter) {
                 $route .= '/{' . ($parameter->isOptional() ? '?' : '') . $parameter->getName() . '}';
             }
         }
         $router->add($httpMethod, $route, [get_class($this), $methodName]);
     }
     return $router;
 }
 public function testMatchMethod()
 {
     $this->object->add(new \PHPixie\Route('get', '/url', array('controller' => 'home', 'action' => 'get'), 'GeT'));
     $this->object->add(new \PHPixie\Route('post', '/url', array('controller' => 'home', 'action' => 'get'), array('PosT')));
     $route = $this->object->match('/url', 'GEt');
     $this->assertEquals('get', $route['route']->name);
     $route = $this->object->match('/url', 'POST');
     $this->assertEquals('post', $route['route']->name);
 }
 /**
  * initialize boot function
  */
 static function boot()
 {
     // load config
     \Config::load('extdirect', true);
     // get route
     $route = \Config::get('extdirect.route', 'direct');
     // add routes
     \Router::add($route . '/(:any)', 'extdirect/$1');
     \Router::add($route, 'extdirect/index');
 }
Exemple #6
0
 public function testBuild()
 {
     $router = new Router();
     $router->add("home", new Route("/"));
     $router->add("article", new Route("/show/{title}"));
     $router->add("mvc", new Route("/{controller}/{action}/{param}", array("controller" => "home", "action" => "index", "param" => "")));
     $this->assertSame("/", $router->build("home", array()));
     $this->assertSame("/", $router->build("home", array("something" => "else")));
     $this->assertFalse($router->build("article", array()));
     $this->assertFalse($router->build("article", array("something" => "else")));
     $this->assertFalse($router->build("article", array("title" => "")));
     $this->assertFalse($router->build("article", array("title" => false)));
     $this->assertSame("/show/1", $router->build("article", array("title" => "1")));
     $this->assertSame("/show/thisisatitle", $router->build("article", array("title" => "thisisatitle")));
     $this->assertSame("/", $router->build("mvc", array()));
     $this->assertSame("/", $router->build("mvc", array("foo" => "bar")));
     $this->assertSame("/", $router->build("mvc", array("controller" => "")));
     $this->assertSame("/", $router->build("mvc", array("controller" => false)));
     $this->assertSame("/", $router->build("mvc", array("controller" => "home")));
 }
Exemple #7
0
 public function testAddVariableWithRegexRoute()
 {
     $patternBuilder = \Mockery::mock('Rootr\\PatternBuilder');
     $patternBuilder->shouldReceive('build')->andReturn(['/products/(\\d+)', ['id']]);
     $router = new Router($patternBuilder);
     $router->add('GET', '/products/{id}', function ($id) {
         return "/products/{$id}";
     });
     assertThat($router->getStaticRoutes(), emptyArray());
     assertThat($router->getVariableRoutes(), arrayWithSize(1));
     assertThat($router->getVariableRoutes(), hasKeyInArray('/products/(\\d+)'));
 }
Exemple #8
0
 /**
  * Constructor of Sask, initialization of the database class.
  *
  * @param string $baseDir The base directory of the application
  */
 public function __construct($baseDir = __DIR__)
 {
     self::$basedir = $baseDir;
     self::$router = new Router();
     /*
      * 	Connect to the database
      * 	==================
      * 	Set your database access details here.
      */
     if (Configuration::$dbConnection['UseDatabase']) {
         switch (Configuration::$dbConnection['Type']) {
             case 'MySQL':
                 self::$database = new Database(Configuration::$dbConnection['Host'], Configuration::$dbConnection['User'], Configuration::$dbConnection['Password'], Configuration::$dbConnection['DatabaseName'], Configuration::$dbConnection['Port']);
                 break;
             default:
                 break;
         }
     }
     foreach (Configuration::$routes as $key => $value) {
         self::$router->add($key, $value);
     }
 }
Exemple #9
0
 public function testNamedParams()
 {
     $id = null;
     $name = null;
     Router::add('|^api/\\w+/(?<name>\\w+)/(?<id>\\d+)$|', function ($r) use(&$id, &$name) {
         $id = (int) $r->param('id');
         $name = $r->param('name');
         return new Result(['id' => $id]);
     });
     $reflection = new \ReflectionMethod('alkemann\\h2l\\Router', 'matchDynamicRoute');
     $reflection->setAccessible(true);
     $route = $reflection->invoke(null, 'api/doesntmatter/tasks/12');
     $this->assertTrue($route instanceof Route);
     $this->assertEquals(['id' => '12', 'name' => 'tasks'], $route->parameters);
 }
 public function testBuildWithPathType()
 {
     $router = new Router();
     $router->add("test", new Host("/", array()));
     $this->assertSame("/", $router->build("test", array(), Host::PATH_ONLY));
     $this->assertSame("/", $router->build("test", array(), Host::PATH_NETWORK));
     $this->assertSame("/", $router->build("test", array(), Host::PATH_FULL));
     // with _host
     $this->assertSame("/", $router->build("test", array("_host" => "example.com"), Host::PATH_ONLY));
     $this->assertSame("//example.com/", $router->build("test", array("_host" => "example.com"), Host::PATH_NETWORK));
     $this->assertSame("//example.com/", $router->build("test", array("_host" => "example.com"), Host::PATH_FULL));
     // with _scheme, no _host
     $this->assertSame("/", $router->build("test", array("_scheme" => "https"), Host::PATH_ONLY));
     $this->assertSame("/", $router->build("test", array("_scheme" => "https"), Host::PATH_NETWORK));
     $this->assertSame("/", $router->build("test", array("_scheme" => "https"), Host::PATH_FULL));
     // with _scheme and _host
     $this->assertSame("/", $router->build("test", array("_host" => "example.com", "_scheme" => "https"), Host::PATH_ONLY));
     $this->assertSame("//example.com/", $router->build("test", array("_host" => "example.com", "_scheme" => "https"), Host::PATH_NETWORK));
     $this->assertSame("https://example.com/", $router->build("test", array("_host" => "example.com", "_scheme" => "https"), Host::PATH_FULL));
 }
Exemple #11
0
<?php

namespace Epic;

session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
define('SITE_URL', 'http://epic-blog/lesson%2010/src/public/index.php');
require '../vendor/autoload.php';
Lib\connection(['host' => 'localhost', 'dbname' => 'blog', 'user' => 'root', 'password' => 'vagrant', 'encoding' => 'utf8']);
$router = new Router();
$router->add('home', '\\Epic\\Controllers\\Home', ['\\Epic\\Lib\\is_logged']);
$router->add('profile', '\\Epic\\Controllers\\Profile', ['\\Epic\\Lib\\is_logged']);
$router->add('login', '\\Epic\\Controllers\\Login');
$router->handle();
Exemple #12
0
<?php

/**
 * BakedCarrot application initialization file 
 *
 * @package BakedCarrot
 * 
 *
 *
 * 
 */
// turning on error reporting
error_reporting(E_ALL | E_STRICT);
// loading main library file
require SYSPATH . 'App.php';
// init
App::create(array('config' => APPPATH . 'config.php', 'mode' => App::MODE_DEVELOPMENT));
// default route
Router::add('default', '/', array('controller' => 'index'));
// run the application
App::run();
Exemple #13
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'app/helpers.php';
require 'app/core/DB.php';
require 'app/core/Router.php';
require 'app/core/Model.php';
require 'app/core/Controller.php';
require 'app/models/Candidate.php';
require 'app/controllers/CandidatesController.php';
Router::add('GET', 'customers', 'CustomersController');
Router::add('GET', 'companies', 'CompaniesController');
Router::test();
$controllerName = $_GET['controller'] . 'Controller';
$actionName = $_GET['action'];
$controller = new $controllerName();
$controller->{$actionName}();
Exemple #14
0
<?php

Router::add('/', DIR_CTRL . '/index.php');
// Router::add('#^/products(/\d+)?/$#', DIR_CTRL.'/products.php', Router::ROUTE_PCRE);
// Router::add('#^/index.php/products(/\d+)?/$#', DIR_CTRL.'/products.php', Router::ROUTE_PCRE);
Router::add('#^/index.php/products/(name|price|latestprice|addedon|lastupdate)(/\\d+)?/$#', DIR_CTRL . '/products.php', Router::ROUTE_PCRE);
Router::add('#^/index.php/products/$#', DIR_CTRL . '/products.php', Router::ROUTE_PCRE);
Router::add('#^/index.php/prcchanged/#', DIR_CTRL . '/prcchanged.php', Router::ROUTE_PCRE);
Router::add('#^/index.php/product(/\\d+)?/$#', DIR_CTRL . '/product.php', Router::ROUTE_PCRE);
Router::add('#^/index.php/settings/$#', DIR_CTRL . '/settings.php', Router::ROUTE_PCRE);
// Router::add('#^/index.php/ajax/$#', DIR_CTRL.'/ajax.php', Router::ROUTE_PCRE);
// Router::add('#^/regex/(test1|test2|test3)/$#', DIR_CTRL.'/regex.php', Router::ROUTE_PCRE);
/**
 * Routes are added with the static method Router::add($pattern, $replacement)
 * It is processed as preg_replace($pattern, $replace) in the router class, so
 * use any style for $pattern. Though it would be best to use # for pattern 
 * delimiters and ${n} for the replacement string variables. To carry a string
 * from the pattern, just put them in parentheses (). These are run in order,
 * and first one that matches and has a readable controller file is used.
 *
 * PHP's preg_replace: http://php.net/preg_replace/
 *
 * examples:
 *
 * Router::add('#/#', DIR_CTRL.'index.php', Router::ROUTE_PCRE);
 *      sends index page to the index.php contoller
 *
 * Router::add('#/news/(archive|latest)/#', DIR_CTRL.'news.${1}.php', Router::ROUTE_PCRE);
 *      /news/archive/ goes to news.archive.php
 *
 * you can also do this
Exemple #15
0
<?php

$router = new Router();
$router->add('/', 'i want to see the dashboard');
$router->get('/');
Exemple #16
0
<?php

namespace Epic;

session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
define('SITE_URL', 'http://epic-blog/lesson%2010/src/public/index.php');
require '../vendor/autoload.php';
$app = new \Application();
$app->register('template', Template::service());
Lib\connection(['host' => 'localhost', 'dbname' => 'blog', 'user' => 'root', 'password' => 'vagrant', 'encoding' => 'utf8']);
$router = new Router();
$router->add('home', '\\Epic\\Controllers\\Home', [function () {
    !empty(Lib\user()) ?: Lib\redirect(SITE_URL . '?action=login');
}]);
$router->add('profile', '\\Epic\\Controllers\\Profile', [function () {
    !empty(Lib\user()) ?: Lib\redirect(SITE_URL . '?action=login');
}]);
$router->add('login', '\\Epic\\Controllers\\Login');
$router->handle();
<?php

// Home Page Routes
Router::add('/', DIR_CTRL . '/index.php');
Router::add('#^/index(|.htm|.html|.php)$#', DIR_CTRL . '/index.php', Router::ROUTE_PCRE);
// Registration Routes
Router::add('/register', DIR_CTRL . '/register.php');
Router::add('/login', DIR_CTRL . '/login.php');
Router::add('/logout', DIR_FUNC . '/logout.php');
Router::add('/dashboard', DIR_CTRL . '/dashboard.php');
Router::add('#^/story/([a-zA-Z\\d])+/$#', DIR_CTRL . '/storyEdit.php', Router::ROUTE_PCRE);
Router::add('/create', DIR_CTRL . '/storyCreate.php');
Router::add('/stories', DIR_CTRL . '/stories.php');
//Router::add('#^/regex/(test1|test2|test3)/$#', DIR_CTRL.'/regex.php', Router::ROUTE_PCRE);
//Router::add('#^/regex/[^/]+/$#', DIR_CTRL.'/regex.php', Router::ROUTE_PCRE);
/**
 * Routes are added with the static method Router::add($pattern, $replacement)
 * It is processed as preg_replace($pattern, $replace) in the router class, so
 * use any style for $pattern. Though it would be best to use # for pattern
 * delimiters and ${n} for the replacement string variables. To carry a string
 * from the pattern, just put them in parentheses (). These are run in order,
 * and first one that matches and has a readable controller file is used.
 *
 * PHP's preg_replace: http://php.net/preg_replace/
 *
 * examples:
 *
 * Router::add('#/#', DIR_CTRL.'index.php', Router::ROUTE_PCRE);
 *      sends index page to the index.php contoller
 *
 * Router::add('#/news/(archive|latest)/#', DIR_CTRL.'news.${1}.php', Router::ROUTE_PCRE);
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \FuelException("You can't initialize Fuel more than once.");
     }
     static::$_paths = array(APPPATH, COREPATH);
     // Is Fuel running on the command line?
     static::$is_cli = (bool) defined('STDIN');
     \Config::load($config);
     // Start up output buffering
     ob_start(\Config::get('ob_callback', null));
     static::$profiling = \Config::get('profiling', false);
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/');
     static::$caching = \Config::get('caching', false);
     static::$cache_lifetime = \Config::get('cache_lifetime', 3600);
     if (static::$caching) {
         \Finder::instance()->read_cache('Fuel::paths');
     }
     // set a default timezone if one is defined
     static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
     date_default_timezone_set(static::$timezone);
     static::$encoding = \Config::get('encoding', static::$encoding);
     MBSTRING and mb_internal_encoding(static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
     }
     // Run Input Filtering
     \Security::clean_input();
     \Event::register('shutdown', 'Fuel::finish');
     //Load in the packages
     foreach (\Config::get('always_load.packages', array()) as $package => $path) {
         is_string($package) and $path = array($package => $path);
         \Package::load($path);
     }
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set  locale
     static::$locale and setlocale(LC_ALL, static::$locale);
     static::$initialized = true;
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
 /**
  * @param string   $name
  * @param string   $pattern
  * @param callable $action
  *
  * @return $this
  */
 public function addAction($name, $pattern, $action)
 {
     $this->router->add($name, $pattern);
     $this->actions->set($name, $action);
     return $this;
 }
Exemple #20
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     \Config::load($config);
     if (static::$initialized) {
         throw new \Fuel_Exception("You can't initialize Fuel more than once.");
     }
     register_shutdown_function('fuel_shutdown_handler');
     set_exception_handler('fuel_exception_handler');
     set_error_handler('fuel_error_handler');
     // Start up output buffering
     ob_start(\Config::get('ob_callback', null));
     static::$profiling = \Config::get('profiling', false);
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/');
     static::$caching = \Config::get('caching', false);
     static::$cache_lifetime = \Config::get('cache_lifetime', 3600);
     if (static::$caching) {
         static::$path_cache = static::cache('Fuel::path_cache');
     }
     // set a default timezone if one is defined
     static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
     date_default_timezone_set(static::$timezone);
     // set the encoding and locale to use
     static::$encoding = \Config::get('encoding', static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     static::$_paths = array(APPPATH, COREPATH);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
         \Uri::detect();
     }
     // Run Input Filtering
     \Security::clean_input();
     static::$env = \Config::get('environment');
     \Event::register('shutdown', 'Fuel::finish');
     //Load in the packages
     foreach (\Config::get('always_load.packages', array()) as $package => $path) {
         is_string($package) and $path = array($package => $path);
         static::add_package($path);
     }
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set  locale
     static::$locale and setlocale(LC_ALL, static::$locale);
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     static::$initialized = true;
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Exemple #21
0
 /**
  * Creates the new Request object by getting a new URI object, then parsing
  * the uri with the Route class.
  *
  * Usage:
  *
  *     $request = new Request('foo/bar');
  *
  * @param   string  the uri string
  * @param   bool    whether or not to route the URI
  * @return  void
  */
 public function __construct($uri, $route = true)
 {
     $this->uri = new \Uri($uri);
     // check if a module was requested
     if (count($this->uri->segments) and $modpath = \Fuel::module_exists($this->uri->segments[0])) {
         // check if the module has routes
         if (file_exists($modpath .= 'config/routes.php')) {
             // load and add the module routes
             $modroutes = \Config::load(\Fuel::load($modpath), $this->uri->segments[0] . '_routes');
             foreach ($modroutes as $name => $modroute) {
                 switch ($name) {
                     case '_root_':
                         // map the root to the module default controller/method
                         $name = $this->uri->segments[0];
                         break;
                     case '_404_':
                         // do not touch the 404 route
                         break;
                     default:
                         // prefix the route with the module name if it isn't done yet
                         if (strpos($name, $this->uri->segments[0] . '/') !== 0 and $name != $this->uri->segments[0]) {
                             $name = $this->uri->segments[0] . '/' . $name;
                         }
                         break;
                 }
                 \Config::set('routes.' . $name, $modroute);
             }
             // update the loaded list of routes
             \Router::add(\Config::get('routes'));
         }
     }
     $this->route = \Router::process($this, $route);
     if (!$this->route) {
         return;
     }
     if ($this->route->module !== null) {
         $this->module = $this->route->module;
         \Fuel::add_module($this->module);
         $this->add_path(\Fuel::module_exists($this->module));
     }
     $this->directory = $this->route->directory;
     $this->controller = $this->route->controller;
     $this->action = $this->route->action;
     $this->method_params = $this->route->method_params;
     $this->named_params = $this->route->named_params;
 }
Exemple #22
0
<?php

define('PROJECTROOT', realpath(APPPATH . '../../') . '/');
define('CMFPATH', PKGPATH . 'cmf/');
// Alias some of the cmf classes to root namespace
Autoloader::alias_to_namespace('CMF\\CMF');
Autoloader::alias_to_namespace('CMF\\Admin');
// Add in the 404 route which routes through the CMF
\Router::add(array('_404_' => 'base/catchall'));
// Load cmf config
\Config::load('cmf', true);
if (\Config::get('cmf.languages.enabled')) {
    \Config::load('db', true);
    $extensions = \Config::get('db.doctrine2.extensions');
    if (!is_array($extensions)) {
        $extensions = array();
    }
    if (!in_array('CMF\\Doctrine\\Extensions\\Translatable', $extensions)) {
        $extensions[] = 'CMF\\Doctrine\\Extensions\\Translatable';
    }
    \Config::set('db.doctrine2.extensions', $extensions);
}
// Check if custom module urls have been set
$isAdmin = !\Fuel::$is_cli && strpos(ltrim($_SERVER['REQUEST_URI'], '/'), trim(\Uri::create('admin'), '/')) === 0;
if ($isAdmin) {
    \Config::set('security.uri_filter', array_merge(array('\\Admin::module_url_filter'), \Config::get('security.uri_filter')));
} else {
    if (\Config::get('cmf.module_urls', false) !== false) {
        \Config::set('security.uri_filter', array_merge(array('\\CMF::module_url_filter'), \Config::get('security.uri_filter')));
    }
}
Exemple #23
0
<?php

//spl_autoload_register();
require '../Core/Router.php';
$router = new Router();
$router->add('', ['controller' => 'Home', 'action' => 'index']);
$router->add('posts', ['controller' => 'Posts', 'action' => 'index']);
//$router->add('posts/new', ['controller' => 'Posts', 'action' => 'new']);
$router->add('{controller}/{action}');
$router->add('admin/{controller}/{action}');
$url = $_SERVER['QUERY_STRING'];
if ($router->match($url)) {
    echo '<pre>';
    var_dump($router->getRoutes());
    var_dump($router->getParams());
    echo '</pre>';
} else {
    echo 'no routes found for URL ' . $url;
}
Exemple #24
0
<?php

namespace Router;

require_once 'vendor/autoload.php';
$router = new Router();
$router->setDefaultModule('index');
$router->setDefaultController('index');
$router->setDefaultAction('index');
$router->add('/admin/controllers/user/show/:param', ['module' => 'Lib\\Controllers', 'controller' => 'user', 'action' => 'show', 'param1' => 1], ['method' => 'get']);
$router->add('/', ['controller' => 'index', 'action' => 'index'], ['method' => 'get | post']);
$router->add('/admin/:controller/:action', ['controller' => 1, 'action' => 2], ['method' => 'post']);
$router->add('/admin/controllers/user/show/:param/:param', ['module' => 'Controllers', 'controller' => 'user', 'action' => 'show', 'param1' => 1, 'param2' => 2], ['method' => 'get']);
$router->add('/admin/:module/users/show/:param', ['module' => 1, 'controller' => 'users', 'action' => 'show', 'param1' => 1], ['method' => 'get']);
$router->add('/admin/users/show/:name', ['controller' => 'users', 'action' => 'show', 'name1' => 1], ['method' => 'get']);
$router->add('/admin/cont/:action/:param/:param', ['controller' => 'cont', 'action' => 1, 'param1' => 2, 'param2' => 3], ['method' => "get | post"]);
$route = $router->resolve();
foreach ($route as $key => $value) {
    echo $key . ': ';
    if (is_string($value)) {
        echo $value;
    } elseif (is_array($value)) {
        foreach ($value as $key2 => $value2) {
            echo '<br><span style="margin-left: 50px"><b>' . $key2 . ': ' . $value2 . '</b></span><br>';
        }
    }
    echo '<br>';
}
Exemple #25
0
 /**
  * Creates the new Request object by getting a new URI object, then parsing
  * the uri with the Route class.
  *
  * Usage:
  *
  *     $request = new Request('foo/bar');
  *
  * @param   string  the uri string
  * @param   bool    whether or not to route the URI
  * @param   string  request method
  * @return  void
  */
 public function __construct($uri, $route = true, $method = null)
 {
     $this->uri = new \Uri($uri);
     $this->method = $method;
     logger(\Fuel::L_INFO, 'Creating a new Request with URI = "' . $uri . '"', __METHOD__);
     // check if a module was requested
     if (count($this->uri->segments()) and $module_path = \Module::exists($this->uri->get_segment(0))) {
         // check if the module has routes
         if (is_file($module_path .= 'config/routes.php')) {
             $module = $this->uri->segments[0];
             // load and add the module routes
             $module_routes = \Fuel::load($module_path);
             $prepped_routes = array();
             foreach ($module_routes as $name => $_route) {
                 if ($name === '_root_') {
                     $name = $module;
                 } elseif (strpos($name, $module . '/') !== 0 and $name != $module and $name !== '_404_') {
                     $name = $module . '/' . $name;
                 }
                 $prepped_routes[$name] = $_route;
             }
             // update the loaded list of routes
             \Router::add($prepped_routes, null, true);
         }
     }
     $this->route = \Router::process($this, $route);
     if (!$this->route) {
         return;
     }
     $this->module = $this->route->module;
     $this->controller = $this->route->controller;
     $this->action = $this->route->action;
     $this->method_params = $this->route->method_params;
     $this->named_params = $this->route->named_params;
     if ($this->route->module !== null) {
         $this->add_path(\Module::exists($this->module));
     }
 }
Exemple #26
0
 public function test_add_route_and_router_option_name()
 {
     $path = 'testing/route';
     $name = 'option_name';
     $options = array('name' => $name);
     $prepend = false;
     $case_sensitive = null;
     Router::add($path, $options, $prepend, $case_sensitive);
     $this->assertEquals($path, Router::$routes[$name]->path);
     $this->assertEquals($name, Router::$routes[$name]->name);
     Router::delete($name);
 }
Exemple #27
0
 /**
  * Initializes the framework.
  * This can only be called once.
  *
  * @access public
  * @return void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \FuelException("You can't initialize Fuel more than once.");
     }
     // BC FIX FOR APPLICATIONS <= 1.6.1, makes Redis_Db available as Redis,
     // like it was in versions before 1.7
     class_exists('Redis', false) or class_alias('Redis_Db', 'Redis');
     static::$_paths = array(APPPATH, COREPATH);
     // Is Fuel running on the command line?
     static::$is_cli = (bool) defined('STDIN');
     \Config::load($config);
     // Start up output buffering
     static::$is_cli or ob_start(\Config::get('ob_callback', null));
     if (\Config::get('caching', false)) {
         \Finder::instance()->read_cache('FuelFileFinder');
     }
     static::$profiling = \Config::get('profiling', false);
     static::$profiling and \Profiler::init();
     // set a default timezone if one is defined
     try {
         static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
         date_default_timezone_set(static::$timezone);
     } catch (\Exception $e) {
         date_default_timezone_set('UTC');
         throw new \PHPErrorException($e->getMessage());
     }
     static::$encoding = \Config::get('encoding', static::$encoding);
     MBSTRING and mb_internal_encoding(static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
     }
     // Run Input Filtering
     \Security::clean_input();
     \Event::register('fuel-shutdown', 'Fuel::finish');
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set locale, log warning when it fails
     if (static::$locale) {
         setlocale(LC_ALL, static::$locale) or logger(\Fuel::L_WARNING, 'The configured locale ' . static::$locale . ' is not installed on your system.', __METHOD__);
     }
     static::$initialized = true;
     // fire any app created events
     \Event::instance()->has_events('app_created') and \Event::instance()->trigger('app_created', '', 'none');
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Exemple #28
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \FuelException("You can't initialize Fuel more than once.");
     }
     static::$_paths = array(APPPATH, COREPATH);
     // Is Fuel running on the command line?
     static::$is_cli = (bool) defined('STDIN');
     \Config::load($config);
     // Start up output buffering
     ob_start(\Config::get('ob_callback', null));
     static::$profiling = \Config::get('profiling', false);
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/');
     static::$caching = \Config::get('caching', false);
     static::$cache_lifetime = \Config::get('cache_lifetime', 3600);
     if (static::$caching) {
         \Finder::instance()->read_cache('Fuel::paths');
     }
     // set a default timezone if one is defined
     static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
     date_default_timezone_set(static::$timezone);
     static::$encoding = \Config::get('encoding', static::$encoding);
     MBSTRING and mb_internal_encoding(static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
     }
     // Run Input Filtering
     \Security::clean_input();
     \Event::register('shutdown', 'Fuel::finish');
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set locale, log warning when it fails
     if (static::$locale) {
         setlocale(LC_ALL, static::$locale) or logger(\Fuel::L_WARNING, 'The configured locale ' . static::$locale . ' is not installed on your system.', __METHOD__);
     }
     static::$initialized = true;
     // fire any app created events
     \Event::instance()->has_events('app_created') and \Event::instance()->trigger('app_created', '', 'none');
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Exemple #29
0
<?php

require_once '../app/config.php';
require_once '../app/database.php';
require_once '../app/router.php';
DB::connect();
Router::add('get', '/', function ($data) {
    include '../view/index.html';
});
Router::add('get', '/note', function ($data) {
    echo DB::find('note', [], $data->page, $data->size)->json;
}, [['page', 1], ['size', 20]], true);
Router::add('post', '/note', function ($data) {
    echo DB::insert('note', ['time' => time(), 'content' => htmlspecialchars($data->content), 'user' => $data->user])->json;
}, ['content', 'user']);
Router::run();
DB::Disconnect();
Exemple #30
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \Fuel_Exception("You can't initialize Fuel more than once.");
     }
     register_shutdown_function('fuel_shutdown_handler');
     set_exception_handler('fuel_exception_handler');
     set_error_handler('fuel_error_handler');
     // Start up output buffering
     ob_start();
     static::$profiling = isset($config['profiling']) ? $config['profiling'] : false;
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = isset($config['cache_dir']) ? $config['cache_dir'] : APPPATH . 'cache/';
     static::$caching = isset($config['caching']) ? $config['caching'] : false;
     static::$cache_lifetime = isset($config['cache_lifetime']) ? $config['cache_lifetime'] : 3600;
     if (static::$caching) {
         static::$path_cache = static::cache('Fuel::path_cache');
     }
     \Config::load($config);
     static::$_paths = array(APPPATH, COREPATH);
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     \View::$auto_encode = \Config::get('security.auto_encode_view_data');
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
         \Uri::detect();
     }
     // Run Input Filtering
     \Security::clean_input();
     static::$env = \Config::get('environment');
     static::$locale = \Config::get('locale');
     //Load in the packages
     foreach (\Config::get('always_load.packages', array()) as $package) {
         static::add_package($package);
     }
     // Set some server options
     setlocale(LC_ALL, static::$locale);
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     static::$initialized = true;
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }