-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
164 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
imports: | ||
- { resource: './database/image_slider.yml' } | ||
- { resource: './database/image_slider_lang.yml' } | ||
- { resource: './database/image_slider_image.yml' } | ||
- { resource: './database/image_slider_lang.yml' } | ||
- { resource: './database/image_slider_shop.yml' } | ||
- { resource: './hooks/register.yml' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Domain/ImageSlider/CommandHandler/UploadFilesTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oksydan\IsImageslider\Domain\ImageSlider\CommandHandler; | ||
|
||
use Doctrine\Common\Collections\Collection; | ||
use Oksydan\IsImageslider\Entity\ImageSliderImage; | ||
use Oksydan\IsImageslider\Entity\ImageSliderLang; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
trait UploadFilesTrait | ||
{ | ||
public function uploadFile(UploadedFile $file): ImageSliderImage | ||
{ | ||
$image = new ImageSliderImage(); | ||
|
||
$fileName = $this->uploadHelper->uploadImage($file); | ||
$image->setName($fileName); | ||
|
||
return $image; | ||
} | ||
|
||
public function saveImagesToSliderLang(array $files, Collection $sliderLangs): void | ||
{ | ||
foreach ($sliderLangs as $index => $sliderLang) { | ||
$langFiles = $files[$index] ?? []; | ||
|
||
foreach ($langFiles as $name => $langFile) { | ||
$file = $langFile['image']; | ||
$name = str_replace('_', '', ucwords($name, '_')); | ||
$setter = 'set' . $name; | ||
|
||
if (null === $file) { | ||
continue; | ||
} | ||
|
||
$imageSliderImage = $this->uploadFile($file); | ||
|
||
if (method_exists($sliderLang, $setter)) { | ||
$sliderLang->$setter($imageSliderImage); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Oksydan\IsImageslider\Helper; | ||
|
||
use Symfony\Component\HttpFoundation\File\Exception\FileException; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
class UploadHelper | ||
{ | ||
private string $imagesDir; | ||
|
||
public function __construct(string $imagesDir) | ||
{ | ||
$this->imagesDir = $imagesDir; | ||
} | ||
|
||
/** | ||
* @throws FileException | ||
*/ | ||
public function uploadImage(UploadedFile $file): string | ||
{ | ||
$originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); | ||
|
||
$newFilename = md5($originalFilename . '-' . uniqid()) . '.' . $file->guessExtension(); | ||
|
||
$file->move($this->imagesDir, $newFilename); | ||
|
||
return $newFilename; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters