Skip to content

Commit

Permalink
Use parameter instead of hardcoded media path
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny van Wijk authored and dannyvw committed May 3, 2021
1 parent 1ebea69 commit 2218395
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
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

0 comments on commit 2218395

Please sign in to comment.