Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release-0.1.5'

  • Loading branch information...
commit 8177e899180e067b2917d75fdd66120bd8eaaf5c 2 parents 5c9fec8 + bf9c68f
@trq trq authored
View
BIN  build/proem.phar
Binary file not shown
View
123 lib/Proem/Api/Dispatch/Payload.php
@@ -0,0 +1,123 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+/**
+ * @namespace Proem\Api\Dispatch
+ */
+namespace Proem\Api\Dispatch;
+
+use Proem\Util\Storage\KeyValStore;
+
+/**
+ * Proem\Api\Dispatch\Payload
+ */
+class Payload
+{
+ /**
+ * A flag to keep note as to wether or not this Payload is populated
+ *
+ * @var bool
+ */
+ private $populated = false;
+
+ /**
+ * Store the actual data.
+ *
+ * @var array
+ */
+ private $data = array();
+
+ public function __construct()
+ {
+ $this->data = new KeyValStore;
+ }
+
+ /**
+ * Store a parameter.
+ *
+ * @param string $name
+ * @param string|array $value
+ * @return Command
+ */
+ public function setParam($name, $value)
+ {
+ $this->data->set($name, $value);
+ return $this;
+ }
+
+ /**
+ * Store multiple params.
+ *
+ * @param array $params
+ */
+ public function setParams(array $params)
+ {
+ foreach ($params as $index => $value) {
+ $this->setParam($index, $value);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Retrieve a parameter or an optional default.
+ *
+ * @param string $name
+ * @param mixed $default
+ * @return mixed
+ */
+ public function getParam($name, $default = null)
+ {
+ return $this->data->get($name, $default);
+ }
+
+ /**
+ * Retrieve all parameters as KeyValStore.
+ *
+ * @return array
+ */
+ public function getParams()
+ {
+ return $this->data;
+ }
+
+ /**
+ * Is the Payload Populated?
+ */
+ public function isPopulated()
+ {
+ return $this->populated;
+ }
+
+ /**
+ * Set the populated flag
+ */
+ public function setPopulated()
+ {
+ $this->populated = true;
+ }
+}
View
16 lib/Proem/Api/IO/Http/Response.php
@@ -118,6 +118,22 @@ class Response
public function __construct()
{
$this->headers = new KeyValStore;
+ $this->headers->set('X-Powered-By','Proem Framework ' . \Proem\Proem::VERSION);
+ }
+
+ /**
+ * Silence the X-Powered-By header produced by Proem.
+ *
+ * This header produces X-Powered-By: Proem Framework X.X.X
+ * and may pose a security concern. It's just here as an easter
+ * egg more than anything. Removing it from this Request may
+ * not remove it all together as PHP itself can produce this
+ * same heeader.
+ */
+ public function silence()
+ {
+ $this->headers->remove('X-Powered-By');
+ return $this;
}
/**
View
2  lib/Proem/Api/Proem.php
@@ -49,7 +49,7 @@ class Proem
/**
* Store the framework version
*/
- const VERSION = '0.1.4';
+ const VERSION = '0.1.5';
/**
* Store events
View
117 lib/Proem/Api/Routing/Route/Generic.php
@@ -0,0 +1,117 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+/**
+ * @namespace Proem\Api\Routing\Route
+ */
+namespace Proem\Api\Routing\Route;
+
+use Proem\Dispatch\Payload,
+ Proem\Util\Opt\Options,
+ Proem\Util\Opt\Option,
+ Proem\Util\ArrayHelper;
+
+/**
+ * Proem\Api\Routing\Route
+ */
+abstract class Generic
+{
+ use Options;
+ use ArrayHelper;
+
+ /**
+ * Store the options for this route
+ */
+ protected $options = [];
+
+ /**
+ * Store a flag indicating a route match
+ *
+ * @var bool
+ */
+ protected $matched = false;
+
+ /**
+ * Store matched parameters within a Dispatch\Payload object.
+ */
+ protected $payload = null;
+
+ /**
+ * Instantiate this route
+ */
+ public function __construct(array $options)
+ {
+ $this->options = $this->setOptions([
+ 'rule' => (new Option(''))->type('string'),
+ 'targets' => (new Option([]))->type('array'),
+ 'filters' => (new Option([]))->type('array')
+ ], $options);
+ }
+
+ /**
+ * Was a match found?
+ *
+ * @return bool
+ */
+ public function isMatch()
+ {
+ return $this->matched;
+ }
+
+ /**
+ * Set matched flag.
+ */
+ public function setMatch()
+ {
+ $this->matched = true;
+ return $this;
+ }
+
+ /**
+ * Retrieve the Payload.
+ */
+ public function getPayload()
+ {
+ if ($this->payload === null) {
+ $this->payload = new Payload;
+ }
+
+ return $this->payload;
+ }
+
+ /**
+ * Method to actually test for a match.
+ *
+ * If a match is found, $this->matched should be set to true
+ * and the payload needs to be instantiated to contain the relevent
+ * matched data.
+ *
+ * @param \Proem\IO\Url $url
+ * @param array $options Options dependent on your implementation.
+ */
+ abstract public function process($uri);
+}
View
164 lib/Proem/Api/Routing/Route/Standard.php
@@ -0,0 +1,164 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+/**
+ * @namespace Proem\Api\Routing\Route
+ */
+namespace Proem\Api\Routing\Route;
+
+use Proem\Routing\Route\Generic;
+
+/**
+ * Proem\Api\Routing\Route\Standard
+ */
+class Standard extends Generic
+{
+ /**
+ * Store default tokens.
+ */
+ private $_default_tokens = [];
+
+ /**
+ * Store default filters.
+ */
+ private $default_filters = [];
+
+ /**
+ * Instantiate object & setup default filters.
+ */
+ public function __construct(array $options) {
+ parent::__construct($options);
+
+ $this->_default_filters = [
+ ':default' => '[a-zA-Z0-9_\+\-%]+',
+ ':gobble' => '[a-zA-Z0-9_\+\-%\/]+',
+ ':int' => '[0-9]+',
+ ':alpha' => '[a-zA-Z]+',
+ ':slug' => '[a-zA-Z0-9_-]+'
+ ];
+
+ $this->_default_tokens = [
+ 'module' => $this->_default_filters[':default'],
+ 'controller' => $this->_default_filters[':default'],
+ 'action' => $this->_default_filters[':default'],
+ 'params' => $this->_default_filters[':gobble']
+ ];
+ }
+
+ /**
+ * Process the gievn url.
+ *
+ * This route takes a simplified series of patterns such as :controller and
+ * replaces them with more complex regular expressions which are then used
+ * within a preg_match_callback to match against the given uri.
+ *
+ * A default rule of /:controller/:action/:params is used if no rule is
+ * provided through the $options array.
+ *
+ * If a 'filter' regex is set within the $options array that regex will be
+ * used within the preg_match_callback. Otherwise a default regex of
+ * ([a-zA-Z0-9_\+\-%]+) is used.
+ *
+ * If one of the 'simplified' patterns within the rule is :params, this is
+ * treated specially and uses a ([a-zA-Z0-9_\+\-%\/]+) regex which will match
+ * the same as the default as well as / .
+ *
+ * This causes the pattern to match entire sections of uri's. Allowing a
+ * simple pattern like the default /:controller/:action/:params to match
+ * uri's like /foo/bar/a/b/c/d/e/f/g/h and cause everything after /foo/bar
+ * to be added to the Payload object as params (which are in turn transformed
+ * into key => value pairs).
+ *
+ * @param string $uri
+ */
+ public function process($uri)
+ {
+ if (!$this->options->rule) {
+ return false;
+ }
+
+ $rule = $this->options->rule;
+ $target = $this->options->targets;
+ $custom_filters = $this->options->filters;
+ $default_tokens = $this->_default_tokens;
+ $default_filters = $this->_default_filters;
+
+ $keys = [];
+ $values = [];
+ $params = [];
+
+ preg_match_all('@:([\w]+)@', $rule, $keys, PREG_PATTERN_ORDER);
+ $keys = $keys[0];
+
+ $regex = preg_replace_callback(
+ '@:[\w]+@',
+ function($matches) use ($custom_filters, $default_tokens, $default_filters)
+ {
+ $key = str_replace(':', '', $matches[0]);
+ if (array_key_exists($key, $custom_filters)) {
+ if (array_key_exists($custom_filters[$key], $default_filters)) {
+ return '(' . $default_filters[$custom_filters[$key]] . ')';
+ } else {
+ return '(' . $custom_filters[$key] . ')';
+ }
+ } else if (array_key_exists($key, $default_tokens)) {
+ return '(' . $default_tokens[$key] . ')';
+ } else {
+ return $default_filters['default'];
+ }
+ },
+ $rule
+ ) . '/?';
+
+ if (preg_match('@^' . $regex . '$@', $uri, $values)) {
+ array_shift($values);
+
+ foreach ($keys as $index => $value) {
+ $params[substr($value, 1)] = urldecode($values[$index]);
+ }
+
+ foreach ($target as $key => $value) {
+ $params[$key] = $value;
+ }
+
+ $this->setMatch();
+ foreach ($params as $key => $value) {
+ // If the string within $value looks like a / seperated string,
+ // parse it into an array and send it to setParams() instead
+ // of the singular setParam.
+ if ($key == 'params' && strpos($value, '/') !== false) {
+ $this->getPayload()->setParams($this->createAssocArray(explode('/', trim($value, '/'))));
+ } else {
+ $this->getPayload()->setParam($key, $value);
+ }
+ }
+
+ $this->getPayload()->setPopulated();
+ }
+ return $this;
+ }
+}
View
84 lib/Proem/Api/Routing/Router.php
@@ -0,0 +1,84 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+/**
+ * @namespace Proem\Api\Routing
+ */
+namespace Proem\Api\Routing;
+
+use Proem\Routing\Route\Generic as Route;
+
+/**
+ * Proem\Api\Routing\Router
+ */
+class Router
+{
+ /**
+ * Store the request url
+ */
+ private $requestUrl;
+
+ /**
+ * Store our routes
+ *
+ * @var array
+ */
+ private $routes = [];
+
+ /**
+ * Setup
+ *
+ * @param string $requestUri
+ */
+ public function __construct($requestUri)
+ {
+ $this->requestUri = $requestUri;
+ }
+
+ /**
+ * Store route objects
+ */
+ public function map($name, Route $route)
+ {
+ $this->_routes[$name] = $route;
+ return $this;
+ }
+
+ /**
+ * Test routes for matching route and found return a DispatchPayload
+ */
+ public function route()
+ {
+ foreach ($this->_routes as $name => $route) {
+ $route->process($this->requestUri);
+ if ($route->isMatch() && $route->getPayload()->isPopulated()) {
+ break;
+ }
+ }
+ return $route->getPayload();
+ }
+}
View
58 lib/Proem/Api/Util/ArrayHelper.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+/**
+ * @namespace Proem\Api\Util
+ */
+namespace Proem\Api\Util;
+
+/**
+ * Proem\Api\Util\ArrayHelper
+ */
+trait ArrayHelper
+{
+ /**
+ * Turn a numerically indexed array into an associative array.
+ *
+ * eg;
+ * ['foo', 'bar', 'bob', 'boo']
+ * becomes:
+ * ['foo' => 'bar', 'bob' => 'boo']
+ */
+ public function createAssocArray($params)
+ {
+ $tmp = array();
+ for ($i = 0; $i <= count($params); $i = $i+2) {
+ if (isset($params[$i+1])) {
+ $tmp[(string) $params[$i]] = (string) $params[$i+1];
+ } else {
+ break;
+ }
+ }
+ return $tmp;
+ }
+}
View
99 tests/lib/Proem/Tests/Routing/RouterTest.php
@@ -0,0 +1,99 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+namespace Proem\Tests;
+
+use Proem\Routing\Router,
+ Proem\Routing\Route\Standard;
+
+class RouterTest extends \PHPUnit_Framework_TestCase
+{
+ public function testCanInstantiateAsset()
+ {
+ $r = new Router('');
+ $this->assertInstanceOf('\Proem\Routing\Router', $r);
+ }
+
+ public function testTargetedMapedRoute()
+ {
+ $router = new Router('/login');
+ $payload = $router->map(
+ 'simple',
+ new Standard([
+ 'rule' => '/login',
+ 'targets' => ['controller' => 'auth', 'action' => 'login']
+ ])
+ )->route();
+
+ $this->assertInstanceOf('\Proem\Dispatch\Payload', $payload);
+ $this->assertTrue($payload->isPopulated());
+ $this->assertEquals('auth', $payload->getParam('controller'));
+ $this->assertEquals('login', $payload->getParam('action'));
+ $this->assertNull($payload->getParam('doesntexist'));
+ }
+
+ public function dataProvider()
+ {
+ return [
+ ['/', 'home', 'index'],
+ ['/login', 'auth', 'login'],
+ ['/logout', 'auth', 'logout']
+ ];
+ }
+
+ /**
+ * @dataProvider dataProvider
+ */
+ public function testSeriesOfMappedRoutes($uri, $controller, $action)
+ {
+ $router = new Router($uri);
+ $payload = $router
+ ->map(
+ 'home-page',
+ new Standard([
+ 'rule' => '/',
+ 'targets' => ['controller' => 'home']
+ ])
+ )->map(
+ 'login',
+ new Standard([
+ 'rule' => '/login',
+ 'targets' => ['controller' => 'auth', 'action' => 'login']
+ ])
+ )->map(
+ 'logout',
+ new Standard([
+ 'rule' => '/logout',
+ 'targets' => ['controller' => 'auth', 'action' => 'logout']
+ ])
+ )->route();
+
+ $this->assertInstanceOf('\Proem\Dispatch\Payload', $payload);
+ $this->assertTrue($payload->isPopulated());
+ $this->assertEquals($controller, $payload->getParam('controller'));
+ $this->assertEquals($action, $payload->getParam('action', 'index'));
+ }
+}
View
85 tests/lib/Proem/Tests/Routing/StandardRouteTest.php
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+namespace Proem\Tests;
+
+use Proem\Routing\Route\Standard;
+
+class StandardRouteTest extends \PHPUnit_Framework_TestCase
+{
+ public function testCanInstantiateAsset()
+ {
+ $r = new Standard([]);
+ $this->assertInstanceOf('Proem\Routing\Route\Generic', $r);
+ }
+
+ public function testController()
+ {
+ $route = new Standard([
+ 'rule' => '/:controller/:action/:params'
+ ]);
+ $route->process('/foo/bar/a/b');
+
+ $this->assertTrue($route->getPayload()->isPopulated());
+ $this->assertEquals('foo', $route->getPayload()->getParam('controller'));
+ $this->assertEquals('bar', $route->getPayload()->getParam('action'));
+ $this->assertEquals('b', $route->getPayload()->getParam('a'));
+ }
+
+ public function testModule()
+ {
+ $route = new Standard([
+ 'rule' => '/:module/:controller/:action/:params'
+ ]);
+ $route->process('/bob/foo/bar/a/b');
+
+ $this->assertTrue($route->getPayload()->isPopulated());
+ $this->assertEquals('bob', $route->getPayload()->getParam('module'));
+ $this->assertEquals('foo', $route->getPayload()->getParam('controller'));
+ $this->assertEquals('bar', $route->getPayload()->getParam('action'));
+ $this->assertEquals('b', $route->getPayload()->getParam('a'));
+ }
+
+ public function testAlphaFilter()
+ {
+ $route = new Standard([
+ 'rule' => '/:data',
+ 'filters' => ['data' => ':alpha']
+ ]);
+ $route->process('/foo');
+
+ $this->assertTrue($route->getPayload()->isPopulated());
+ $this->assertEquals('foo', $route->getPayload()->getParam('data'));
+
+ $route = new Standard([
+ 'rule' => '/:data',
+ 'filters' => ['data' => ':alpha']
+ ]);
+ $route->process('/123');
+
+ $this->assertFalse($route->getPayload()->isPopulated());
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.