diff --git a/lib/.pear2registry b/lib/.pear2registry index ad7c1ff64c68787256d4fbfba757837292d2bf75..fae52034d512c482b1b4fa280fb21f50e4afe04a 100644 Binary files a/lib/.pear2registry and b/lib/.pear2registry differ diff --git a/lib/.xmlregistry/packages/pear.unl.edu/RegExpRouter/0.1.0-info.xml b/lib/.xmlregistry/packages/pear.unl.edu/RegExpRouter/0.1.0-info.xml new file mode 100644 index 0000000000000000000000000000000000000000..2c574f721371957528a1afab13082c5547954a53 --- /dev/null +++ b/lib/.xmlregistry/packages/pear.unl.edu/RegExpRouter/0.1.0-info.xml @@ -0,0 +1,114 @@ +<?xml version="1.0" encoding="UTF-8"?> +<package xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd"> + <name>RegExpRouter</name> + <channel>pear.unl.edu</channel> + <summary>h1. RegExpRouter +</summary> + <description> +h2. Introduction + +RegExpRouter is a php router system that routes clean URLs based on regular expressions and support PSR-0 complient projects. + +*Possible Options for a new Router:* +$options = array( +'baseURL'=>'yoururl', //required: the full url: http://www.yoururl.com/ +'srcDir'=>'yourSrcDir' //Only required if you want to scan your models. *Must* be a full system path to your source directory. +); + +h2. Methods of routing: + +1. *Scanning* + +The router will scan though your models and load routes. You will need a file called Routes.php within each of your model's directories (ie: project/exampleModel/Routes.php). This Routes.php file must extend RegExpRouter\RoutesInterface and define all of the routes for that model. + +For each Model that has a route, you will need to place a file named "Routes" within that class, which implements RegExpRouter\RoutesInterface and define the regex routes for the model. + +Routes are defined as an array of routes. And example route would look like this: $routes = array(array('yourRegex' => 'referenceModel'), array('moreRegex' => 'anotherModel')); +The reference model should be the name of a class within the current model *without* it's namespace. The namespace will be added to it automatically. + +*Here is some example code for scanning your models:* + +$options = array('baseURL'=>'yoururl', 'srcDir'=>'yourSrcDir'); +$router = new RegExpRouter\Router($options); +$router->route($_SERVER['REQUEST_URI'], $_GET); + +2. *User Defined Mapping* + +You can compile the array of regex to model mapping yourself and call the RegExpRouter->setRoutes(array) method: + +*Here is some example code for using your own mapping:* + +Routes are the same as the scaning method, except you should *always* define the fulll namesapce to the class within the model that you are referencing. + +$options = array('baseURL'=>'yoururl'); +$router = new RegExpRouter\Router($options); +$router->setRoutes(array('/^home$/i' => 'ExampleProject\ExampleModel\View')); +$router->route($_SERVER['REQUEST_URI'], $_GET); + +h2. Example + +To view the very simple Example application in the Example folder to get a better feel of how it works. + +To set up the example application you will have to do the following: +1) Copy the config.sample.php to a new file called config.inc.php in the same folder. +2) Change the Example\Controller::$url in config.inc.php to a url that works with your setup. +3) Copy the sample.htaccess file to a new file called .htaccess in the same folder. +4) In .htaccess change the RewriteBase path to work with your setup.</description> + <lead> + <name>Brett Bieber</name> + <user>saltybeagle</user> + <email>brett.bieber@gmail.com</email> + <active>yes</active> + </lead> + <lead> + <name>Michael Fairchild</name> + <user>mfairchild365</user> + <email>mfairchild365@gmail.com</email> + <active>yes</active> + </lead> + <date>2013-04-29</date> + <time>14:18:29</time> + <version> + <release>0.1.0</release> + <api>0.1.0</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license> + <notes>First release with basic regular expression route support + + +Initial API +</notes> + <contents> + <dir name="/"> + <file role="test" name="tests/Route/route_setRoutes.phpt" md5sum="9b4c54ada9207e97360bf698e0c382ea"/> + <file role="test" name="tests/Route/route.phpt" md5sum="9a9ba581d9fe855e8309026ee392ed61"/> + <file role="test" name="tests/Route/cacheRoute.phpt" md5sum="54f6ceb663a8f1342d96e8b7974ec460"/> + <file role="php" name="src/RegExpRouter/RoutesInterface.php" md5sum="ad2776c9dea3d8bc6ebefa9119c8cb79"/> + <file role="php" name="src/RegExpRouter/Router.php" md5sum="96038c2abf43c7efe90981879d67b3e6"/> + <file role="doc" name="examples/src/Example/Home/View.php" md5sum="8baf713b1d31ece2b2b1fd21b04de833"/> + <file role="doc" name="examples/src/Example/Home/Routes.php" md5sum="52ae0d52690a0db04b1bcd5c9ffd9da2"/> + <file role="doc" name="examples/src/Example/Home/Edit.php" md5sum="7ac78644f1052f4d68d6acd798c00f4c"/> + <file role="doc" name="examples/src/Example/Controller.php" md5sum="96572cf4a42a697f9a0c0ff361b9c626"/> + <file role="doc" name="examples/src/Example/Account/View.php" md5sum="3e9d4646712398fdf0f2ab48714d169a"/> + <file role="doc" name="examples/src/Example/Account/Routes.php" md5sum="2106acbda79a257df99f70a9507cb64d"/> + <file role="doc" name="examples/sample.htaccess" md5sum="cc0d3150b6ce09cbab8fba7891341645"/> + <file role="doc" name="examples/index.php" md5sum="8c7297dddd30289ff571fbd42ffb5b6a"/> + <file role="doc" name="examples/config.sample.php" md5sum="20edc00ee4b949503bde4fdaab64b0b6"/> + </dir> + </contents> + <dependencies> + <required> + <php> + <min>5.2.0</min> + </php> + <pearinstaller> + <min>2.0.0a1</min> + </pearinstaller> + </required> + </dependencies> + <phprelease/> +</package> diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/config.sample.php b/lib/docs/pear.unl.edu/RegExpRouter/examples/config.sample.php new file mode 100644 index 0000000000000000000000000000000000000000..a7d9bc20ff2d740f490d05bf9d2865e996939b31 --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/config.sample.php @@ -0,0 +1,26 @@ +<?php +function autoload($class) +{ + $file = str_replace(array('_', '\\'), '/', $class).'.php'; + if ($fullpath = stream_resolve_include_path($file)) { + include $fullpath; + return true; + } + return false; +} + +spl_autoload_register("autoload"); + +set_include_path( + implode(PATH_SEPARATOR, array(get_include_path())).PATH_SEPARATOR + . dirname(dirname(__FILE__)) . '/src' . PATH_SEPARATOR + . dirname(__FILE__) . '/src' . PATH_SEPARATOR +); + +ini_set('display_errors', true); + +error_reporting(E_ALL); + +RegExpRouter\Router::$cacheRoutes = false; + +Example\Controller::$url = 'http://localhost/application/vendor/RegExpRouter/examples/'; \ No newline at end of file diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/index.php b/lib/docs/pear.unl.edu/RegExpRouter/examples/index.php new file mode 100644 index 0000000000000000000000000000000000000000..1d74a8b3c028b2c2608d1864d88ef1f905b14968 --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/index.php @@ -0,0 +1,14 @@ +<?php +if (file_exists(dirname(__FILE__) . '/config.inc.php')) { + require_once dirname(__FILE__) . '/config.inc.php'; +} else { + require dirname(__FILE__) . '/config.sample.php'; +} + +if (isset($_GET['model'])) { + unset($_GET['model']); +} + +$router = new RegExpRouter\Router(array('baseURL' => Example\Controller::$url, 'srcDir' => dirname(__FILE__) . "/src/Example/")); + +$example = new Example\Controller($router->route($_SERVER['REQUEST_URI'], $_GET)); \ No newline at end of file diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/sample.htaccess b/lib/docs/pear.unl.edu/RegExpRouter/examples/sample.htaccess new file mode 100644 index 0000000000000000000000000000000000000000..56f972497512ddb268d95bee9cc8c6d6b8218f0b --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/sample.htaccess @@ -0,0 +1,7 @@ +RewriteEngine On +RewriteBase /app/vendor/RegExpRouter/Example + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d + +RewriteRule . index.php [L] \ No newline at end of file diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Account/Routes.php b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Account/Routes.php new file mode 100644 index 0000000000000000000000000000000000000000..2b7684ab2ecccb80b95ba535e1cc805944070e35 --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Account/Routes.php @@ -0,0 +1,25 @@ +<?php +namespace Example\Account; + +class Routes extends \RegExpRouter\RoutesInterface +{ + public function getGetRoutes() + { + return array('/^account$/i' => 'View'); //'View' refers to the 'View' class for THIS model. + } + + public function getPostRoutes() + { + return array(); + } + + public function getDeleteRoutes() + { + return array(); + } + + public function getPutRoutes() + { + return array(); + } +} \ No newline at end of file diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Account/View.php b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Account/View.php new file mode 100644 index 0000000000000000000000000000000000000000..32db7b8313b2c68d6e3bba7f58d323e65381a301 --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Account/View.php @@ -0,0 +1,15 @@ +<?php +namespace Example\Account; + +class View +{ + function __construct(array $options = array()) + { + + } + + function speak() + { + return "I am in " . __CLASS__; + } +} \ No newline at end of file diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Controller.php b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Controller.php new file mode 100644 index 0000000000000000000000000000000000000000..f4269f329e4e5be07a2886020e0749a387d1664a --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Controller.php @@ -0,0 +1,40 @@ +<?php +namespace Example; + +class Controller +{ + /** + * Options array + * Will include $_GET vars + */ + public $options = array( + 'format' => 'html' + ); + + public static $url = ''; + + public $actionable = array(); + + function __construct($options = array()) + { + $this->options = $options + $this->options; + + $model = $this->run(); + echo $model->speak(); + } + + /** + * Run + * + * @throws Exception if view is unregistered + */ + function run() + { + if (!isset($this->options['model'])) { + throw new Exception('Un-registered view', 404); + } + + return new $this->options['model']($this->options); + } + +} \ No newline at end of file diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/Edit.php b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/Edit.php new file mode 100644 index 0000000000000000000000000000000000000000..9f7b90e84d5bbc151487e0230ccb8a40072c8c6a --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/Edit.php @@ -0,0 +1,21 @@ +<?php +namespace Example\Home; + +class Edit +{ + public $id; + + function __construct(array $options = array()) + { + if (!isset($options['id']) || empty($options['id'])) { + throw new Exception("No id was set.", 400); + } + + $this->id = $options['id']; + } + + function speak() + { + return "I am in " . __CLASS__ . " and my ID is: " . $this->id; + } +} \ No newline at end of file diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/Routes.php b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/Routes.php new file mode 100644 index 0000000000000000000000000000000000000000..e51185d7b892685f980d60eaad8a5c44c1184084 --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/Routes.php @@ -0,0 +1,34 @@ +<?php +namespace Example\Home; + +class Routes extends \RegExpRouter\RoutesInterface +{ + public function getGetRoutes() + { + return array('/^home$/i' => 'View', //'View' points to the 'View' class for THIS model. + '/^$/i' => 'View', //Match to an empty string, thus this is now the default home page. + ); + } + + public function getPostRoutes() + { + /** + * The Regex: ((?<id>[\d]+)\/)? will match a return variable with the key name 'id' with its value being the digit following it. + * The ? at the end of the statment makes the match optional. + * + * thus /home/1/edit will return array('id'=>1, 'model'=>'Example\Home\Edit'); + * and /home/edit will return array('model'=>'Example\Home\Edit'); + */ + return array('/^home\/((?<id>[\d]+)\/)?edit$/i' => 'Edit'); //'Edit' points to the 'Edit' class for THIS model. + } + + public function getDeleteRoutes() + { + return array(); + } + + public function getPutRoutes() + { + return array(); + } +} \ No newline at end of file diff --git a/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/View.php b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/View.php new file mode 100644 index 0000000000000000000000000000000000000000..9541af5434bcee873d8836ea6a5afe920b7f932c --- /dev/null +++ b/lib/docs/pear.unl.edu/RegExpRouter/examples/src/Example/Home/View.php @@ -0,0 +1,15 @@ +<?php +namespace Example\Home; + +class View +{ + function __construct(array $options = array()) + { + + } + + function speak() + { + return "I am in " . __CLASS__; + } +} \ No newline at end of file diff --git a/lib/php/RegExpRouter/Router.php b/lib/php/RegExpRouter/Router.php new file mode 100644 index 0000000000000000000000000000000000000000..23570146a715b46311d2e328e67da62eb150838d --- /dev/null +++ b/lib/php/RegExpRouter/Router.php @@ -0,0 +1,272 @@ +<?php +/** + * RegExpRouter + * + * This router is used to compile all of the routes for a php application and return + * routes based on regex and a URI. + * + * PHP Version 5 + * + * LICENSE http://www.opensource.org/licenses/mit-license.php + * + * @category Router + * @package RegExpRouter + * @author Michael Fairchild <mfairchild365@gmail.com> + * @author Brett Bieber <brett.bieber@gmail.com> + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version GIT: <git_id> + * @link # + */ +namespace RegExpRouter; + + +/** + * Router + * + * The main router class. Routes a url. + * + * @category Router + * @package RegExpRouter + * @author Michael Fairchild <mfairchild365@gmail.com> + * @author Brett Bieber <brett.bieber@gmail.com> + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @link # + */ +class Router +{ + //Determins if routes should be cached or not. + public static $cacheRoutes = false; + + //The directory where your source is stored. + protected $srcDir = ""; + + //Array of routes + protected $routes = array(); + + /** + * Constructor + * + * @param array $options - array of options. Requires baseURL. srcDir is + * required only if you want to scan for models + * (srcDir must be a full system path). + * + * @throws Exception + */ + function __construct(array $options = array()) + { + //Check if the baseURL is set. + if (!isset($options['baseURL']) || empty($options['baseURL'])) { + throw new Exception("You must define the baseURL", 500); + } + + //Set all class properties with the passed options. + foreach ($options as $key=>$val) { + $this->$key = $val; + } + + //Get the default routes. + $this->routes = $this->getDefaultRoutes(); + } + + /** + * Routes based on a requestURI and options. + * + * @param string $requestURI The request uri. + * @param array $options An array of options. see the readme. + * + * @return array $options - with the model defined (if one was found). + */ + public function route($requestURI, array $options = array()) + { + //tidy up the requestURI + if (!empty($_SERVER['QUERY_STRING'])) { + $requestURI = substr( + $requestURI, + 0, + -strlen($_SERVER['QUERY_STRING']) - 1 + ); + } + + // Trim the base part of the URL + $requestURI = substr( + $requestURI, + strlen(parse_url($this->baseURL, PHP_URL_PATH)) + ); + + /** + * For older systems we used 'view' instead of 'model', + * this allows for backwards compatability. + **/ + if (isset($options['view'], $this->routes[$options['view']])) { + $options['model'] = $this->routes[$options['view']]; + return $options; + } + + /** + * Loop though all of the routes and check to see the + * current url matches any routes. + **/ + foreach ($this->routes as $route_exp=>$model) { + if ($route_exp[0] == '/' + && preg_match($route_exp, $requestURI, $matches) + ) { + $options += $matches; + $options['model'] = $model; + return $options; + } + } + + //No routes were found, don't return a model. + return $options; + } + + /** + * Set the routes. + * + * @param array $newRoutes An associative array of routes. + * + * @return null + */ + public function setRoutes(array $newRoutes) + { + $this->routes = $newRoutes; + } + + /** + * Get the routes + * + * @return array $routes + */ + public function getRoutes() + { + return $this->routes; + } + + /** + * Gets the default routes by using the cache if we are using cached + * routes or by compiling the routes. + * + * @return array $routes + */ + public function getDefaultRoutes() + { + //if we are not caching routes, just compile them. + if (!self::$cacheRoutes) { + return $this->compileRoutes(); + } + + //We are caching routes, so check if we have them cached. + if (file_exists($this->getCachePath())) { + //We have them cached, so send them back. + $cache = file_get_contents($this->getCachePath()); + return unserialize($cache); + } + + //cache the routes because they haven't been cached yet. + return $this->cacheRoutes(); + } + + /** + * Caches the routes. + * + * @return Array $routes + */ + public function cacheRoutes() + { + //Get the routes. + $routes = $this->compileRoutes(); + + //Save the routes on the file system. + file_put_contents($this->getCachePath(), serialize($routes)); + + return $routes; + } + + /** + * Generates and returns the cache path for routes. + * The path is determined by a hash of the class directory name and prefix. + * + * @return string + */ + public function getCachePath() + { + return sys_get_temp_dir() . "/RegExRouterCache_" + . md5($this->srcDir) . ".php"; + } + + /** + * Compiles the routes by looping though all of the models + * and getting the routes for each model. + * + * @return array $routes + */ + public function compileRoutes() + { + //Initialize an empty array. + $routes = array(); + + //Check if we are going to sift though directories. + if (empty($this->srcDir)) { + return $routes; + } + + //Directory iterator + $directory = new \DirectoryIterator($this->srcDir); + + /** + * Loop though the src directory and find all sub + * directories (all models should have a sub directory). + **/ + foreach ($directory as $file) { + //Only check diretories. + if ($file->getType() == 'dir' && !$file->isDot()) { + //generate the filename of the routes class for this model. + $fileName = $this->srcDir . "/" + . $file->getFileName() . "/Routes.php"; + + //If the file exists, include it. + if (file_exists($fileName)) { + include $fileName; + } + } + } + + //Now that we have included all of the routes classes, loop though them. + foreach (get_declared_classes() as $class) { + //Add all of the routes as long as the class extends the routes interface + if (in_array('RegExpRouter\RoutesInterface', class_parents($class))) { + $routes += call_user_func($class . "::getRoutes"); + } + } + + return $routes; + } + + /** + * Adds a single route to the routes array. + * + * @param array $route an associative array containing the route to be added. + * + * @return RegExpRouter\Router $this + */ + public function addRoute(array $route) + { + array_push($this->routes, $route); + + return $this; + } + + /** + * magic function for calling the object as a function. + * Using this method will invoke the route method. + * + * @param string $requestURI the request uri + * @param array $options an array of options. + * + * @return array $options - with the model defined (if one was found). + */ + public function __invoke($requestURI, array $options = array()) + { + return $this->route($requestURI, $options); + } +} diff --git a/lib/php/RegExpRouter/RoutesInterface.php b/lib/php/RegExpRouter/RoutesInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..5478e9830d1b0ef37045e3b62e08f37276193875 --- /dev/null +++ b/lib/php/RegExpRouter/RoutesInterface.php @@ -0,0 +1,109 @@ +<?php +/** + * RegExpRouter RoutesInterface + * + * This file cantins the routes interface class that can be + * optionally used for scanning routes. + * + * PHP Version 5 + * + * LICENSE http://www.opensource.org/licenses/mit-license.php + * + * @category Router + * @package RegExpRouter + * @author Michael Fairchild <mfairchild365@gmail.com> + * @author Brett Bieber <brett.bieber@gmail.com> + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @version GIT: <git_id> + * @link # + */ +namespace RegExpRouter; + + +/** + * RoutesInterface + * + * This class is a routes interface. All Routes class must + * implement this interface to work properly. + * + * @category Router + * @package RegExpRouter + * @author Michael Fairchild <mfairchild365@gmail.com> + * @author Brett Bieber <brett.bieber@gmail.com> + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @link # + */ +abstract class RoutesInterface +{ + /** + * All of the Post POST for this model. + * + * @return array an associative array of routes + */ + abstract public function getPostRoutes(); + + /** + * All of the GET Routes for this model. + * + * @return array an associative array of routes + */ + abstract public function getGetRoutes(); + + /** + * All of the DELETE Routes for this model. + * + * @return array an associative array of routes + */ + abstract public function getDeleteRoutes(); + + /** + * All of the PUT Routes for this model. + * + * @return array an associative array of routes + */ + abstract public function getPutRoutes(); + + /** + * Gathers all of the Routes for this object. + * It then adds the called class's parent's namespace to all of the routes. + * The namespace is added here to make development faster, and to ensure + * that all routes belong to only one model. + * Finally it returns the routs with the added namespace. + * + * @return array $routes an associative array of routes + */ + public static function getRoutes() + { + $class = get_called_class(); + $object = new $class(); + $routes = array(); + $namespace = substr($class, 0, strlen($class)-6); + + $routes += $object->getPostRoutes(); + $routes += $object->getGetRoutes(); + $routes += $object->getDeleteRoutes(); + $routes += $object->getPutRoutes(); + + return $object->addNamespaces($namespace, $routes); + } + + /** + * Adds a namespace to the routes's model class. + * + * @param string $nameSpace the namespace to add to the routes + * @param array $routes the routes to be modified + * + * @return array $newRoutes the modified routes + */ + protected function addNamespaces($nameSpace, array $routes) + { + $newRoutes = array(); + + foreach ($routes as $regex=>$route) { + $route = $nameSpace.$route; + $newRoutes[$regex] = $route; + } + + return $newRoutes; + } +} \ No newline at end of file diff --git a/lib/tests/pear.unl.edu/RegExpRouter/Route/cacheRoute.phpt b/lib/tests/pear.unl.edu/RegExpRouter/Route/cacheRoute.phpt new file mode 100644 index 0000000000000000000000000000000000000000..0262843d35d3ab4051ccf7be9efe789393e188e0 --- /dev/null +++ b/lib/tests/pear.unl.edu/RegExpRouter/Route/cacheRoute.phpt @@ -0,0 +1,19 @@ +--TEST-- +route() test, runs tests for route(). Note, the example app must me correctly set up. +--FILE-- +<?php +if (file_exists(dirname(dirname(dirname(__FILE__))) . '/examples/config.inc.php')) { + require_once dirname(dirname(dirname(__FILE__))) . '/examples/config.inc.php'; +} else { + require dirname(dirname(dirname(__FILE__))) . '/examples/config.sample.php'; +} + +$router = new RegExpRouter\Router(array('baseURL' => Example\Controller::$url, 'srcDir' => dirname(dirname(dirname(__FILE__))) . "/examples/src/Example/")); + +RegExpRouter\Router::$cacheRoutes = true; + +$uri = parse_url(Example\Controller::$url . "home/1/edit", PHP_URL_PATH); +$example = new Example\Controller($router->route($uri, array())); +?> +--EXPECT-- +I am in Example\Home\Edit and my ID is: 1 \ No newline at end of file diff --git a/lib/tests/pear.unl.edu/RegExpRouter/Route/route.phpt b/lib/tests/pear.unl.edu/RegExpRouter/Route/route.phpt new file mode 100644 index 0000000000000000000000000000000000000000..ffe0e14fa17b38d7b69a9c0256ac15fd5f111951 --- /dev/null +++ b/lib/tests/pear.unl.edu/RegExpRouter/Route/route.phpt @@ -0,0 +1,17 @@ +--TEST-- +route() test, runs tests for route(). Note, the example app must me correctly set up. +--FILE-- +<?php +if (file_exists(dirname(dirname(dirname(__FILE__))) . '/examples/config.inc.php')) { + require_once dirname(dirname(dirname(__FILE__))) . '/examples/config.inc.php'; +} else { + require dirname(dirname(dirname(__FILE__))) . '/examples/config.sample.php'; +} + +$router = new RegExpRouter\Router(array('baseURL' => Example\Controller::$url, 'srcDir' => dirname(dirname(dirname(__FILE__))) . "/examples/src/Example/")); + +$uri = parse_url(Example\Controller::$url . "home/1/edit", PHP_URL_PATH); +$example = new Example\Controller($router->route($uri, array())); +?> +--EXPECT-- +I am in Example\Home\Edit and my ID is: 1 \ No newline at end of file diff --git a/lib/tests/pear.unl.edu/RegExpRouter/Route/route_setRoutes.phpt b/lib/tests/pear.unl.edu/RegExpRouter/Route/route_setRoutes.phpt new file mode 100644 index 0000000000000000000000000000000000000000..03f5799ac9b6cb8172d17012df9fc172a7ad2022 --- /dev/null +++ b/lib/tests/pear.unl.edu/RegExpRouter/Route/route_setRoutes.phpt @@ -0,0 +1,22 @@ +--TEST-- +route() test, runs tests for route(). Tests static routs being set with setRoutes(); +--FILE-- +<?php +if (file_exists(dirname(dirname(dirname(__FILE__))) . '/examples/config.inc.php')) { + require_once dirname(dirname(dirname(__FILE__))) . '/examples/config.inc.php'; +} else { + require dirname(dirname(dirname(__FILE__))) . '/examples/config.sample.php'; +} + +$router = new RegExpRouter\Router(array('baseURL' => Example\Controller::$url)); + +$routes = array('/^home\/((?<id>[\d]+)\/)?edit$/i' => 'Example\Home\Edit'); + +$router->setRoutes($routes); + +$uri = parse_url(Example\Controller::$url . "home/2/edit", PHP_URL_PATH); + +$example = new Example\Controller($router->route($uri, array())); +?> +--EXPECT-- +I am in Example\Home\Edit and my ID is: 2 \ No newline at end of file