Try to find a strategy to override the file alternative for $media and run it

@param MediaInterface $media
@param string         $newFilePath
@param string         $formatName
976515
public function overrideAlternative(MediaInterface $media, $newFilePath, $formatName)
    {
        foreach ($this->strategies as $strategy) {
            if ($strategy->support($media)) {
                $strategy->overrideAlternative($media, $newFilePath, $formatName);

                return;
            }
        }

        $this->defaultStrategy->overrideAlternative($media, $newFilePath, $formatName);
    }
1041884
public function viewImageAction(Request $request, $id, $format = MediaProviderInterface::FORMAT_REFERENCE)
    {
        $media = $this->getMedia($id);

        if (!$media) {
            throw new NotFoundHttpException(sprintf('unable to find the media with the id : %s', $id));
        }

        if (!$this->get('sonata.media.pool')->getDownloadStrategy($media)->isGranted($media, $request)) {
            throw new AccessDeniedException();
        }
        $provider = $this->getProvider($media);

        return new RedirectResponse($provider->generatePublicUrl($media, $format));
    }
1055100
public static function fromFile(string $filename, bool $allowGuessByExtension): MediaType
    {
        $result = 'application/octet-stream';

        if (!@is_file($filename) || !@is_readable($filename)) {
            return new self($result);
        }

        $result = self::guessFromFinfo($filename);
        if (self::isFallback($result)) {
            $result = self::guessFromFileCommand($filename);
        }

        if ($allowGuessByExtension && self::isFallback($result)) {
            $extension = pathinfo($filename, PATHINFO_EXTENSION);
            if (self::isKnownExtension($extension)) {
                return self::fromExtension($extension);
            }
        }

        $result = str_replace(['charset=binary', 'charset=us-ascii'], ['', ''], strtolower($result));
        $result = rtrim($result, '; ');

        return new self($result);
    }
851768
private function performMoveMedia($type, $location, $oldName, $newName)
    {
        $from = "{$location}/{$oldName}";

        switch (Str::lower($type)) {
            case Media::MEDIA_TYPE_FILE:
                return $this->moveFile($from, $location, $newName);

            case Media::MEDIA_TYPE_DIRECTORY:
                return $this->moveDirectory($from, $location, $newName);

            default:
                return false;
        }
    }
338379
private function findMedia($path)
    {
        /** @var \Ekyna\Bundle\MediaBundle\Model\MediaInterface $media */
        $media = $this
            ->get('ekyna_media.media.repository')
            ->findOneBy(['path' => $path])
        ;
        if (null === $media) {
            throw new NotFoundHttpException('Media not found');
        }

        $fs = $this->get('local_media_filesystem');
        if (!$fs->has($media->getPath())) {
            throw new NotFoundHttpException('Media not found');
        }
        $file = $fs->get($media->getPath());

        return [$media, $file];
    }
940857
public function getFormat($name, $filePath, $mode) {
        $formats = $this->getFormats();
        if (!isset($formats[$name])) {
            throw new Exception("Format `$name` is not registered");
        }
        if (!is_callable($formats[$name])) {
            throw new Exception("Cannot generate format `$name`");
        }
        $format = call_user_func($formats[$name], $filePath, $mode);
        if (!$format instanceof Format) {
            throw new Exception("Cannot generate format `$name`");
        }
        return $format;
    }
925757
public function getImageUrl(Media $media, $basepath)
    {
        if ($media->getUrl() === parse_url($media->getUrl(), PHP_URL_PATH)) {
            return $basepath . $media->getUrl();
        }

        return $media->getUrl();
    }
1185995
public function setFormat(FormatInterface $format)
    {
        $this->formatId = $format->getName();

        return parent::setFormat($format);
    }
464744
public function getImageUrl(Media $media, $basepath)
    {
        $filename = $this->pdfTransformer->getPreviewFilename($basepath . $media->getUrl());
        if (!file_exists($this->webPath . $filename)) {
            return null;
        }

        return $filename;
    }
914175
public function renameFileInFileSystem(File $originFile, File $newFile)
	{
		$originFilePath = $this->getFilesystemPath($originFile);
		
		if ( ! file_exists($originFilePath)) {
			// silently exit to allow to rename physically non existing files
			return false;
		}

		$newPath = $this->getFilesystemPath($newFile);
		
		if (! rename($originFilePath, $newPath)) {
			throw new Exception\RuntimeException('File renaming failed');
		}

		if ($originFile instanceof Image) {
			
			$sizes = $originFile->getImageSizeCollection();
			
			foreach ($sizes as $size) {
				
				$sizeName = $size->getName();
				
				$newPath = $this->getImagePath($newFile, $sizeName);
				
				$currentPath = $this->getImagePath($originFile, $sizeName);
			
				rename($currentPath, $newPath);
			}
		}
	}
