Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c16fcc9

Browse files
garakfabpot
authored andcommitted
Dynamic bundle assets
1 parent dca9325 commit c16fcc9

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
137137
$validAssetDirs = [];
138138
/** @var BundleInterface $bundle */
139139
foreach ($kernel->getBundles() as $bundle) {
140-
if (!is_dir($originDir = $bundle->getPath().'/Resources/public')) {
140+
if (!method_exists($bundle, 'getPublicPath')) {
141+
@trigger_error('Not defining "getPublicPath()" method is deprecated since Symfony 4.4 and will not be supported in 5.0.', E_USER_DEPRECATED);
142+
$publicPath = 'Resources/public';
143+
} else {
144+
$publicPath = $bundle->getPublicPath();
145+
}
146+
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.$publicPath)) {
141147
continue;
142148
}
143149

src/Symfony/Component/HttpKernel/Bundle/Bundle.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public function registerCommands(Application $application)
135135
{
136136
}
137137

138+
public function getPublicPath(): string
139+
{
140+
return 'Resources/public';
141+
}
142+
138143
/**
139144
* Returns the bundle's container extension class.
140145
*

src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* BundleInterface.
2020
*
2121
* @author Fabien Potencier <[email protected]>
22+
*
23+
* @method string getPublicPath() Returns relative path for public assets
2224
*/
2325
interface BundleInterface extends ContainerAwareInterface
2426
{

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ protected function getBundle($dir = null, $parent = null, $className = null, $bu
627627
{
628628
$bundle = $this
629629
->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')
630-
->setMethods(['getPath', 'getParent', 'getName'])
630+
->setMethods(['getPath', 'getPublicPath', 'getParent', 'getName'])
631631
->disableOriginalConstructor()
632632
;
633633

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

652+
$bundle
653+
->expects($this->any())
654+
->method('getPublicPath')
655+
->willReturn('Resources/public')
656+
;
657+
652658
$bundle
653659
->expects($this->any())
654660
->method('getParent')

0 commit comments

Comments
 (0)