Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c7f664c

Browse filesBrowse files
committed
feature #21027 [Asset] Provide default context (ro0NL)
This PR was squashed before being merged into the 3.4 branch (closes #21027). Discussion ---------- [Asset] Provide default context | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19396 | License | MIT | Doc PR | should be noted somewhere, ill create an issue Allows configuring the default asset context to make things works on CLI for example. Same approach as the routing component. Introduces ```yaml # parameters.yml asset.request_context.base_path: '/base/path' asset.request_context.secure: false ``` Commits ------- 9137d57 [Asset] Provide default context
2 parents 648a895 + 9137d57 commit c7f664c
Copy full SHA for c7f664c

File tree

5 files changed

+36
-3
lines changed
Filter options

5 files changed

+36
-3
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ CHANGELOG
5454
`EventDispatcherDebugCommand`, `RouterDebugCommand`, `RouterMatchCommand`,
5555
`TranslationDebugCommand`, `TranslationUpdateCommand`, `XliffLintCommand`
5656
and `YamlLintCommand` classes have been marked as final
57+
* Added `asset.request_context.base_path` and `asset.request_context.secure` parameters
58+
to provide a default request context in case the stack is empty (similar to `router.request_context.*` parameters)
5759

5860
3.3.0
5961
-----

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

7+
<parameters>
8+
<parameter key="asset.request_context.base_path"></parameter>
9+
<parameter key="asset.request_context.secure">false</parameter>
10+
</parameters>
11+
712
<services>
813
<defaults public="false" />
914

@@ -19,6 +24,8 @@
1924

2025
<service id="assets.context" class="Symfony\Component\Asset\Context\RequestStackContext">
2126
<argument type="service" id="request_stack" />
27+
<argument>%asset.request_context.base_path%</argument>
28+
<argument>%asset.request_context.secure%</argument>
2229
</service>
2330

2431
<service id="assets.path_package" class="Symfony\Component\Asset\PathPackage" abstract="true">

‎src/Symfony/Component/Asset/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Asset/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
3.4.0
5+
-----
6+
7+
* added optional arguments `$basePath` and `$secure` in `RequestStackContext::__construct()`
8+
to provide a default request context in case the stack is empty
9+
410
3.3.0
511
-----
612
* Added `JsonManifestVersionStrategy` as a way to read final,

‎src/Symfony/Component/Asset/Context/RequestStackContext.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Asset/Context/RequestStackContext.php
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@
2121
class RequestStackContext implements ContextInterface
2222
{
2323
private $requestStack;
24+
private $basePath;
25+
private $secure;
2426

25-
public function __construct(RequestStack $requestStack)
27+
/**
28+
* @param RequestStack $requestStack
29+
* @param string $basePath
30+
* @param bool $secure
31+
*/
32+
public function __construct(RequestStack $requestStack, $basePath = '', $secure = false)
2633
{
2734
$this->requestStack = $requestStack;
35+
$this->basePath = $basePath;
36+
$this->secure = $secure;
2837
}
2938

3039
/**
@@ -33,7 +42,7 @@ public function __construct(RequestStack $requestStack)
3342
public function getBasePath()
3443
{
3544
if (!$request = $this->requestStack->getMasterRequest()) {
36-
return '';
45+
return $this->basePath;
3746
}
3847

3948
return $request->getBasePath();
@@ -45,7 +54,7 @@ public function getBasePath()
4554
public function isSecure()
4655
{
4756
if (!$request = $this->requestStack->getMasterRequest()) {
48-
return false;
57+
return $this->secure;
4958
}
5059

5160
return $request->isSecure();

‎src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,13 @@ public function testIsSecureTrue()
6161

6262
$this->assertTrue($requestStackContext->isSecure());
6363
}
64+
65+
public function testDefaultContext()
66+
{
67+
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
68+
$requestStackContext = new RequestStackContext($requestStack, 'default-path', true);
69+
70+
$this->assertSame('default-path', $requestStackContext->getBasePath());
71+
$this->assertTrue($requestStackContext->isSecure());
72+
}
6473
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.