-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for 'ReplacingFile' to 'upload' files not uploaded via …
- Loading branch information
1 parent
fb44772
commit 3b64675
Showing
17 changed files
with
217 additions
and
15 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
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,47 @@ | ||
# Inject files from other sources | ||
|
||
The bundle provides a way to inject files into entities coming from other sources than [HTTP uploads via forms](../form/vich_file_type.md). | ||
|
||
When you have configured your entity like laid out in the [usage page](../usage.md), you can use code like the one below to inject files which are coming from other sources like | ||
|
||
- already a file on the server, | ||
- downloaded with curl/wget or | ||
- migrate old uploads. | ||
|
||
|
||
## Example | ||
|
||
```php | ||
// ... | ||
use Acme\DemoBundle\Entity\Product; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Vich\UploaderBundle\FileAbstraction\ReplacingFile; | ||
|
||
class MigrationCommand extends Command | ||
{ | ||
public function __construct( | ||
protected EntityManagerInterface $em, | ||
) { | ||
parent::__construct(); | ||
} | ||
// ... | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$product = new Product(); | ||
$product->imageFile = new ReplacingFile('myFile.png'); | ||
// ... | ||
|
||
$this->em->persist($product); | ||
$this->em->flush(); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} | ||
``` | ||
|
||
## That was it! | ||
|
||
Check out the docs for information on how to use the bundle! [Return to the | ||
index.](../index.md) |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vich\UploaderBundle\FileAbstraction; | ||
|
||
use Symfony\Component\HttpFoundation\File\File; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
/** | ||
* This class can be used to signal that the given file should be "uploaded" into the Vich-abstraction | ||
* in cases where it is not possible to construct an `UploadedFile`. | ||
*/ | ||
class ReplacingFile extends File | ||
{ | ||
public function getClientOriginalName(): string | ||
{ | ||
return $this->getFilename(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.