Generate filename

@param FileInfoInterface $fileInfo
@param MediaProviderInterface $mediaProvider
@return string
359719
public function generate(FileInfoInterface $fileInfo, MediaProviderInterface $mediaProvider)
    {
        $ext = pathinfo($fileInfo->getName(), PATHINFO_EXTENSION);
        return md5(uniqid()).'.'.$ext;
    }
138581
public function fileName($fileName = null)
    {
        if (func_num_args() > 0) {
            $parts = pathinfo($this->_name);
            $this->_name = "{$parts['dirname']}/{$fileName}.{$parts['extension']}";
            return $this;
        }
        return pathinfo($this->_name, PATHINFO_FILENAME);
    }
744905
public function buildMediaInfoCommandRunner($filePath, array $configuration = [])
    {
        if (filter_var($filePath, FILTER_VALIDATE_URL) === false) {
            $fileSystem = new Filesystem();

            if (!$fileSystem->exists($filePath)) {
                throw new \Exception(sprintf('File "%s" does not exist', $filePath));
            }

            if (is_dir($filePath)) {
                throw new \Exception(sprintf(
                    'Expected a filename, got "%s", which is a directory',
                    $filePath
                ));
            }
        }

        $configuration = $configuration + [
            'command'                            => null,
            'use_oldxml_mediainfo_output_format' => false,
        ];

        return new MediaInfoCommandRunner(
            $filePath,
            $configuration['command'],
            null,
            null,
            $configuration['use_oldxml_mediainfo_output_format']
        );
    }
154805
public function generateThumbnail(MediaInterface $media)
    {
        $fileName = $media->getFilesystemName();
        $thumbnailName = '';

        $extractedImagePath = $this->videoManager->extractImageFromVideo(
            $this->tmpDir . DIRECTORY_SEPARATOR . $fileName,
            1
        );

        $thumbnailPath = $this->imageManager->generateAlternative($extractedImagePath, $this->thumbnailFormat);

        if ('' !== $thumbnailPath) {
            $thumbnailName = self::THUMBNAIL_PREFIX . '-' . pathinfo($fileName, PATHINFO_FILENAME) . '.jpg';
            $this->mediaStorageManager->uploadFile($thumbnailName, $thumbnailPath);
        }

        if (trim($extractedImagePath, DIRECTORY_SEPARATOR) !== trim($this->tmpDir, DIRECTORY_SEPARATOR)) {
            $this->fileSystem->remove(array($extractedImagePath));
        }

        $media->setThumbnail($thumbnailName);
    }
703035
public static function getMediaTypeFromFilename(string $filename): string
    {
        $pathinfo = pathinfo(strtolower($filename));
        if (!isset($pathinfo['extension'])) {
            return 'application/octet-stream';
        }
        return self::$extensionToMediaType[$pathinfo['extension']] ?? 'application/octet-stream';
    }
1222396
public static function getMediaTypeFromFileContent(string $fileContent): string
    {
        $fileInfo = new \finfo(FILEINFO_MIME);
        $mediaType = self::trimMediaType($fileInfo->buffer($fileContent));
        return isset(self::$mediaTypeToFileExtension[$mediaType]) ? $mediaType : 'application/octet-stream';
    }
426211
public function getClientFilename() : string
    {
        return ($this->clientFilename === null) ? $this->fileStream->getFilename() : $this->clientFilename;
    }
1103291
private function generateFilename()
    {
        $filename = str_random(100) . "." . $this->extension;

        if(Storage::exists($this->folder . '/' . $filename))
        {
            $this->generateFilename();
        }

        return $filename;
    }
632038
public function save(MediaProviderInterface $mediaProvider, $andFlush = true)
    {
        $context = $mediaProvider->getMedia()->getContext();
        $provider = $this->providerService->getProviderManager($context);

        if (null !== $mediaProvider->getMedia()->getFile()) {
            $this->uploadProcess($provider, $mediaProvider);
        }

        $this->persistProcess($provider, $mediaProvider, $andFlush);
    }
33706
public function getFormName($data)
    {
        $context = $data;

        if ($data instanceof MediaCommonInterface) {
            if ($data instanceof MediaProviderInterface) {
                $context = $data->getMedia()->getContext();
            } else {
                $context = $data->getContext();
            }
        }

        return $this->providerService->getProviderManager($context)->getFormName();
    }
422283
public function generateThumbUrl(MediaInterface $media)
    {
        $path = null;

        if ($media->getType() === MediaTypes::IMAGE) {
            $path = $this->cacheManager->getBrowserPath($media->getPath(), 'media_thumb');
        } else {
            $path = $this->generateFileThumb($media);
        }

        if (null === $path) {
            $path = '/bundles/ekynamedia/img/file.jpg';
        }

        return $path;
    }
403492
protected function formatFileInfo($fileInfo)
    {
        if(empty($fileInfo) || !is_array($fileInfo) || isset($fileInfo[0])){
            return $fileInfo;
        }

        $file = [];
        foreach ($fileInfo as $key => $value){
            if(is_array($value)){
                foreach ($value as $k => $v){
                    $file[$k][$key] = $v;
                }
            } else {
                $file[$key] = $value;
            }
        }

        return $file;
    }
1021292
private function generateName(string $name, int $sufix = null): string
	{
		$fileName = $name . $sufix;
		if (file_exists($this->getFullPath($fileName))) {
			return $this->generateName($name, $sufix === null ? 1 : ++$sufix);
		}
		return $fileName;
	}
706377
public function generateDownloadUrl(FileInterface $file)
    {
        return $this->container->get('router')->generate('thrace_media_file_download', array(
            'filepath' => $file->getFilePath(), 'filename' => $file->getOriginalName()
        ), true);
    }
878781
public function getFormat(MediaProviderInterface $provider, $context)
    {
        $format = $this->input->getArgument('format');

        if (null === $format) {
            $formats = array_keys($provider->getFormats());
            $formats[] = '<ALL THUMBNAILS>';

            $format = $this->getQuestionHelper()->ask(
                $this->input,
                $this->output,
                new ChoiceQuestion('Please select the format', $formats)
            );

            if ('<ALL THUMBNAILS>' === $format) {
                $format = $context.'_all';
            }
        } else {
            $format = $context.'_'.$format;
        }

        return $format;
    }
927041
public function provideNameByHash(FileInfo $srcFileInfo, $hash)
    {
        $pathSuffixParts = array();
        for ($i = 0; $i < $this->partCount; $i++) {
            $pathSuffixParts[] = substr($hash, $i * $this->partLength, $this->partLength);
        }
        if ($this->shouldFullFilenameBeKept) {
            $name = $hash;
        } else {
            $name = substr($hash, $i * $this->partLength);
        }
        $pathSuffix = implode(FileInfo::SEPARATOR_DIRECTORY, $pathSuffixParts);
        $dstFileInfo = $srcFileInfo
            ->changeBasename($name)
            ->changePath($srcFileInfo->getPath().FileInfo::SEPARATOR_DIRECTORY.$pathSuffix)
        ;

        return $dstFileInfo;
    }
882850
public function getMediaType()
    {
        if ($this->mediaType === null) {
            return Utility\MediaTypes::getMediaTypeFromFilename($this->filename);
        } else {
            return $this->mediaType;
        }
    }