diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
index dafd4c46bb..8bcbe06ae6 100644
--- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
@@ -53,6 +53,8 @@ CHANGELOG
`EventDispatcherDebugCommand`, `RouterDebugCommand`, `RouterMatchCommand`,
`TranslationDebugCommand`, `TranslationUpdateCommand`, `XliffLintCommand`
and `YamlLintCommand` classes have been marked as final
+ * Added `asset.request_context.base_path` and `asset.request_context.secure` parameters
+ to provide a default request context in case the stack is empty (similar to `router.request_context.*` parameters)
3.3.0
-----
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml
index e714e2834c..cb0f11c926 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml
@@ -4,6 +4,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+
+
+ false
+
+
@@ -19,6 +24,8 @@
+ %asset.request_context.base_path%
+ %asset.request_context.secure%
diff --git a/src/Symfony/Component/Asset/CHANGELOG.md b/src/Symfony/Component/Asset/CHANGELOG.md
index 72030a9d65..bb4c02f333 100644
--- a/src/Symfony/Component/Asset/CHANGELOG.md
+++ b/src/Symfony/Component/Asset/CHANGELOG.md
@@ -1,6 +1,12 @@
CHANGELOG
=========
+3.4.0
+-----
+
+ * added optional arguments `$basePath` and `$secure` in `RequestStackContext::__construct()`
+ to provide a default request context in case the stack is empty
+
3.3.0
-----
* Added `JsonManifestVersionStrategy` as a way to read final,
diff --git a/src/Symfony/Component/Asset/Context/RequestStackContext.php b/src/Symfony/Component/Asset/Context/RequestStackContext.php
index ba7113851d..c18f833264 100644
--- a/src/Symfony/Component/Asset/Context/RequestStackContext.php
+++ b/src/Symfony/Component/Asset/Context/RequestStackContext.php
@@ -21,10 +21,19 @@ use Symfony\Component\HttpFoundation\RequestStack;
class RequestStackContext implements ContextInterface
{
private $requestStack;
+ private $basePath;
+ private $secure;
- public function __construct(RequestStack $requestStack)
+ /**
+ * @param RequestStack $requestStack
+ * @param string $basePath
+ * @param bool $secure
+ */
+ public function __construct(RequestStack $requestStack, $basePath = '', $secure = false)
{
$this->requestStack = $requestStack;
+ $this->basePath = $basePath;
+ $this->secure = $secure;
}
/**
@@ -33,7 +42,7 @@ class RequestStackContext implements ContextInterface
public function getBasePath()
{
if (!$request = $this->requestStack->getMasterRequest()) {
- return '';
+ return $this->basePath;
}
return $request->getBasePath();
@@ -45,7 +54,7 @@ class RequestStackContext implements ContextInterface
public function isSecure()
{
if (!$request = $this->requestStack->getMasterRequest()) {
- return false;
+ return $this->secure;
}
return $request->isSecure();
diff --git a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php
index 7269d0e6bc..7f24534eba 100644
--- a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php
+++ b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php
@@ -61,4 +61,13 @@ class RequestStackContextTest extends TestCase
$this->assertTrue($requestStackContext->isSecure());
}
+
+ public function testDefaultContext()
+ {
+ $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
+ $requestStackContext = new RequestStackContext($requestStack, 'default-path', true);
+
+ $this->assertSame('default-path', $requestStackContext->getBasePath());
+ $this->assertTrue($requestStackContext->isSecure());
+ }
}