Page MenuHomePhabricator

D526.id1681.diff
No OneTemporary

D526.id1681.diff

diff --git a/AbsoluteURL.php b/AbsoluteURL.php
--- a/AbsoluteURL.php
+++ b/AbsoluteURL.php
@@ -46,7 +46,7 @@
$get = array_shift($params);
$environment = array_shift($params);
- parent::__construct($app, $controller, $action, $object, 'php', $get, $environment);
+ parent::__construct($controller, $action, $object, 'php', $get, $environment);
}
}
diff --git a/App.php b/App.php
--- a/App.php
+++ b/App.php
@@ -76,7 +76,6 @@
#The reverser for the default route is rather simple again.
#It will concatenate app, controller and action
$default->setReverser(new ClosureReverser(function (Path$path, $explicit = false) {
- $app = $path->getApp();
$controller = $path->getController();
$action = $path->getAction();
$object = $path->getObject();
@@ -84,7 +83,7 @@
if ($action === Environment::get('default_action') && empty($object) && !$explicit) { $action = ''; }
if ($controller === (array)Environment::get('default_controller') && empty($object) && empty($action) && !$explicit) { $controller = Array(); }
- return '/' . trim(implode('/', array_filter(array_merge([$app], (array)$controller, [$action], $object))), '/');
+ return '/' . trim(implode('/', array_filter(array_merge((array)$controller, [$action], $object))), '/');
}));
}
diff --git a/core/Path.php b/core/Path.php
--- a/core/Path.php
+++ b/core/Path.php
@@ -15,14 +15,6 @@
class Path
{
- /**
- * The namespace of the app being used. This allows spitfire to locate the
- * application for the namespace and correctly handle it.
- *
- * @var string|null|Pattern
- */
- private $app;
-
/**
* The 'name' of the controller expected. The name of the controller is a list
* of string in an array. This is especially useful when mapping a URL
@@ -73,15 +65,13 @@
* the expected response format and the parameters it took from the URL.
*
*
- * @param string|Pattern|App|null $app
* @param string[]|Pattern[]|Pattern|string|null $controller
* @param string|Pattern|null $action
* @param string[]|Pattern[]|string|Pattern|null $object
* @param string[]|string $format
* @param string[]|Pattern[] $parameters
*/
- public function __construct($app, $controller, $action, $object, $format = 'php', $parameters = Array()) {
- $this->app = $app instanceof App? $app->url() : $app;
+ public function __construct($controller, $action, $object, $format = 'php', $parameters = Array()) {
$this->controller = array_filter(is_array($controller)? $controller : [$controller]);
$this->action = $action;
$this->object = array_filter(is_array($object)? $object : [$object]);
@@ -89,34 +79,6 @@
$this->parameters = $parameters;
}
- /**
- * Returns the namespace of the app chosen to handle the request. This allows
- * your application to quickly generate links pointing to the current app.
- *
- * @return string|null|Pattern
- */
- public function getApp() {
- return $this->app;
- }
-
- /**
- * Changes the app in charge of handling the requested Path. Please note that
- * this is required to be the namespace of the app, so you will have to retrieve
- * this from the app in case you wanna use it.
- *
- * @param string $app
- * @return Path
- */
- public function setApp($app) {
- #If the App is actually an App and the user didn't read the doc, we will
- #forgive him.
- if ($app instanceof App) {
- $app = $app->getMapping()->getNameSpace();
- }
- $this->app = $app;
- return $this;
- }
-
/**
* Returns the controller name in array format. This allows you to manipulate
* the fragments easily.
diff --git a/core/functions.php b/core/functions.php
--- a/core/functions.php
+++ b/core/functions.php
@@ -278,18 +278,8 @@
*/
function url() {
#Get the parameters the first time
- $sf = spitfire();
$params = func_get_args();
- #Extract the app
- try {
- $app = $sf->getApp(reset($params));
- array_shift($params);
- }
- catch (\spitfire\core\app\AppNotFoundException$ex) {
- $app = $sf->getApp('');
- }
-
#Get the controller, and the action
$controller = null;
$action = null;
@@ -307,7 +297,7 @@
$get = array_shift($params);
$environment = array_shift($params);
- return new URL($app, $controller, $action, $object, 'php', $get, $environment);
+ return new URL($controller, $action, $object, 'php', $get, $environment);
}
/**
diff --git a/core/http/URL.php b/core/http/URL.php
--- a/core/http/URL.php
+++ b/core/http/URL.php
@@ -29,10 +29,10 @@
private $params = Array();
- public function __construct($app, $controller = null, $action = null, $object = null, $extension = null, $get = null, $environment = null) {
+ public function __construct($controller = null, $action = null, $object = null, $extension = null, $get = null, $environment = null) {
$this->params = $get;
- $this->path = new Path($app, $controller, $action, $object, $extension, $environment);
+ $this->path = new Path($controller, $action, $object, $extension, $environment);
}
public function setExtension($extension) {
@@ -53,15 +53,6 @@
return $this;
}
- public function setApp($app) {
- $this->path->setApp($app);
- return $this;
- }
-
- public function getApp() {
- return $this->path->getApp();
- }
-
/**
* Sets a parameter for the URL's GET
* @param string $param
@@ -133,11 +124,6 @@
$url = $rev->reverse($this->path);
}
- foreach ($this->getRedirections() as $red) {
- try { $url = $red->reverse($url); }
- catch (\Exception$e) { /*Ignore*/ }
- }
-
if (empty(trim($url, '/')) && $this->path->getFormat() !== 'php') {
$url = $rev->reverse($this->path, true);
}
@@ -197,7 +183,7 @@
return $e instanceof \spitfire\Model? implode(':', $e->getPrimaryData()) : $e;
}, $ctx->object);
- return new URL($ctx->app, $ctx->app->getControllerLocator()->getControllerURI($ctx->controller), $ctx->action, $object, $ctx->extension, $_GET);
+ return new URL($ctx->app->getControllerLocator()->getControllerURI($ctx->controller), $ctx->action, $object, $ctx->extension, $_GET);
}
public static function canonical() {
@@ -207,11 +193,11 @@
throw new PrivateException("No context for URL generation");
}
- return new URL($ctx->app, $ctx->controller, $ctx->action, $ctx->object, $ctx->extension, $_GET->getCanonical());
+ return new URL($ctx->controller, $ctx->action, $ctx->object, $ctx->extension, $_GET->getCanonical());
}
public function absolute($domain = null) {
- $t = new AbsoluteURL($this->getApp());
+ $t = new AbsoluteURL();
$t->setExtension($this->getExtension());
$t->setParams($this->params);
@@ -228,15 +214,5 @@
));
}
- /**
- *
- * @return \spitfire\core\router\Redirection[]
- */
- public function getRedirections() {
- $router = Router::getInstance();
- return array_merge(
- $router->server()->getRedirections()->toArray(), $router->getRedirections()->toArray()
- );
- }
}
diff --git a/core/router/ParametrizedPath.php b/core/router/ParametrizedPath.php
--- a/core/router/ParametrizedPath.php
+++ b/core/router/ParametrizedPath.php
@@ -66,7 +66,6 @@
* with controller, action and object.
*/
$path = new Path(
- self::replaceIn($this->getApp(), $data),
self::replaceIn($this->getController(), $data),
self::replaceIn($this->getAction(), $data),
array_merge(self::replaceIn($this->getObject(), $data), $add),
@@ -122,7 +121,6 @@
* internal data.
*/
$p = new Parameters();
- $p->addParameters($fn([$this->getApp()], [$from->getApp()]));
$p->addParameters($fn($this->getController(), $from->getController()));
$p->addParameters($fn([$this->getAction()], [$from->getAction()]));
$p->addParameters($fn($this->getObject(), $from->getObject(), true));
@@ -146,7 +144,6 @@
public function getPatterns() {
#Extract the patterns
$patterns = new Collection(array_merge(
- [$this->getApp()],
$this->getController(),
[$this->getAction()],
$this->getObject(),
@@ -227,7 +224,6 @@
* of code that requires the new version to function.
*/
return new ParametrizedPath(
- $arr['app']?? null,
$arr['controller']?? null,
isset($arr['action'])? reset($arr['action']) : null,
$arr['object']?? null,
diff --git a/core/router/Redirection.php b/core/router/Redirection.php
deleted file mode 100644
--- a/core/router/Redirection.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php namespace spitfire\core\router;
-
-use spitfire\core\router\reverser\RouteReverserInterface;
-
-/**
- * A route is a class that rewrites a URL path (route) that matches a
- * route or pattern (old_route) into a new route that the system can
- * use (new_route) to handle the current request.
- *
- * A Route will only accept Closures, Responses or Paths (including arrays that
- * can be interpreted as Paths by the translation class) as the target.
- *
- * @todo Define translate class for array to Path translation
- * @todo Define parameter class to replace inside Paths
- * @author César de la Cal <cesar@magic3w.com>
- */
-class Redirection extends RewriteRule
-{
-
-
- private $reverser;
-
- public function __construct(Routable $server, $pattern, $new_route, $method, $proto = Route::PROTO_ANY) {
- parent::__construct($server, $pattern, $new_route, $method, $proto);
- $this->reverser = $this;
- }
-
- /**
- *
- * @return RouteReverserInterface
- */
- public function getReverser() {
- return $this->reverser;
- }
-
- /**
- *
- * @param RouteReverserInterface $reverser
- * @return Route
- */
- public function setReverser($reverser) {
- $this->reverser = $reverser;
- return $this;
- }
-
- /**
- *
- * @param type $URI
- * @param type $method
- * @param type $protocol
- * @param type $server
- * @return string New route
- */
- public function rewrite($URI, $method, $protocol, $server) {
- try {
- return $this->getTarget()->reverse($this->getSource()->test($URI));
- }
- catch (\spitfire\core\router\RouteMismatchException$e) {
- return false;
- }
- catch (\spitfire\exceptions\PrivateException$e) {
- return false;
- }
- }
-
- /**
- * Takes a URL that may match the target URL and if it does, take the params
- * and construct a source compatible URL.
- *
- * @throws RouteMismatchException
- * @throws \spitfire\exceptions\PrivateException
- * @param string $uri
- * @return string
- */
- public function reverse($uri) {
- return $this->getSource()->reverse($this->getTarget()->test($uri));
- }
-
-}
diff --git a/core/router/RewriteRule.php b/core/router/RewriteRule.php
--- a/core/router/RewriteRule.php
+++ b/core/router/RewriteRule.php
@@ -169,5 +169,5 @@
* @todo Server parameter should be a Parameter set provided by the server IMO
* Need to check whether the server itself could have any impact on it
*/
- abstract public function rewrite($URI, $method, $protocol, $server);
+ abstract public function rewrite($URI, $method, $protocol, Parameters $server);
}
diff --git a/core/router/Routable.php b/core/router/Routable.php
--- a/core/router/Routable.php
+++ b/core/router/Routable.php
@@ -20,15 +20,8 @@
private $routes;
- /**
- *
- * @var Collection
- */
- private $redirections;
-
public function __construct() {
$this->routes = new Collection();
- $this->redirections = new Collection();
}
/**
@@ -41,7 +34,7 @@
* @return Route The route that is generated by this
*/
public function request($pattern, $target) {
- return $this->addRoute($pattern, $target, Route::METHOD_GET|Route::METHOD_POST|Route::METHOD_HEAD|Route::METHOD_OPTIONS);
+ return $this->addRoute($pattern, $target, Route::METHOD_GET|Route::METHOD_POST|Route::METHOD_HEAD);
}
/**
@@ -50,12 +43,28 @@
*
* @param string $pattern A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
* @param string $target Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
- * @return Route|Redirection The route that is generated by this
+ * @return Route The route that is generated by this
*/
public function get($pattern, $target) {
return $this->addRoute($pattern, $target, Route::METHOD_GET);
}
+ /**
+ * Adds a route to reply to OPTIONS requests, these are most commonly used by
+ * user-agents when they attempt to perform pre-flight CORS tests.
+ *
+ * Options requests should therefore not be treated the same way as GET, POST
+ * or HEAD requests, since they do not assume that the user agent is enforcing
+ * CORS policies when sending them.
+ *
+ * @param string $pattern A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
+ * @param string $target Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
+ * @return Route The route that is generated by this
+ */
+ public function options($pattern, $target) {
+ return $this->addRoute($pattern, $target, Route::METHOD_OPTIONS);
+ }
+
/**
* This method adds a route that will only rewrite the request if it's method
@@ -108,14 +117,6 @@
*/
public function addRoute($pattern, $target, $method = 0x03, $protocol = 0x03) {
- /*
- * If the target of our route is a string or a URI we will turn it into a
- * redirection.
- */
- if (is_string($target) || $target instanceof URIPattern) {
- return $this->redirections->push(new Redirection($this, URIPattern::make($pattern), URIPattern::make($target), $method, $protocol));
- }
-
/*
* For the other accepted targets, we will create a route. This will
* translate in a response from the system (either through a controller or
@@ -137,10 +138,6 @@
}
}
- public function getRedirections() {
- return $this->redirections;
- }
-
public function getRoutes() {
return $this->routes;
}
diff --git a/core/router/Route.php b/core/router/Route.php
--- a/core/router/Route.php
+++ b/core/router/Route.php
@@ -34,6 +34,7 @@
const METHOD_PUT = 0x04;
const METHOD_DELETE = 0x08;
const METHOD_HEAD = 0x10;
+ const METHOD_OPTIONS= 0x20;
private $reverser = null;
@@ -46,7 +47,7 @@
* @param string $extension
* @return \spitfire\core\Path|\spitfire\core\Response
*/
- public function rewrite($URI, $method, $protocol, $server, $extension = 'php') {
+ public function rewrite($URI, $method, $protocol, Parameters $server, $extension = 'php') {
$params = $this->getSource()->test($URI);
/*
diff --git a/core/router/Rule.php b/core/router/Rule.php
deleted file mode 100644
--- a/core/router/Rule.php
+++ /dev/null
@@ -1,133 +0,0 @@
-<?php namespace spitfire\core\router;
-
-use spitfire\exceptions\PrivateException;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * 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.
- */
-
-/**
- * The router\rule class allows the application to define both routes and
- * redirections, since both inherit from it.
- *
- * The request path finder will manage the nice-ness. And therefore will allow
- * spitfire to sort the requests by priority. Please note that the less nice a
- * route / redirection is the sooner it will be used.
- *
- * Also note that, depending on the task - the sorter may use other factors than
- * the nice-ness to determine whether a path finder has priority over another,
- * specifically it's type will be very important.
- */
-abstract class Rule
-{
-
- const NICENESS_MIN = 0x00;
- const NICENESS_MAX = 0xff;
-
- /**
- * The default niceness of a route that's intended to catch all the traffic.
- * Please note that we do not use the nicest value for the default catch-all
- * to provide additional fallback.
- *
- * e.g. A system that shows a user-profile if the username doesn't collide
- * with a controller name. Obviously, a user should not be able to override
- * a site's section with their username.
- */
- const NICENESS_CATCHALL = 0xf9;
-
- /**
- * Niceness is a term inherited from the Linux / Unix process management.
- * Every route is created as a high priority route with 0 niceness, but you
- * can let your route give precedence to the rest.
- *
- * Please note that niceness (0xff - 0x05) and above is reserved to default
- * routes and creating a route THAT nice may result in it never being used.
- *
- * @var int
- */
- private $niceness = 0x00;
-
- /**
- * Defines the niceness of the rule. This allows the application to define
- * what priority the system gives to the rule.
- *
- * As opposed to raising priority, niceness allows a rule to give precedence
- * to the other rules.
- *
- * @param int $niceness
- * @return Rule
- * @throws PrivateException
- */
- public function setNiceness($niceness) {
-
- /*
- * Since niceness can only have values ranging between (0 and 255) we will
- * verify that these are not exceeded. Accepting values other than these
- * could lead to broken sorting and therefore faulty behaviour.
- */
- if ($niceness > self::NICENESS_MAX || $niceness < self::NICENESS_MIN) {
- throw new PrivateException('Niceness is out of range', 1705161724);
- }
-
- #If the niceness was actually fine, then we continue.
- $this->niceness = $niceness;
-
- #Make this setter fluent
- return $this;
- }
-
- /**
- * Returns the niceness score for the current rule. This allows the router
- * to sort them appropriately when routing or de-routing.
- *
- * @return int
- */
- public function getNiceness() {
- return $this->niceness;
- }
-
- /**
- * Depending on whether this object is a Route or a Redirection it will return
- * a route reverser or a redirection (that reverses the current one) respectively.
- *
- * Please note that if a route provides no reverser (alas. no way to undo
- * itself) the method may return null and therefore require filtering.
- *
- * @return reverser\RouteReverserInterface|Redirection|null
- */
- public abstract function getReverser();
-
- /**
- * This method allows a rule to rewrite the request it's receiving. This can
- * result in either a Path, a Response object or a string (in the case of
- * redirections).
- *
- * @param string $URI The URI being requested
- * @param int $method The HTTP method (GET / POST / PUT)
- * @param int $protocol Whether the request is HTTP or HTTPS
- * @param Server $server The server the request is being routed through
- * @return \spitfire\core\Path|\spitfire\core\Response|string|false
- */
- public abstract function rewrite($URI, $method, $protocol, Server$server);
-
-}
\ No newline at end of file
diff --git a/core/router/Server.php b/core/router/Server.php
--- a/core/router/Server.php
+++ b/core/router/Server.php
@@ -63,10 +63,7 @@
if (!($params = $this->test($server))) { return false; }
#Combine routes from the router and server
- $routes = array_merge(
- $this->getRedirections()->toArray(), $this->router->getRedirections()->toArray(),
- $this->getRoutes()->toArray(), $this->router->getRoutes()->toArray()
- );
+ $routes = array_merge( $this->getRoutes()->toArray(), $this->router->getRoutes()->toArray() );
#Test the routes
foreach ($routes as $route) { /*@var $route Route*/
diff --git a/tests/URLTest.php b/tests/URLTest.php
--- a/tests/URLTest.php
+++ b/tests/URLTest.php
@@ -21,7 +21,6 @@
Router::getInstance()->server(':lang.:tld.com')->request('/hello/', ['controller' => 'test', 'action' => 'a', 'object' => 'a']);
#Create a redirection
- Router::getInstance()->request('/about', '/static/about');
Router::getInstance()->request('/static/:page', ['controller' => 'content', 'action' => 'page', 'object' => ':page']);
$t = new \spitfire\UnnamedApp('');
@@ -72,12 +71,4 @@
$this->assertEquals('http://test.com/a/a/', strval($absURL));
}
- public function testRedirectionReverser() {
- $urla = url('content', 'page', 'about');
- $urlb = url('content', 'page', 'me');
-
- $this->assertEquals('/static/me/', strval($urlb));
- $this->assertEquals('/about/', strval($urla));
- }
-
}
\ No newline at end of file
diff --git a/tests/router/ParametrizedPathTest.php b/tests/router/ParametrizedPathTest.php
--- a/tests/router/ParametrizedPathTest.php
+++ b/tests/router/ParametrizedPathTest.php
@@ -32,19 +32,17 @@
{
public function testReplacement() {
- $pp = new ParametrizedPath(new Pattern(':app'), new Pattern(':controller'), new Pattern(':action'), new Pattern(':object'));
- $path = $pp->replace(['app' => 'a', 'controller' => 'b', 'action' => 'c', 'object' => 'd']);
+ $pp = new ParametrizedPath(new Pattern(':controller'), new Pattern(':action'), new Pattern(':object'));
+ $path = $pp->replace(['controller' => 'b', 'action' => 'c', 'object' => 'd']);
- $this->assertEquals('a', $path->getApp());
$this->assertEquals('b', $path->getController()[0]);
$this->assertEquals('c', $path->getAction());
}
public function testReplacementArrays() {
- $pp = new ParametrizedPath(new Pattern(':app'), [new Pattern(':c2'), new Pattern(':c1')], new Pattern(':action'), new Pattern(':object'));
- $path = $pp->replace(['app' => 'a', 'c1' => 'b1', 'c2' => 'b2', 'action' => 'c', 'object' => 'd']);
+ $pp = new ParametrizedPath([new Pattern(':c2'), new Pattern(':c1')], new Pattern(':action'), new Pattern(':object'));
+ $path = $pp->replace(['c1' => 'b1', 'c2' => 'b2', 'action' => 'c', 'object' => 'd']);
- $this->assertEquals('a', $path->getApp());
$this->assertEquals('b2', $path->getController()[0]);
$this->assertEquals('c', $path->getAction());
}
diff --git a/tests/router/RouterTest.php b/tests/router/RouterTest.php
--- a/tests/router/RouterTest.php
+++ b/tests/router/RouterTest.php
@@ -6,7 +6,10 @@
*/
use PHPUnit\Framework\TestCase;
+use spitfire\core\Path;
+use spitfire\core\router\Parameters;
use spitfire\core\router\Route;
+use spitfire\core\router\RouteMismatchException;
use spitfire\core\router\Router;
class RouterTest extends TestCase
@@ -25,8 +28,8 @@
*/
public function testCreateRoute() {
- $route = $this->router->get('/test', 'test2');
- $this->assertInstanceOf('\spitfire\core\router\Redirection', $route);
+ $route = $this->router->get('/test', ['controller' => 'test']);
+ $this->assertInstanceOf('\spitfire\core\router\Route', $route);
}
/**
@@ -38,45 +41,37 @@
$router = $this->router;
#Prepare a route that redirects with no parameters
- $route = $router->get('/test', 'test2');
+ $route = $router->get('/test', ['controller' => 'test']);
$this->assertEquals(true, $route->test('/test', 'GET', Route::PROTO_HTTP, $router->server()));
- $this->assertEquals('/test2/', $route->rewrite('/test', 'GET', Route::PROTO_HTTP, $router->server()));
+ $this->assertInstanceOf(Path::class, $route->rewrite('/test', 'GET', Route::PROTO_HTTP, new Parameters));
$this->assertEquals(false, $route->test('/test', 'POST', Route::PROTO_HTTP, $router->server()));
//> This last test should fail because we're sending a POST request to a GET route
- #Prepare a route that redirects with parameters
- $route2 = $router->get('/another/:param', '/:param/another');
- $this->assertEquals('/test/another/', $route2->rewrite('/another/test', 'GET', Route::PROTO_HTTP, $router->server()));
- $this->assertEquals('/test/another/', $route2->rewrite('/another/test/', 'GET', Route::PROTO_HTTP, $router->server()));
- $this->assertEquals(false, $route2->test('/another/test', 'POST', Route::PROTO_HTTP, $router->server()));
}
public function testTrailingSlashStringRoute() {
$router = $this->router;
#Create a route with a trailing slash
- $route1 = $router->get('/this/is/a/test/', '/output/');
+ $route1 = $router->get('/this/is/a/test/', ['controller' => 'test']);
$this->assertEquals(true, $route1->test('/this/is/a/test', 'GET', Route::PROTO_HTTP, $router->server()), 'The route should match a route without trailing slash');
$this->assertEquals(true, $route1->test('/this/is/a/test/', 'GET', Route::PROTO_HTTP, $router->server()), 'The route should match a route with a trailing slash');
+ $this->assertEquals(false, $route1->test('/this/is/a/test/with/more', 'GET', Route::PROTO_HTTP, $router->server()), 'The route shouldnot match excessive content');
- $this->assertEquals( '/output/', $route1->rewrite('/this/is/a/test/', 'GET', Route::PROTO_HTTP, $router->server()), 'The route should match a route with a trailing slash');
- $this->assertNotEquals('/output/', $route1->rewrite('/this/is/a/test/with/extra', 'GET', Route::PROTO_HTTP, $router->server()), 'The route should not match additional pieces');
+ $this->assertInstanceOf(Path::class, $route1->rewrite('/this/is/a/test/', 'GET', Route::PROTO_HTTP, new Parameters), 'The route should match a route with a trailing slash');
+
+ $this->expectException(RouteMismatchException::class, 'The route should not match additional pieces');
+ $route1->rewrite('/this/is/a/test/with/extra', 'GET', Route::PROTO_HTTP, new Parameters);
+ }
+
+ public function testTrailingSlashStringRoute2() {
+ $router = $this->router;
#Create a route without a trailing slash
- $route2 = $router->get('/this/is/a/test', '/output/');
+ $route2 = $router->get('/this/is/a/test', ['controller' => 'test']);
$this->assertEquals(true, $route2->test('/this/is/a/test/with/more/fragments', 'GET', Route::PROTO_HTTP, $router->server()), 'The route shoud match a route with additional fragments');
$this->assertEquals(true, $route2->test('/this/is/a/test/', 'GET', Route::PROTO_HTTP, $router->server()), 'The route shoud match a route with a trailing slash');
- $this->assertEquals('/output/', $route2->rewrite('/this/is/a/test/', 'GET', Route::PROTO_HTTP, $router->server()), 'The route should rewrite a string without additional frgaments fine');
- $this->assertEquals(false, $route2->rewrite('/this/is/a/test/with/strings', 'GET', Route::PROTO_HTTP, $router->server()), 'The route should remove additional fragments.');
-
- #Create a route without a trailing slash with a target without trailing slash
- #This addresses a bug found on 16/11/2014
- $route3 = $router->get('/this/is/a/test', '/output');
- $this->assertEquals(true, $route3->test('/this/is/a/test/with/more/fragments', 'GET', Route::PROTO_HTTP, $router->server()), 'The route shoud match a route with additional fragments');
- $this->assertEquals(true, $route3->test('/this/is/a/test/', 'GET', Route::PROTO_HTTP, $router->server()), 'The route shoud match a route with a trailing slash');
- $this->assertEquals('/output/', $route3->rewrite('/this/is/a/test/', 'GET', Route::PROTO_HTTP, $router->server()), 'The route should rewrite a string without additional frgaments fine');
- $this->assertEquals('/output/with/strings/', $route3->rewrite('/this/is/a/test/with/strings', 'GET', Route::PROTO_HTTP, $router->server()), 'The route should rewrite a string with additional fragments fine.');
}
public function testArrayRoute() {
diff --git a/url.php b/url.php
--- a/url.php
+++ b/url.php
@@ -43,7 +43,7 @@
$get = array_shift($params);
$environment = array_shift($params);
- parent::__construct($app, $controller, $action, $object, 'php', $get, $environment);
+ parent::__construct($controller, $action, $object, 'php', $get, $environment);
}
}

File Metadata

Mime Type
text/plain
Expires
Apr 12 2021, 4:32 PM (9 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5535
Default Alt Text
D526.id1681.diff (27 KB)

Event Timeline