Skip to content
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

[MediaBundle] Use parameter instead of hardcoded media path #2782

Merged
merged 1 commit into from
May 8, 2021
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
5 changes: 5 additions & 0 deletions UPGRADE-5.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ UserManagementBundle
------------

* Overriding the user adminlist configurator class with `kunstmaan_user_management.user_admin_list_configurator.class` is deprecated, use the `kunstmaan_user_management.user.adminlist_configurator` config instead.

MediaBundle
----------

* Not passing a value for the "$mediaPath" parameter of "\Kunstmaan\MediaBundle\Helper\File\FileHelper::__construct" is deprecated, a value will be required.
2 changes: 1 addition & 1 deletion src/Kunstmaan/MediaBundle/Helper/File/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function canHandle($object)
*/
public function getFormHelper(Media $media)
{
return new FileHelper($media);
return new FileHelper($media, $this->mediaPath);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/Kunstmaan/MediaBundle/Helper/File/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ class FileHelper
*/
protected $path;

public function __construct(Media $media)
/** @var string */
private $mediaPath;

public function __construct(Media $media, string $mediaPath = null)
{
$this->media = $media;

if ($mediaPath === null) {
@trigger_error(sprintf('Not passing a value for the "$mediaPath" parameter of "%s" is deprecated since KunstmaanMediaBundle 5.9 and a value will be required in KunstmaanMediaBundle 6.0. Injected the required parameter in the constructor instead.', __METHOD__), E_USER_DEPRECATED);
$mediaPath = '/uploads/media/';
}

$this->mediaPath = $mediaPath;
}

/**
Expand Down Expand Up @@ -122,7 +132,7 @@ public function setFile(File $file)
$this->media->setContent($file);
$this->media->setContentType($file->getMimeType());
$this->media->setUrl(
'/uploads/media/' . $this->media->getUuid() . '.' . $this->media->getContent()->getExtension()
$this->mediaPath . $this->media->getUuid() . '.' . $this->media->getContent()->getExtension()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FileHelperTest extends TestCase
protected function setUp(): void
{
$this->media = new Media();
$this->object = new FileHelper($this->media);
$this->object = new FileHelper($this->media, '/uploads/media/');
}

public function testGetSetName()
Expand Down