Compare commits

...

7 Commits

Author SHA1 Message Date
Simon Sessingø ac594ebde2 Merge pull request #427 from skipperbent/v4-development
Version 4.2.0.5
2018-08-31 01:41:36 +02:00
Simon Sessingø 064154f27f Merge pull request #426 from skipperbent/v4-optimisations
Optimizations
2018-08-31 01:41:05 +02:00
Simon Sessingø 0ac7fd559a Optimizations
- Settings parameter in group method are no longer optional.
- Updated README to contain PHP JSON-extension under requirements.
- Updated composer.json to include php json extension.
2018-08-31 01:40:21 +02:00
Simon Sessingø 57c9da2c42 Merge pull request #423 from skipperbent/v4-development
Version 4.2.0.4
2018-08-24 17:24:25 +02:00
Simon Sessingø 6bdfe06223 Merge pull request #422 from skipperbent/v4-optional-character-fix
Fix for issue #421: Incorrectly optional character in route
2018-08-24 17:23:43 +02:00
Simon Sessingø 5c2a973214 Merge branch 'v4-development' into v4-optional-character-fix 2018-08-24 17:23:33 +02:00
Simon Sessingø a7cbacbde7 Fix for issue #421: Incorrectly optional character in route 2018-08-24 17:16:02 +02:00
7 changed files with 406 additions and 368 deletions
+371 -349
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -144,6 +144,7 @@ You can find the demo-project here: [https://github.com/skipperbent/simple-route
## Requirements
- PHP 7.1 or greater (version 3.x and below supports PHP 5.5+)
- PHP JSON extension enabled.
## Features
+1
View File
@@ -28,6 +28,7 @@
],
"require": {
"php": ">=7.1",
"ext-json": "*",
"php-di/php-di": "^6.0"
},
"require-dev": {
@@ -63,7 +63,7 @@ class CookieTokenProvider implements ITokenProvider
public function setToken(string $token): void
{
$this->token = $token;
setcookie(static::CSRF_KEY, $token, (int)((time() + 60) * $this->cookieTimeoutMinutes), '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
setcookie(static::CSRF_KEY, $token, (time() + 60) * $this->cookieTimeoutMinutes, '/', ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
}
/**
+4 -8
View File
@@ -151,17 +151,13 @@ abstract class Route implements IRoute
/* If custom regex is defined, use that */
if (isset($this->where[$name]) === true) {
$regex = $this->where[$name];
} else if ($parameterRegex !== null) {
$regex = $parameterRegex;
} else {
/* If method specific regex is defined use that, otherwise use the default parameter regex */
if ($parameterRegex !== null) {
$regex = $parameterRegex;
} else {
$regex = $this->defaultParameterRegex ?? static::PARAMETERS_DEFAULT_REGEX;
}
$regex = $this->defaultParameterRegex ?? static::PARAMETERS_DEFAULT_REGEX;
}
$regex = sprintf('(?:\/|\-)%1$s(?P<%2$s>%3$s)%1$s', $parameters[2][$key], $name, $regex);
$regex = sprintf('((\/|\-)(?P<%2$s>%3$s))%1$s', $parameters[2][$key], $name, $regex);
}
$urlRegex .= preg_quote($t, '/') . $regex;
+1 -1
View File
@@ -261,7 +261,7 @@ class SimpleRouter
* @return RouteGroup
* @throws InvalidArgumentException
*/
public static function group(array $settings = [], \Closure $callback): IGroupRoute
public static function group(array $settings, \Closure $callback): IGroupRoute
{
if (\is_callable($callback) === false) {
throw new InvalidArgumentException('Invalid callback provided. Only functions or methods supported');
+27 -9
View File
@@ -6,10 +6,28 @@ require_once 'Dummy/Exception/ExceptionHandlerException.php';
class RouterRouteTest extends \PHPUnit\Framework\TestCase
{
/**
* Issue #421: Incorrectly optional character in route
*
* @throws Exception
*/
public function testOptionalCharacterRoute()
{
$result = false;
TestRouter::get('/api/v1/users/{userid}/projects/{id}/pages/{pageid?}', function () use (&$result) {
$result = true;
});
TestRouter::debug('/api/v1/users/1/projects/8399421535/pages/43/', 'get');
$this->assertTrue($result);
}
public function testMultiParam()
{
$result = false;
TestRouter::get('/test-{param1}-{param2}', function ($param1, $param2) use(&$result) {
TestRouter::get('/test-{param1}-{param2}', function ($param1, $param2) use (&$result) {
if ($param1 === 'param1' && $param2 === 'param2') {
$result = true;
@@ -94,13 +112,12 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
$result = false;
TestRouter::request()->setHost('hello.world.com');
TestRouter::group(['domain' => '{subdomain}.world.com'], function () use(&$result) {
TestRouter::get('/test', function ($subdomain = null) use(&$result) {
TestRouter::group(['domain' => '{subdomain}.world.com'], function () use (&$result) {
TestRouter::get('/test', function ($subdomain = null) use (&$result) {
$result = ($subdomain === 'hello');
});
});
TestRouter::debug('/test', 'get');
$this->assertTrue($result);
@@ -113,8 +130,8 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
$result = false;
TestRouter::group(['domain' => '{subdomain}.world.com'], function () use(&$result) {
TestRouter::get('/test', function ($subdomain = null) use(&$result) {
TestRouter::group(['domain' => '{subdomain}.world.com'], function () use (&$result) {
TestRouter::get('/test', function ($subdomain = null) use (&$result) {
$result = ($subdomain === 'hello');
});
});
@@ -133,11 +150,12 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
$this->assertTrue(true);
}
public function testParameterDefaultValue() {
public function testParameterDefaultValue()
{
$defaultVariable = null;
TestRouter::get('/my/{path?}', function($path = 'working') use(&$defaultVariable) {
TestRouter::get('/my/{path?}', function ($path = 'working') use (&$defaultVariable) {
$defaultVariable = $path;
});
@@ -157,7 +175,7 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
public function testDefaultParameterRegexGroup()
{
TestRouter::group(['defaultParameterRegex' => '[\w\-]+'], function() {
TestRouter::group(['defaultParameterRegex' => '[\w\-]+'], function () {
TestRouter::get('/my/{path}', 'DummyController@param');
});