Skip to content

Navigation Menu

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 dfdb6eb

Browse filesBrowse files
committed
Add doc for strict JsonManifest strategy
1 parent 14ff17d commit dfdb6eb
Copy full SHA for dfdb6eb

File tree

2 files changed

+41
-1
lines changed
Filter options

2 files changed

+41
-1
lines changed

‎components/asset.rst

Copy file name to clipboardExpand all lines: components/asset.rst
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ In those cases, use the
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 ``rev-manifest.json`` file, the original -
169+
*unmodified* - asset path will be returned.
170+
The ``$strictMode`` 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 $strictMode can be specific per environment "true" for debugging and "false" for stability.
177+
$strictMode = true;
178+
// assumes the JSON file above is called "rev-manifest.json"
179+
$package = new Package(new JsonManifestVersionStrategy(__DIR__.'/rev-manifest.json', null, $strictMode));
180+
181+
echo $package->getUrl('not-found.css');
182+
// error:
183+
184+
.. versionadded:: 5.3
185+
186+
The ``$strictMode`` option was introduced in Symfony 5.3.
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

Copy file name to clipboardExpand all lines: reference/configuration/framework.rst
+21-1Lines changed: 21 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_mode`_
4445
* `version_format`_
4546
* `version_strategy`_
4647
* `version`_
@@ -1933,6 +1934,7 @@ Each package can configure the following options:
19331934
* :ref:`version <reference-framework-assets-version>`
19341935
* :ref:`version_format <reference-assets-version-format>`
19351936
* :ref:`json_manifest_path <reference-assets-json-manifest-path>`
1937+
* :ref:`strict_mode <reference-assets-strict-mode>`
19361938

19371939
.. _reference-framework-assets-version:
19381940
.. _ref-framework-assets-version:
@@ -2175,6 +2177,8 @@ package:
21752177
foo_package:
21762178
# this package uses its own manifest (the default file is ignored)
21772179
json_manifest_path: "%kernel.project_dir%/public/build/a_different_manifest.json"
2180+
# for debug, an exception is thrown when an asset is not found in the manifest
2181+
strict_mode: "%kernel.debug%"
21782182
bar_package:
21792183
# this package uses the global manifest (the default file is used)
21802184
base_path: '/images'
@@ -2195,9 +2199,11 @@ package:
21952199
<!-- you can use absolute URLs too and Symfony will download them automatically -->
21962200
<!-- <framework:assets json-manifest-path="https://cdn.example.com/manifest.json"> -->
21972201
<!-- this package uses its own manifest (the default file is ignored) -->
2202+
<!-- for debug, an exception is thrown when an asset is not found in the manifest -->
21982203
<framework:package
21992204
name="foo_package"
2200-
json-manifest-path="%kernel.project_dir%/public/build/a_different_manifest.json"/>
2205+
json-manifest-path="%kernel.project_dir%/public/build/a_different_manifest.json"
2206+
strict-mode="true"/>
22012207
<!-- this package uses the global manifest (the default file is used) -->
22022208
<framework:package
22032209
name="bar_package"
@@ -2219,6 +2225,8 @@ package:
22192225
'foo_package' => [
22202226
// this package uses its own manifest (the default file is ignored)
22212227
'json_manifest_path' => '%kernel.project_dir%/public/build/a_different_manifest.json',
2228+
// for debug, an exception is thrown when an asset is not found in the manifest
2229+
'strict_mode' => '%kernel.debug%',
22222230
],
22232231
'bar_package' => [
22242232
// this package uses the global manifest (the default file is used)
@@ -2243,11 +2251,23 @@ package:
22432251

22442252
If you request an asset that is *not found* in the ``manifest.json`` file, the original -
22452253
*unmodified* - asset path will be returned.
2254+
Set `strict_mode` to `true` to get an exception when an asset is *not found*.
22462255

22472256
.. note::
22482257

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

2260+
.. _reference-assets-strict-mode:
2261+
2262+
strict_mode
2263+
...........
2264+
2265+
**type**: ``boolean`` **default**: ``false``
2266+
2267+
.. versionadded:: 5.3
2268+
2269+
This option was introduced in Symfony 5.3.
2270+
22512271
translator
22522272
~~~~~~~~~~
22532273

0 commit comments

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