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
09968780
Commit
09968780
authored
May 14, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert the addition of RequestContextFactory
parent
d0e0095b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
70 deletions
+41
-70
doc/services.rst
doc/services.rst
+0
-3
src/Silex/Application.php
src/Silex/Application.php
+9
-5
src/Silex/RequestContextFactory.php
src/Silex/RequestContextFactory.php
+0
-44
tests/Silex/Tests/Extension/UrlGeneratorExtensionTest.php
tests/Silex/Tests/Extension/UrlGeneratorExtensionTest.php
+32
-18
No files found.
doc/services.rst
View file @
09968780
...
...
@@ -237,9 +237,6 @@ of them.
* **request_context**: The request context is a simplified representation
of the request that is used by the Router and the UrlGenerator.
* **request_context.factory**: Is used internally to create a RequestContext
from a Request.
.. note::
All of these Silex core services are shared.
...
...
src/Silex/Application.php
View file @
09968780
...
...
@@ -27,6 +27,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
use
Symfony\Component\Routing\Route
;
use
Symfony\Component\Routing\RouteCollection
;
use
Symfony\Component\Routing\RequestContext
;
use
Symfony\Component\Routing\Matcher\Exception\Exception
as
MatcherException
;
use
Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException
;
use
Symfony\Component\Routing\Matcher\Exception\NotFoundException
;
...
...
@@ -80,10 +81,6 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return
new
HttpKernel
(
$app
[
'dispatcher'
],
$app
[
'resolver'
]);
});
$this
[
'request_context.factory'
]
=
$this
->
share
(
function
()
{
return
new
RequestContextFactory
();
});
$this
[
'request.http_port'
]
=
80
;
$this
[
'request.https_port'
]
=
443
;
}
...
...
@@ -319,7 +316,14 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
{
$this
[
'request'
]
=
$event
->
getRequest
();
$this
[
'request_context'
]
=
$this
[
'request_context.factory'
]
->
create
(
$this
[
'request'
],
$this
[
'request.http_port'
],
$this
[
'request.https_port'
]);
$this
[
'request_context'
]
=
new
RequestContext
(
$this
[
'request'
]
->
getBaseUrl
(),
$this
[
'request'
]
->
getMethod
(),
$this
[
'request'
]
->
getHost
(),
$this
[
'request'
]
->
getScheme
(),
!
$this
[
'request'
]
->
isSecure
()
?
$this
[
'request'
]
->
getPort
()
:
$this
[
'request.http_port'
],
$this
[
'request'
]
->
isSecure
()
?
$this
[
'request'
]
->
getPort
()
:
$this
[
'request.https_port'
]
);
$this
[
'controllers'
]
->
flush
();
...
...
src/Silex/RequestContextFactory.php
deleted
100644 → 0
View file @
d0e0095b
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Silex
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\Routing\RequestContext
;
/**
* Creates a RequestContext from a Request.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class
RequestContextFactory
{
/**
* Creates the RequestContext instance.
*
* @param Request $request The input Request
* @param int $defaultHttpPort The default port for HTTP
* @param int $defaultHttpsPort The default port for HTTPS
*
* @return RequestContext the RequestContext
*/
public
function
create
(
Request
$request
,
$defaultHttpPort
=
80
,
$defaultHttpsPort
=
443
)
{
return
new
RequestContext
(
$request
->
getBaseUrl
(),
$request
->
getMethod
(),
$request
->
getHost
(),
$request
->
getScheme
(),
!
$request
->
isSecure
()
?
$request
->
getPort
()
:
$defaultHttpPort
,
$request
->
isSecure
()
?
$request
->
getPort
()
:
$defaultHttpsPort
);
}
}
tests/Silex/Tests/Extension/UrlGeneratorExtensionTest.php
View file @
09968780
...
...
@@ -32,8 +32,10 @@ class UrlGeneratorExtensionTest extends \PHPUnit_Framework_TestCase
$app
->
get
(
'/hello/{name}'
,
function
(
$name
)
{})
->
bind
(
'hello'
);
$app
[
'request'
]
=
Request
::
create
(
'/'
);
$app
[
'request_context'
]
=
$app
[
'request_context.factory'
]
->
create
(
$app
[
'request'
]);
$app
->
get
(
'/'
,
function
()
{});
$request
=
Request
::
create
(
'/'
);
$app
->
handle
(
$request
);
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\Generator\UrlGenerator'
,
$app
[
'url_generator'
]);
}
...
...
@@ -47,11 +49,14 @@ class UrlGeneratorExtensionTest extends \PHPUnit_Framework_TestCase
$app
->
get
(
'/hello/{name}'
,
function
(
$name
)
{})
->
bind
(
'hello'
);
$app
[
'request'
]
=
Request
::
create
(
'/'
);
$app
[
'request_context'
]
=
$app
[
'request_context.factory'
]
->
create
(
$app
[
'request'
]);
$app
->
get
(
'/'
,
function
()
use
(
$app
)
{
return
$app
[
'url_generator'
]
->
generate
(
'hello'
,
array
(
'name'
=>
'john'
));
});
$request
=
Request
::
create
(
'/'
);
$response
=
$app
->
handle
(
$request
);
$url
=
$app
[
'url_generator'
]
->
generate
(
'hello'
,
array
(
'name'
=>
'john'
));
$this
->
assertEquals
(
'/hello/john'
,
$url
);
$this
->
assertEquals
(
'/hello/john'
,
$response
->
getContent
());
}
public
function
testAbsoluteUrlGeneration
()
...
...
@@ -63,11 +68,14 @@ class UrlGeneratorExtensionTest extends \PHPUnit_Framework_TestCase
$app
->
get
(
'/hello/{name}'
,
function
(
$name
)
{})
->
bind
(
'hello'
);
$app
[
'request'
]
=
Request
::
create
(
'https://localhost:81/'
);
$app
[
'request_context'
]
=
$app
[
'request_context.factory'
]
->
create
(
$app
[
'request'
]);
$app
->
get
(
'/'
,
function
()
use
(
$app
)
{
return
$app
[
'url_generator'
]
->
generate
(
'hello'
,
array
(
'name'
=>
'john'
),
true
);
});
$request
=
Request
::
create
(
'https://localhost:81/'
);
$response
=
$app
->
handle
(
$request
);
$url
=
$app
[
'url_generator'
]
->
generate
(
'hello'
,
array
(
'name'
=>
'john'
),
true
);
$this
->
assertEquals
(
'https://localhost:81/hello/john'
,
$url
);
$this
->
assertEquals
(
'https://localhost:81/hello/john'
,
$response
->
getContent
());
}
public
function
testUrlGenerationWithHttp
()
...
...
@@ -80,11 +88,14 @@ class UrlGeneratorExtensionTest extends \PHPUnit_Framework_TestCase
->
bind
(
'insecure_page'
)
->
requireHttp
();
$app
[
'request'
]
=
Request
::
create
(
'https://localhost/'
);
$app
[
'request_context'
]
=
$app
[
'request_context.factory'
]
->
create
(
$app
[
'request'
]);
$app
->
get
(
'/'
,
function
()
use
(
$app
)
{
return
$app
[
'url_generator'
]
->
generate
(
'insecure_page'
);
});
$url
=
$app
[
'url_generator'
]
->
generate
(
'insecure_page'
);
$this
->
assertEquals
(
'http://localhost/insecure'
,
$url
);
$request
=
Request
::
create
(
'https://localhost/'
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertEquals
(
'http://localhost/insecure'
,
$response
->
getContent
());
}
public
function
testUrlGenerationWithHttps
()
...
...
@@ -97,10 +108,13 @@ class UrlGeneratorExtensionTest extends \PHPUnit_Framework_TestCase
->
bind
(
'secure_page'
)
->
requireHttps
();
$app
[
'request'
]
=
Request
::
create
(
'http://localhost/'
);
$app
[
'request_context'
]
=
$app
[
'request_context.factory'
]
->
create
(
$app
[
'request'
]);
$app
->
get
(
'/'
,
function
()
use
(
$app
)
{
return
$app
[
'url_generator'
]
->
generate
(
'secure_page'
);
});
$request
=
Request
::
create
(
'http://localhost/'
);
$response
=
$app
->
handle
(
$request
);
$url
=
$app
[
'url_generator'
]
->
generate
(
'secure_page'
);
$this
->
assertEquals
(
'https://localhost/secure'
,
$url
);
$this
->
assertEquals
(
'https://localhost/secure'
,
$response
->
getContent
());
}
}
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