@@ -24,9 +24,7 @@ Asset Packages
2424
2525The Asset component manages its assets through packages. A package groups all
2626the assets which use the same versioning strategy. In the following basic
27- example, a package is created to manage assets without any versioning:
28-
29- .. code-block :: php
27+ example, a package is created to manage assets without any versioning::
3028
3129 use Symfony\Component\Asset\Package;
3230 use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
@@ -36,23 +34,14 @@ example, a package is created to manage assets without any versioning:
3634 echo $package->getUrl('/image.png');
3735 // result: /image.png
3836
39- Packages implement the `` PackageInterface ``, which defines the following two
40- methods::
37+ Packages implement the :class: ` Symfony \\ Component \\ Asset \\ PackageInterface `,
38+ which defines the following two methods::
4139
42- namespace Symfony\Component\Asset;
40+ :method: `Symfony\\ Component\\ Asset\\ PackageInterface::getVersion `
41+ Returns the asset version for an asset.
4342
44- interface PackageInterface
45- {
46- /**
47- * Returns the asset version for an asset.
48- */
49- public function getVersion($path);
50-
51- /**
52- * Returns an absolute or root-relative public path.
53- */
54- public function getUrl($path);
55- }
43+ :method: `Symfony\\ Component\\ Asset\\ PackageInterface::getUrl `
44+ Returns an absolute or root-relative public path.
5645
5746Versioned Assets
5847~~~~~~~~~~~~~~~~
@@ -63,12 +52,12 @@ assets are cached.
6352
6453Instead of relying on a simple version mechanism, the Asset component allows to
6554define advanced versioning strategies via PHP classes. The two built-in strategies
66- provided by the component are `` EmptyVersionStrategy ``, which doesn't add any
67- version to the asset, and `` StaticVersionStrategy ``, which allows to set the
68- version with a format string.
55+ provided by the component are :class: ` Symfony \C omponent \A sset \V ersionStrategy \ E mptyVersionStrategy `,
56+ which doesn't add any version to the asset and :class: ` Symfony \C omponent \A sset \V ersionStrategy \ S taticVersionStrategy `,
57+ which allows to set the version with a format string.
6958
70- In this example, the `` StaticVersionStrategy `` is used to append the `` v1 ` `
71- suffix to any asset path::
59+ In this example, the :class: ` Symfony \C omponent \A sset \V ersionStrategy \ S taticVersionStrategy `
60+ is used to append the `` v1 `` suffix to any asset path::
7261
7362 use Symfony\Component\Asset\Package;
7463 use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
@@ -79,7 +68,8 @@ suffix to any asset path::
7968 // result: /image.png?v1
8069
8170In case you want to modify the version format, pass a sprintf-compatible format
82- string as the second argument of the ``StaticVersionStrategy `` constructor::
71+ string as the second argument of the
72+ :class: `Symfony\C omponent\A sset\V ersionStrategy\S taticVersionStrategy ` constructor::
8373
8474 // put the 'version' word before the version value
8575 $package = new Package(new StaticVersionStrategy('v1', '%s?version=%s'));
@@ -96,9 +86,9 @@ string as the second argument of the ``StaticVersionStrategy`` constructor::
9686Custom Version Strategies
9787.........................
9888
99- Use the `` VersionStrategyInterface `` to define your own version strategy. For
100- example, you could define a versioning where the current date is appended to
101- bust the cache every day::
89+ Use the :class: ` Symfony \C omponent \A sset \V ersionStrategy \ V ersionStrategyInterface `
90+ to define your own version strategy. For example, you could define a versioning
91+ where the current date is appended to bust the cache every day::
10292
10393 use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
10494
@@ -126,10 +116,12 @@ Grouped Assets
126116~~~~~~~~~~~~~~
127117
128118It's common for applications to store their assets in a common path. If that's
129- your case, replace the default ``Package `` class by ``PathPackage `` to avoid
130- repeating the same path time and again::
119+ your case, replace the default :class: `Symfony\C omponent\A sset\P ackage ` class by
120+ :class: `Symfony\C omponent\A sset\P athPackage ` to avoid repeating the same path
121+ time and again::
131122
132123 use Symfony\Component\Asset\PathPackage;
124+ // ...
133125
134126 $package = new PathPackage('/static/images', new StaticVersionStrategy('v1'));
135127
@@ -140,11 +132,12 @@ Request Context Aware Assets
140132............................
141133
142134If you are also using the HttpFoundation component in your project, for example
143- in a Symfony application, the `` PathPackage `` class can take into account the
144- context of the current request::
135+ in a Symfony application, the :class: ` Symfony \C omponent \A sset \ P athPackage ` class
136+ can take into account the context of the current request::
145137
146138 use Symfony\Component\Asset\PathPackage;
147139 use Symfony\Component\Asset\Context\RequestStackContext;
140+ // ...
148141
149142 $package = new PathPackage('/static/images', new StaticVersionStrategy('v1'));
150143 $package->setContext(new RequestStackContext($requestStack));
@@ -153,29 +146,34 @@ context of the current request::
153146 // result: /somewhere/static/images/logo.png?v1
154147
155148When the request context is set, in addition to the configured base path,
156- `` PathPackage `` also prepends the current request base URL (`` /somewhere/ `` in
157- this example) to assets. This allows your website to be hosted anywhere under
158- the web server root directory.
149+ :class: ` Symfony \C omponent \A sset \ P athPackage ` also prepends the current request
150+ base URL (`` /somewhere/ `` in this example) to assets. This allows your website
151+ to be hosted anywhere under the web server root directory.
159152
160153Absolute Assets and CDNs
161154~~~~~~~~~~~~~~~~~~~~~~~~
162155
163156Applications that host their assets on different domains and CDNs (*Content
164- Delivery Networks *) should use instead the `` UrlPackage `` class to generate
165- absolute URLs for their assets::
157+ Delivery Networks *) should use the :class: ` Symfony \C omponent \A sset \ U rlPackage `
158+ class to generate absolute URLs for their assets::
166159
167160 use Symfony\Component\Asset\UrlPackage;
161+ // ...
168162
169- $package = new UrlPackage('http://static.example.com/images/', new StaticVersionStrategy('v1'));
163+ $package = new UrlPackage(
164+ 'http://static.example.com/images/',
165+ new StaticVersionStrategy('v1')
166+ );
170167
171168 echo $package->getUrl('/logo.png');
172169 // result: http://static.example.com/images/logo.png?v1
173170
174171In case you serve assets from more than one domain to improve application
175- performance, pass an array of URLs as the first argument of `` UrlPackage ``
176- constructor::
172+ performance, pass an array of URLs as the first argument of
173+ :class: ` Symfony \C omponent \A sset \U rlPackage ` constructor::
177174
178175 use Symfony\Component\Asset\UrlPackage;
176+ // ...
179177
180178 $urls = array(
181179 'http://static1.example.com/images/',
@@ -200,8 +198,12 @@ protocol-relative URLs for HTTPs requests, any base URL for HTTP requests)::
200198
201199 use Symfony\Component\Asset\UrlPackage;
202200 use Symfony\Component\Asset\Context\RequestStackContext;
201+ // ...
203202
204- $package = new UrlPackage(array('http://example.com/', 'https://example.com/'), new StaticVersionStrategy('v1'));
203+ $package = new UrlPackage(
204+ array('http://example.com/', 'https://example.com/'),
205+ new StaticVersionStrategy('v1')
206+ );
205207 $package->setContext(new RequestStackContext($requestStack));
206208
207209 echo $package->getUrl('/logo.png');
@@ -212,7 +214,8 @@ Named Packages
212214
213215Applications that manage lots of different assets may need to group them in
214216packages with the same versioning strategy and base path. The Asset component
215- includes a ``Packages `` class to simplify the management of several packages.
217+ includes a :class: `Symfony\C omponent\A sset\P ackages ` class to simplify the
218+ management of several packages.
216219
217220In the following example, all packages use the same versioning strategy, but
218221they all have different base paths::
@@ -221,6 +224,7 @@ they all have different base paths::
221224 use Symfony\Component\Asset\PathPackage;
222225 use Symfony\Component\Asset\UrlPackage;
223226 use Symfony\Component\Asset\Packages;
227+ // ...
224228
225229 $versionStrategy = new StaticVersionStrategy('v1');
226230
@@ -233,11 +237,11 @@ they all have different base paths::
233237
234238 $packages = new Packages($defaultPackage, $namedPackages)
235239
236- The `` Packages `` class requires to define a default package which will be applied
237- to all assets except those which indicate the name of the package to use. In
238- addition, this application defines a package named `` img `` to serve images from
239- an external domain and a ``doc `` package to avoid repeating long paths when
240- linking to a document inside a template::
240+ The :class: ` Symfony \C omponent \A sset \ P ackages ` class requires to define a default
241+ package which will be applied to all assets except those which indicate the name
242+ of the package to use. In addition, this application defines a package named
243+ `` img `` to serve images from an external domain and a ``doc `` package to avoid
244+ repeating long paths when linking to a document inside a template::
241245
242246 echo $packages->getUrl('/main.css');
243247 // result: /main.css?v1
0 commit comments