Skip to content

Dynamic bundle assets #31975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public function registerCommands(Application $application)
{
}

public function getPublicPath(): string
{
return 'Resources/public';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO that should return the absolute dir to be consistent with getLogDir etc,

return $this->getProjectDir().'/var/log';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobion here we're not in the project context, but in the bundle one. Anyway, bundle always returned such path, this is not changing anything

}

/**
* Returns the bundle's container extension class.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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