Filter the files by their extension.

@param string|string[] $extension one or more file extensions (with or without leading dot)
173134
public function filterByExtension($extension)
    {
        $extensions = is_array($extension) ? $extension : [$extension];
        if (count($extensions) > 0) {
            $expr = $this->query->expr();
            $or = $expr->orX();
            foreach ($extensions as $extension) {
                $extension = ltrim((string) $extension, '.');
                $or->add($expr->eq('fv.fvExtension', $this->query->createNamedParameter($extension)));
                if ($extension === '') {
                    $or->add($expr->isNull('fv.fvExtension'));
                }
            }
            $this->query->andWhere($or);
        }
    }
891455
public function checkSingleExtension($extension)
    {
        $extension = strtolower(ltrim($extension,'.'));

        if (sizeof($this->_deniedExtensions)) {
            if (in_array($extension, $this->_deniedExtensions)) {
                return false;
            }
        }

        if (sizeof($this->_allowedExtensions)) {
            return in_array($extension, $this->_allowedExtensions);
        }

        return true;
    }
125078
public function addExtensions($extensions): self
    {
        $this->fileExtensions = \array_unique(\array_merge($this->fileExtensions, \array_map('strtolower', (array) $extensions)));
        
        return $this;
    }
297389
public static function for_extensions($extensions)
    {
        foreach ($extensions as $extension) {
            if ($formatter = self::for_extension($extension)) {
                return $formatter;
            }
        }

        return false;
    }
85182
public function setExtension(string $extension) {
        if(!$this->setModified('extension', $extension)->isModified()) {
            return $this;
        }
		$this->extension = $extension;
		return $this;
    }
1338204
public function filterByExtension()
	{
		// The call back that filters files through the finder
		$filter = function (\SplFileInfo $file) {
			
			return in_array($file->getExtension(), $this->extensions);
		};

		$this->filter($filter);
	}
559476
public function withExtension($extension)
    {
        $clone = clone $this;
        $clone->info['extension'] = $extension;

        if (empty($clone->info['file'])) {
            $clone->info['file'] = array_pop($clone->info['path']);
        }

        return $clone;
    }
461621
protected function fileMatchesMoreSpecificExtension(string $filename, string $extension) : bool
    {
      return array_reduce($this->extensions, function ($match, $compare) use ($filename, $extension) {
        if ($match || $compare === $extension || strlen($compare) < strlen($extension)) {
          return $match;
        }

        return $filename === basename($filename, ".{$compare}").".{$compare}";
      }, false);
    }
889023
public function addExtension($extension)
    {
        if (($index = array_search($extension, $this->extensions)) !== false) {
            unset($this->extensions[$index]);
        }

        array_unshift($this->extensions, $extension);
    }
925502
public function resolveFilename($extension = null)
    {
        if ($extension === null) {
            $extension = $this->extension;
        }
        return $this->name . '-' . $this->id . '.' . $extension;
    }
1196593
protected function removeExtensionFromFilename($filename, $extension)
    {
        $extension = '.'.$extension;
        $extension_length = mb_strlen($filename) - mb_strlen($extension);
        if (mb_strrpos($filename, $extension) === $extension_length) {
            $filename = mb_substr($filename, 0, $extension_length);
        }

        return $filename;
    }
349181
public function addExtension($extension)
    {
        $extensions = $this->getExtension();
        if (is_string($extension)) {
            $extension = explode(',', $extension);
        }

        foreach ($extension as $content) {
            if (empty($content) || !is_string($content)) {
                continue;
            }

            $extensions[] = trim($content);
        }
        $extensions = array_unique($extensions);

        // Sanity check to ensure no empty values
        foreach ($extensions as $key => $ext) {
            if (empty($ext)) {
                unset($extensions[$key]);
            }
        }

        $this->_extension = implode(',', $extensions);

        return $this;
    }
1214724
public static function detectByFileExtension(string $extension): string
    {
        static $extToMimeTypeMap;

        if (! $extToMimeTypeMap) {
            $extToMimeTypeMap = static::getExtensionToMimeTypeMap();
        }

        if (isset($extToMimeTypeMap[$extension])) {
            return $extToMimeTypeMap[$extension];
        }

        return 'text/plain';
    }
186997
public static function DeleteFilesFromPath($file)
	{
		$files = self::RetrieveFilesFromFolder($file->PathSuggested(),null);
		foreach ($files as $f)
		{
			if (strpos($f,$file->Extension())!== false)
			{
				self::DeleteFileString($f);
			}
		}
	}
187848
public function setExtension($extension = null)
    {
        if (!$extension) {
            $this->_path['extension'] = null;
        } else {
            $this->_path['extension'] = (string) trim($extension, '.');
        }

        return $this;
    }
1055999
protected function filterFiles($files)
    {
        if (! $files) {
            return;
        }

        foreach ($files as $key => $file) {
            if (is_array($file)) {
                $files[$key] = $this->filterFiles($files[$key]);
            }

            if (empty($files[$key])) {
                unset($files[$key]);
            }
        }

        return $files;
    }
1138632
protected function validateExtensions($extensions): Extensions
    {
        if (empty($extensions)) {
            $extensions = new Extensions(['']);
        }

        if (! $extensions instanceof Extensions) {
            $extensions = new Extensions((array)$extensions);
        }

        return $extensions;
    }