Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
65382f4c
Commit
65382f4c
authored
Jun 15, 2017
by
MatTheCat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add json manifest version strategy support
parent
79c588dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
6 deletions
+39
-6
src/Silex/Provider/AssetServiceProvider.php
src/Silex/Provider/AssetServiceProvider.php
+20
-6
tests/Silex/Tests/Fixtures/manifest.json
tests/Silex/Tests/Fixtures/manifest.json
+3
-0
tests/Silex/Tests/Provider/AssetServiceProviderTest.php
tests/Silex/Tests/Provider/AssetServiceProviderTest.php
+16
-0
No files found.
src/Silex/Provider/AssetServiceProvider.php
View file @
65382f4c
...
@@ -19,6 +19,7 @@ use Symfony\Component\Asset\PathPackage;
...
@@ -19,6 +19,7 @@ use Symfony\Component\Asset\PathPackage;
use
Symfony\Component\Asset\UrlPackage
;
use
Symfony\Component\Asset\UrlPackage
;
use
Symfony\Component\Asset\Context\RequestStackContext
;
use
Symfony\Component\Asset\Context\RequestStackContext
;
use
Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy
;
use
Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy
;
use
Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy
;
use
Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy
;
use
Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy
;
/**
/**
...
@@ -33,7 +34,7 @@ class AssetServiceProvider implements ServiceProviderInterface
...
@@ -33,7 +34,7 @@ class AssetServiceProvider implements ServiceProviderInterface
$app
[
'assets.packages'
]
=
function
(
$app
)
{
$app
[
'assets.packages'
]
=
function
(
$app
)
{
$packages
=
array
();
$packages
=
array
();
foreach
(
$app
[
'assets.named_packages'
]
as
$name
=>
$package
)
{
foreach
(
$app
[
'assets.named_packages'
]
as
$name
=>
$package
)
{
$version
=
$app
[
'assets.strategy_factory'
](
isset
(
$package
[
'version'
])
?
$package
[
'version'
]
:
''
,
isset
(
$package
[
'version_format'
])
?
$package
[
'version_format'
]
:
null
);
$version
=
$app
[
'assets.strategy_factory'
](
isset
(
$package
[
'version'
])
?
$package
[
'version'
]
:
null
,
isset
(
$package
[
'version_format'
])
?
$package
[
'version_format'
]
:
null
,
isset
(
$package
[
'json_manifest_path'
])
?
$package
[
'json_manifest_path'
]
:
null
,
$name
);
$packages
[
$name
]
=
$app
[
'assets.package_factory'
](
isset
(
$package
[
'base_path'
])
?
$package
[
'base_path'
]
:
''
,
isset
(
$package
[
'base_urls'
])
?
$package
[
'base_urls'
]
:
array
(),
$version
,
$name
);
$packages
[
$name
]
=
$app
[
'assets.package_factory'
](
isset
(
$package
[
'base_path'
])
?
$package
[
'base_path'
]
:
''
,
isset
(
$package
[
'base_urls'
])
?
$package
[
'base_urls'
]
:
array
(),
$version
,
$name
);
}
}
...
@@ -42,7 +43,7 @@ class AssetServiceProvider implements ServiceProviderInterface
...
@@ -42,7 +43,7 @@ class AssetServiceProvider implements ServiceProviderInterface
};
};
$app
[
'assets.default_package'
]
=
function
(
$app
)
{
$app
[
'assets.default_package'
]
=
function
(
$app
)
{
$version
=
$app
[
'assets.strategy_factory'
](
$app
[
'assets.version'
],
$app
[
'assets.version_format'
]);
$version
=
$app
[
'assets.strategy_factory'
](
$app
[
'assets.version'
],
$app
[
'assets.version_format'
]
,
$app
[
'assets.json_manifest_path'
],
'default'
);
return
$app
[
'assets.package_factory'
](
$app
[
'assets.base_path'
],
$app
[
'assets.base_urls'
],
$version
,
'default'
);
return
$app
[
'assets.package_factory'
](
$app
[
'assets.base_path'
],
$app
[
'assets.base_urls'
],
$version
,
'default'
);
};
};
...
@@ -55,17 +56,30 @@ class AssetServiceProvider implements ServiceProviderInterface
...
@@ -55,17 +56,30 @@ class AssetServiceProvider implements ServiceProviderInterface
$app
[
'assets.base_urls'
]
=
array
();
$app
[
'assets.base_urls'
]
=
array
();
$app
[
'assets.version'
]
=
null
;
$app
[
'assets.version'
]
=
null
;
$app
[
'assets.version_format'
]
=
null
;
$app
[
'assets.version_format'
]
=
null
;
$app
[
'assets.json_manifest_path'
]
=
null
;
$app
[
'assets.named_packages'
]
=
array
();
$app
[
'assets.named_packages'
]
=
array
();
// prototypes
// prototypes
$app
[
'assets.strategy_factory'
]
=
$app
->
protect
(
function
(
$version
,
$format
)
use
(
$app
)
{
$app
[
'assets.strategy_factory'
]
=
$app
->
protect
(
function
(
$version
,
$format
,
$jsonManifestPath
,
$name
)
use
(
$app
)
{
if
(
!
$version
)
{
if
(
$version
&&
$jsonManifestPath
)
{
return
new
EmptyVersionStrategy
(
);
throw
new
\LogicException
(
sprintf
(
'Asset package "%s" cannot have version and manifest.'
,
$name
)
);
}
}
return
new
StaticVersionStrategy
(
$version
,
$format
);
if
(
$version
)
{
return
new
StaticVersionStrategy
(
$version
,
$format
);
}
if
(
$jsonManifestPath
)
{
if
(
!
class_exists
(
'Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy'
))
{
throw
new
\RuntimeException
(
'You must require symfony/asset >= 3.3 to use JSON manifest version strategy.'
);
}
return
new
JsonManifestVersionStrategy
(
$jsonManifestPath
);
}
return
new
EmptyVersionStrategy
();
});
});
$app
[
'assets.package_factory'
]
=
$app
->
protect
(
function
(
$basePath
,
$baseUrls
,
$version
,
$name
)
use
(
$app
)
{
$app
[
'assets.package_factory'
]
=
$app
->
protect
(
function
(
$basePath
,
$baseUrls
,
$version
,
$name
)
use
(
$app
)
{
...
...
tests/Silex/Tests/Fixtures/manifest.json
0 → 100644
View file @
65382f4c
{
"app.js"
:
"some-random-hash.js"
}
\ No newline at end of file
tests/Silex/Tests/Provider/AssetServiceProviderTest.php
View file @
65382f4c
...
@@ -33,4 +33,20 @@ class AssetServiceProviderTest extends TestCase
...
@@ -33,4 +33,20 @@ class AssetServiceProviderTest extends TestCase
$this
->
assertEquals
(
'/whatever-makes-sense/foo.css?css2'
,
$app
[
'assets.packages'
]
->
getUrl
(
'foo.css'
,
'css'
));
$this
->
assertEquals
(
'/whatever-makes-sense/foo.css?css2'
,
$app
[
'assets.packages'
]
->
getUrl
(
'foo.css'
,
'css'
));
$this
->
assertEquals
(
'https://img.example.com/foo.png'
,
$app
[
'assets.packages'
]
->
getUrl
(
'/foo.png'
,
'images'
));
$this
->
assertEquals
(
'https://img.example.com/foo.png'
,
$app
[
'assets.packages'
]
->
getUrl
(
'/foo.png'
,
'images'
));
}
}
public
function
testJsonManifestVersionStrategy
()
{
if
(
!
class_exists
(
'Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy'
))
{
$this
->
markTestSkipped
(
'JsonManifestVersionStrategy class is not available.'
);
return
;
}
$app
=
new
Application
();
$app
->
register
(
new
AssetServiceProvider
(),
array
(
'assets.json_manifest_path'
=>
__DIR__
.
'/../Fixtures/manifest.json'
,
));
$this
->
assertEquals
(
'/some-random-hash.js'
,
$app
[
'assets.packages'
]
->
getUrl
(
'app.js'
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment