Commit d0e0095b authored by Igor Wiedler's avatar Igor Wiedler

rename requireSecure to requireHttps and add requireHttp

parent a2259f1d
...@@ -95,10 +95,20 @@ class Controller ...@@ -95,10 +95,20 @@ class Controller
return $this; return $this;
} }
/**
* Sets the requirement of HTTP (no HTTPS) on this controller.
*/
public function requireHttp()
{
$this->route->setRequirement('_scheme', 'http');
return $this;
}
/** /**
* Sets the requirement of HTTPS on this controller. * Sets the requirement of HTTPS on this controller.
*/ */
public function requireSecure() public function requireHttps()
{ {
$this->route->setRequirement('_scheme', 'https'); $this->route->setRequirement('_scheme', 'https');
......
...@@ -70,20 +70,37 @@ class UrlGeneratorExtensionTest extends \PHPUnit_Framework_TestCase ...@@ -70,20 +70,37 @@ class UrlGeneratorExtensionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('https://localhost:81/hello/john', $url); $this->assertEquals('https://localhost:81/hello/john', $url);
} }
public function testUrlGenerationWithHttp()
{
$app = new Application();
$app->register(new UrlGeneratorExtension());
$app->get('/insecure', function () {})
->bind('insecure_page')
->requireHttp();
$app['request'] = Request::create('https://localhost/');
$app['request_context'] = $app['request_context.factory']->create($app['request']);
$url = $app['url_generator']->generate('insecure_page');
$this->assertEquals('http://localhost/insecure', $url);
}
public function testUrlGenerationWithHttps() public function testUrlGenerationWithHttps()
{ {
$app = new Application(); $app = new Application();
$app->register(new UrlGeneratorExtension()); $app->register(new UrlGeneratorExtension());
$app->get('/hello/{name}', function ($name) {}) $app->get('/secure', function () {})
->bind('hello') ->bind('secure_page')
->requireSecure(); ->requireHttps();
$app['request'] = Request::create('http://localhost/'); $app['request'] = Request::create('http://localhost/');
$app['request_context'] = $app['request_context.factory']->create($app['request']); $app['request_context'] = $app['request_context.factory']->create($app['request']);
$url = $app['url_generator']->generate('hello', array('name' => 'john')); $url = $app['url_generator']->generate('secure_page');
$this->assertEquals('https://localhost/hello/john', $url); $this->assertEquals('https://localhost/secure', $url);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment