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 Oct 13, 2020
1 parent bdacee7 commit 2a8a51f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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 @@ -178,7 +178,7 @@ public function canHandle($object)
*/
public function getFormHelper(Media $media)
{
return new FileHelper($media);
return new FileHelper($media, $this->mediaPath);
}

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

protected $mediaPath;

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

if ($mediaPath === null) {
@trigger_error(sprintf('Not passing the media path as the second argument of "%s" is deprecated since KunstmaanMediaBundle 5.7 and 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 @@ -131,7 +141,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 @@ -27,7 +27,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 2a8a51f

Please sign in to comment.