Skip to content

Commit

Permalink
minor #32452 [Bundles] Rename getPublicPath() as getPublicDir() (javi…
Browse files Browse the repository at this point in the history
…ereguiluz)

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

Discussion
----------

[Bundles] Rename getPublicPath() as getPublicDir()

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | -
| License       | MIT
| Doc PR        | I'll add this if approved

While documenting #31975 (see symfony/symfony-docs#11930) I realized that the `getPublicPath()` method name is not consistent with the rest of Symfony.

In Symfony, "path" is usually associated to routes and we use "dir" for things similar to this:

* `getCacheDir()` and `getLogdir()` to override Symfony structure (https://symfony.com/doc/current/configuration/override_dir_structure.html)
* `binDir`, `configDir`, `srcDir`, `varDir`, `publicDir` in Symfony Flex recipes (https://github.com/symfony/recipes) to override the dir structure

So, this PR proposes to rename `getPublicPath()` as `getPublicDir()`

Commits
-------

4ab2f99 [Bundles] Rename getPublicPath() as getPublicDir()
  • Loading branch information
fabpot committed Jul 12, 2019
2 parents c4568d1 + 4ab2f99 commit adcd643
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Expand Up @@ -137,13 +137,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$validAssetDirs = [];
/** @var BundleInterface $bundle */
foreach ($kernel->getBundles() as $bundle) {
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';
if (!method_exists($bundle, 'getPublicDir')) {
@trigger_error(sprintf('Not defining "getPublicDir()" method in the "%s" class is deprecated since Symfony 4.4 and will not be supported in 5.0.', get_class($bundle)), E_USER_DEPRECATED);
$publicDir = 'Resources/public';
} else {
$publicPath = $bundle->getPublicPath();
$publicDir = ltrim($bundle->getPublicDir(), '\\/');
}
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.$publicPath)) {
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.$publicDir)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Expand Up @@ -135,7 +135,7 @@ public function registerCommands(Application $application)
{
}

public function getPublicPath(): string
public function getPublicDir(): string
{
return 'Resources/public';
}
Expand Down
Expand Up @@ -20,7 +20,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @method string getPublicPath() Returns relative path for public assets
* @method string getPublicDir() Returns relative path for the public assets directory
*/
interface BundleInterface extends ContainerAwareInterface
{
Expand Down
4 changes: 2 additions & 2 deletions 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', 'getPublicPath', 'getParent', 'getName'])
->setMethods(['getPath', 'getPublicDir', 'getParent', 'getName'])
->disableOriginalConstructor()
;

Expand All @@ -651,7 +651,7 @@ protected function getBundle($dir = null, $parent = null, $className = null, $bu

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

Expand Down

0 comments on commit adcd643

Please sign in to comment.