feature #31975 Dynamic bundle assets (garak)

This PR was squashed before being merged into the 4.4 branch (closes #31975).

Discussion
----------

Dynamic bundle assets

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no (new method in interface as annotation)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29213
| License       | MIT
| Doc PR        | none (yet)

Everything is explained in linked issue

Commits
-------

c16fcc93e2 Dynamic bundle assets
This commit is contained in:
Fabien Potencier 2019-07-09 08:13:12 +02:00
commit de710f6640
4 changed files with 21 additions and 2 deletions

View File

@ -137,7 +137,13 @@ EOT
$validAssetDirs = [];
/** @var BundleInterface $bundle */
foreach ($kernel->getBundles() as $bundle) {
if (!is_dir($originDir = $bundle->getPath().'/Resources/public')) {
if (!method_exists($bundle, 'getPublicPath')) {
@trigger_error('Not defining "getPublicPath()" method is deprecated since Symfony 4.4 and will not be supported in 5.0.', E_USER_DEPRECATED);
$publicPath = 'Resources/public';
} else {
$publicPath = $bundle->getPublicPath();
}
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.$publicPath)) {
continue;
}

View File

@ -135,6 +135,11 @@ abstract class Bundle implements BundleInterface
{
}
public function getPublicPath(): string
{
return 'Resources/public';
}
/**
* Returns the bundle's container extension class.
*

View File

@ -19,6 +19,8 @@ use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
* BundleInterface.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @method string getPublicPath() Returns relative path for public assets
*/
interface BundleInterface extends ContainerAwareInterface
{

View File

@ -627,7 +627,7 @@ EOF;
{
$bundle = $this
->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')
->setMethods(['getPath', 'getParent', 'getName'])
->setMethods(['getPath', 'getPublicPath', 'getParent', 'getName'])
->disableOriginalConstructor()
;
@ -649,6 +649,12 @@ EOF;
->willReturn($dir)
;
$bundle
->expects($this->any())
->method('getPublicPath')
->willReturn('Resources/public')
;
$bundle
->expects($this->any())
->method('getParent')