731378
public function copy($filename, $newFilePath, $newFileName = null, $pathToFile = null)
    {
        if ($pathToFile==null) {
            $pathToFile=$this->_filePath;
        }
        if ($newFileName==null) {
            $newFileName=$filename;
        }
        if (file_exists($pathToFile."/".$filename)) {
            return copy($pathToFile."/".$filename, $newFilePath."/".$newFileName);
        } else {
            return false;
        }
    }
1083976
public static function create($path, $format)
    {
        switch ($format) {
            case IMAGETYPE_JPEG:
                $result = imagecreatefromjpeg($path);
                break;
            case IMAGETYPE_PNG:
                $result = imagecreatefrompng($path);
                break;
            case IMAGETYPE_GIF:
                $result = imagecreatefromgif($path);
                break;
        }

        if (!$result) {
            throw new \Exception("Failing to create image (" . $path . ")");
        }

        return $result;
    }
808184
public function runAdditionalProcess(MediaInterface $media, FormInterface $form)
    {
        $this->cropAlternative($form);
        $this->overrideAlternative($form);
    }
981570
public function apply(TranscodeInterface $media, FormatInterface $format)
	{
		$options = [];
		
		foreach (clone $this->filters as $filter)
		{
			foreach ($filter->apply($media, $format) as $option => $value)
			{
				if (stripos($option, 'filter') !== false)
				{
					$option = 'filter';
				}
				
				$options[$option][] = $value;
			}
		}
		
		if (isset($options['filter']))
		{
			$option = [];
			
			foreach (array_merge_recursive(...$options['filter']) as $filter => $value)
			{
				$option[] = $filter.'='.implode(', '.$filter.'=', (array) $value);
			}
			
			$options['filter'] = implode('', $this->inputs).implode(', ', $option).implode('', $this->outputs);
		}
		
		return $options;
	}
1141113
public function copy($path, $newpath)
    {
        $this->writeStream(static::normalizerPath($newpath), $this->readStream(static::normalizerPath($path))['stream'], new Config() );

        return true;
    }
1287643
public function mediaAction($type, $filename, $includePath = array())
    {
        $includePath = array_merge(
            $includePath,
            array($this->application->getStorageDir(), $this->application->getMediaDir())
        );

        if (null !== $this->application->getBBUserToken()) {
            $includePath[] = $this->application->getTemporaryDir();
        }

        $matches = array();
        if (preg_match('/([a-f0-9]{3})\/([a-f0-9]{29})\/(.*)\.([^\.]+)/', $filename, $matches)) {
            $filename = $matches[1].'/'.$matches[2].'.'.$matches[4];
        } elseif (preg_match('/([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})\/.*\.([^\.]+)/', $filename, $matches)) {
            $filename = $matches[1].$matches[2].$matches[3].$matches[4].$matches[5].$matches[6].$matches[7].$matches[8].'.'.$matches[9];
            File::resolveMediapath($filename, null, array('include_path' => $includePath));
        }

        File::resolveFilepath($filename, null, array('include_path' => $includePath));
        $this->application->info(sprintf('Handling image URL `%s`.', $filename));

        if (false === file_exists($filename) || false === is_readable($filename)) {
            $request = $this->application->getRequest();

            throw new FrontControllerException(sprintf(
                'The file `%s` can not be found (referer: %s).',
                $request->getHost().'/'.$request->getPathInfo(),
                $request->server->get('HTTP_REFERER')
            ), FrontControllerException::NOT_FOUND);
        }

        return $this->createMediaResponse($filename);
    }
268176
public function load($path, $module = null, $format = self::DEFAULT_FORMAT)
    {
        $module = $this->_cleanMessage($module);
        $format = $this->_clean($format);
        $path   = realpath($path);

        if ($path && !$this->_storage->get($module . '.' . $format)) {
            $this->_path->add($path, $module);

            if (!in_array($format, ['ini', 'yml', 'php', 'json'], true)) {
                throw new Exception('Undefined format: ' . $format);
            }

            $this->_storage->set($module, $format);
            if ($module !== self::DEFAULT_MODULE) {
                $this->load($path, self::DEFAULT_MODULE, $format);
            }

            return true;
        }

        return false;
    }