Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
d0e0095b
Commit
d0e0095b
authored
May 14, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename requireSecure to requireHttps and add requireHttp
parent
a2259f1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
src/Silex/Controller.php
src/Silex/Controller.php
+11
-1
tests/Silex/Tests/Extension/UrlGeneratorExtensionTest.php
tests/Silex/Tests/Extension/UrlGeneratorExtensionTest.php
+22
-5
No files found.
src/Silex/Controller.php
View file @
d0e0095b
...
@@ -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
require
Secure
()
public
function
require
Https
()
{
{
$this
->
route
->
setRequirement
(
'_scheme'
,
'https'
);
$this
->
route
->
setRequirement
(
'_scheme'
,
'https'
);
...
...
tests/Silex/Tests/Extension/UrlGeneratorExtensionTest.php
View file @
d0e0095b
...
@@ -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
'
)
->
require
Secure
();
->
require
Https
();
$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
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment