Skip to content

Commit

Permalink
Router::$defaultFlags and flag SECURED are deprecated [Closes nette/r…
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 19, 2016
1 parent a1ed037 commit 12d577b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Application/IRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IRouter
/** only matching route */
const ONE_WAY = 0b0001;

/** HTTPS route */
/** @deprecated */
const SECURED = 0b0010;

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Route implements Application\IRouter
PATH_OPTIONAL = 1,
CONSTANT = 2;

/** @var int */
/** @deprecated */
public static $defaultFlags = 0;

/** @var array */
Expand Down Expand Up @@ -132,6 +132,11 @@ public function __construct($mask, $metadata = [], $flags = 0)
];
}

if (static::$defaultFlags) {
trigger_error('Route::$defaultFlags is deprecated, router by default keeps the used protocol.', E_USER_DEPRECATED);
} elseif ($flags & self::SECURED) {
trigger_error('IRouter::SECURED is deprecated, router by default keeps the used protocol.', E_USER_DEPRECATED);
}
$this->flags = $flags | static::$defaultFlags;
$this->setMask($mask, $metadata);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Application/Routers/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function __construct($defaults = [], $flags = 0)

$this->defaults = $defaults;
$this->flags = $flags;
if ($flags & self::SECURED) {
trigger_error('IRouter::SECURED is deprecated, router by default keeps the used protocol.', E_USER_DEPRECATED);
}
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Routers/Route.secured.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php';
require __DIR__ . '/Route.php';


$route = new Route('<param>', [
$route = @new Route('<param>', [ // @ SECURED is deprecated
'presenter' => 'Presenter',
], Route::SECURED);

Expand Down
2 changes: 1 addition & 1 deletion tests/Routers/SimpleRouter.secured.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


$router = new Application\Routers\SimpleRouter([
$router = @new Application\Routers\SimpleRouter([ // @ SECURED is deprecated
'id' => 12,
'any' => 'anyvalue',
], Application\Routers\SimpleRouter::SECURED);
Expand Down

2 comments on commit 12d577b

@JanTvrdik
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

But AFAIK this currently makes it impossible to have one Nette application which handles requests from 2 different domains – one with HTTP and one with HTTPS – because you cannot specify protocol in mask.

copy protocol when route mask doesn't contain domain or when generated domain is the same as current domain (+subdomain).

@dg
Copy link
Member Author

@dg dg commented on 12d577b May 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right.

Please sign in to comment.