Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
-------

c16fcc9 Dynamic bundle assets
  • Loading branch information
fabpot committed Jul 9, 2019
2 parents 4a50400 + c16fcc9 commit de710f6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Expand Up @@ -137,7 +137,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Expand Up @@ -135,6 +135,11 @@ public function registerCommands(Application $application)
{
}

public function getPublicPath(): string
{
return 'Resources/public';
}

/**
* Returns the bundle's container extension class.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
Expand Up @@ -19,6 +19,8 @@
* BundleInterface.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @method string getPublicPath() Returns relative path for public assets
*/
interface BundleInterface extends ContainerAwareInterface
{
Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Expand Up @@ -627,7 +627,7 @@ protected function getBundle($dir = null, $parent = null, $className = null, $bu
{
$bundle = $this
->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')
->setMethods(['getPath', 'getParent', 'getName'])
->setMethods(['getPath', 'getPublicPath', 'getParent', 'getName'])
->disableOriginalConstructor()
;

Expand All @@ -649,6 +649,12 @@ protected function getBundle($dir = null, $parent = null, $className = null, $bu
->willReturn($dir)
;

$bundle
->expects($this->any())
->method('getPublicPath')
->willReturn('Resources/public')
;

$bundle
->expects($this->any())
->method('getParent')
Expand Down

0 comments on commit de710f6

Please sign in to comment.