-
Notifications
You must be signed in to change notification settings - Fork 0
feat/upload #46
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
base: master
Are you sure you want to change the base?
feat/upload #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
|
|
||
| namespace App\CustomException; | ||
|
|
||
| use Throwable; | ||
|
|
||
| class FileException extends \Symfony\Component\HttpFoundation\File\Exception\FileException | ||
| { | ||
| public function __construct($message = "", $code = 0, Throwable $previous = null) | ||
| { | ||
| parent::__construct($message, $code, $previous); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DoctrineMigrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use Doctrine\Migrations\AbstractMigration; | ||
|
|
||
| /** | ||
| * Auto-generated Migration: Please modify to your needs! | ||
| */ | ||
| final class Version20191127143154 extends AbstractMigration | ||
| { | ||
| public function getDescription() : string | ||
| { | ||
| return ''; | ||
| } | ||
|
|
||
| public function up(Schema $schema) : void | ||
| { | ||
| // this up() migration is auto-generated, please modify it to your needs | ||
| $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
|
||
| $this->addSql('DROP TABLE customer'); | ||
| $this->addSql('ALTER TABLE partner CHANGE project project VARCHAR(255) DEFAULT NULL'); | ||
| } | ||
|
|
||
| public function down(Schema $schema) : void | ||
| { | ||
| // this down() migration is auto-generated, please modify it to your needs | ||
| $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
|
||
| $this->addSql('CREATE TABLE customer (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); | ||
| $this->addSql('ALTER TABLE partner CHANGE project project VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
|
|
||
| namespace App\Service; | ||
|
|
||
| use App\CustomException\FileException; | ||
| use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
|
||
| class FileUploader | ||
| { | ||
| private $targetDirectory; | ||
|
|
||
| // public function __construct($targetDirectory) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ne merge jamais de code commenté. Si tu n'as pas besoin de se bout de code tu le vire. Si tu n'en as pas besoin dans cette PR, tu le fais dans une pr distincte. 90% du code commenté reste du code mort |
||
| // { | ||
| // //$this->targetDirectory = $targetDirectory; | ||
| // } | ||
|
|
||
| public function upload(UploadedFile $file) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type ta sortie |
||
| { | ||
| $originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); | ||
| $safeFilename = transliterator_transliterate( | ||
| 'Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()', | ||
| $originalFilename | ||
| ); | ||
| $fileName = $safeFilename.'-'.uniqid().'.'.$file->guessExtension(); | ||
|
|
||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ta méthode ne va pas car tu retourne soit ton $fileName, soit void. Dans ton cas, je retournerais toujours une string soit le filename, soit ''. Du coup tu peux virer ton try catch qui ne te sert pas |
||
| $file->move($this->getTargetDirectory(), $fileName); | ||
| } catch (FileException $exception) { | ||
| } | ||
|
|
||
| return $fileName; | ||
| } | ||
|
|
||
| public function getTargetDirectory() | ||
| { | ||
| return $this->targetDirectory; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
il faudra que tu rebase ta table pour ne pas garder customer dans ta migration