vendor/vich/uploader-bundle/src/Injector/FileInjector.php line 32

Open in your IDE?
  1. <?php
  2. namespace Vich\UploaderBundle\Injector;
  3. use Symfony\Component\HttpFoundation\File\File;
  4. use Vich\UploaderBundle\Mapping\PropertyMapping;
  5. use Vich\UploaderBundle\Storage\StorageInterface;
  6. /**
  7. * FileInjector.
  8. *
  9. * @author Dustin Dobervich <ddobervich@gmail.com>
  10. * @final
  11. */
  12. class FileInjector implements FileInjectorInterface
  13. {
  14. /**
  15. * @var StorageInterface
  16. */
  17. protected $storage;
  18. public function __construct(StorageInterface $storage)
  19. {
  20. $this->storage = $storage;
  21. }
  22. public function injectFile($obj, PropertyMapping $mapping): void
  23. {
  24. $path = $this->storage->resolvePath($obj, $mapping->getFilePropertyName());
  25. if (null !== $path) {
  26. $mapping->setFile($obj, new File($path, false));
  27. }
  28. }
  29. }