Skip to content

Commit 3611a87

Browse files
committed
Add doc for strict JsonManifest strategy
1 parent bcc56c9 commit 3611a87

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

components/asset.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,31 @@ In those cases, use the
160160
use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy;
161161

162162
// assumes the JSON file above is called "rev-manifest.json"
163-
$package = new Package(new JsonManifestVersionStrategy(__DIR__.'/rev-manifest.json'));
163+
$package = new Package(new JsonManifestVersionStrategy(__DIR__.'/rev-manifest.json'), $strict);
164164

165165
echo $package->getUrl('css/app.css');
166166
// result: build/css/app.b916426ea1d10021f3f17ce8031f93c2.css
167167

168+
If you request an asset that is *not found* in the ``manifest.json`` file, the original -
169+
*unmodified* - asset path will be returned.
170+
The ``$strict`` argument helps for debugging as it throws an exception when the asset is
171+
not listed in the manifest::
172+
173+
use Symfony\Component\Asset\Package;
174+
use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy;
175+
176+
// The value of $strict can be specific per environment "true" for debugging and "false" for stability.
177+
$strict = true;
178+
// assumes the JSON file above is called "rev-manifest.json"
179+
$package = new Package(new JsonManifestVersionStrategy(__DIR__.'/rev-manifest.json'), $strict);
180+
181+
echo $package->getUrl('not-found.css');
182+
// error:
183+
184+
.. versionadded:: 5.2
185+
186+
Option ``strict`` was introduced in Symfony 5.2.
187+
168188
If your JSON file is not on your local filesystem but is accessible over HTTP,
169189
use the :class:`Symfony\\Component\\Asset\\VersionStrategy\\RemoteJsonManifestVersionStrategy`
170190
with the :doc:`HttpClient component </http_client>`::

reference/configuration/framework.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Configuration
4141
* `base_urls`_
4242
* `json_manifest_path`_
4343
* `packages`_
44+
* `strict`_
4445
* `version_format`_
4546
* `version_strategy`_
4647
* `version`_
@@ -1842,6 +1843,7 @@ Each package can configure the following options:
18421843
* :ref:`version <reference-framework-assets-version>`
18431844
* :ref:`version_format <reference-assets-version-format>`
18441845
* :ref:`json_manifest_path <reference-assets-json-manifest-path>`
1846+
* :ref:`strict <reference-assets-strict>`
18451847

18461848
.. _reference-framework-assets-version:
18471849
.. _ref-framework-assets-version:
@@ -2084,6 +2086,8 @@ package:
20842086
foo_package:
20852087
# this package uses its own manifest (the default file is ignored)
20862088
json_manifest_path: "%kernel.project_dir%/public/build/a_different_manifest.json"
2089+
# for debug, an exception is thrown when an asset is not found in the manifest
2090+
strict: "%kernel.debug%"
20872091
bar_package:
20882092
# this package uses the global manifest (the default file is used)
20892093
base_path: '/images'
@@ -2104,9 +2108,11 @@ package:
21042108
<!-- you can use absolute URLs too and Symfony will download them automatically -->
21052109
<!-- <framework:assets json-manifest-path="https://cdn.example.com/manifest.json"> -->
21062110
<!-- this package uses its own manifest (the default file is ignored) -->
2111+
<!-- for debug, an exception is thrown when an asset is not found in the manifest -->
21072112
<framework:package
21082113
name="foo_package"
2109-
json-manifest-path="%kernel.project_dir%/public/build/a_different_manifest.json"/>
2114+
json-manifest-path="%kernel.project_dir%/public/build/a_different_manifest.json"
2115+
strict="true"/>
21102116
<!-- this package uses the global manifest (the default file is used) -->
21112117
<framework:package
21122118
name="bar_package"
@@ -2128,6 +2134,8 @@ package:
21282134
'foo_package' => [
21292135
// this package uses its own manifest (the default file is ignored)
21302136
'json_manifest_path' => '%kernel.project_dir%/public/build/a_different_manifest.json',
2137+
// for debug, an exception is thrown when an asset is not found in the manifest
2138+
'strict' => '%kernel.debug%',
21312139
],
21322140
'bar_package' => [
21332141
// this package uses the global manifest (the default file is used)
@@ -2152,11 +2160,21 @@ package:
21522160

21532161
If you request an asset that is *not found* in the ``manifest.json`` file, the original -
21542162
*unmodified* - asset path will be returned.
2163+
Set `strict` to `true` to get an exception when an asset is *not found*.
21552164

21562165
.. note::
21572166

21582167
If an URL is set, the JSON manifest is downloaded on each request using the `http_client`_.
21592168

2169+
strict
2170+
......
2171+
2172+
**type**: ``boolean`` **default**: ``false``
2173+
2174+
.. versionadded:: 5.2
2175+
2176+
This option was introduced in Symfony 5.2.
2177+
21602178
translator
21612179
~~~~~~~~~~
21622180

0 commit comments

Comments
 (0)