file extensions accepted
@access public
@param $extension string[]
@param $error     string
@return \Gcs\Framework\Core\Orm\Validation\Element\File
@since 3.0
@package Gcs\Framework\Core\Form\Validation\Element
437794
public function extension($extension, $error) {
        if ($this->_exist) {
            array_push($this->_constraints, ['type' => self::EXTENSION, 'value' => $extension, 'message' => $error]);
        }

        return $this;
    }
710732
public static function extension($file, $separator = self::SEPARATOR_BOTH){
        return self::validate($file, $separator) ? substr($file, strrpos($file, '.') + 1) : false;
    }
648218
public function getFilenameWithExtension() {
		if ($this->extension === null) {
			return $this->filename;
		}
		else {
			return $this->filename . '.' . $this->extension;
		}
	}
665622
public function allowedFileExtensions($fileExtensions)
    {
        if (!is_array($fileExtensions)) {
            $fileExtensions = [$fileExtensions];
        }
        $this->extensions = array_unique(array_merge($this->extensions, $fileExtensions));

        return $this;
    }
292912
private function _getExtension($file = null)
	{
		if (!is_null($file))
		{
			$dot = strrpos($file, '.') + 1;

			return strtolower(substr($file, $dot));
		}

		return '##INVALID_FILE##';
	}
903096
protected function validateExtensionAndMimeType()
    {
        if ($this->allowed_file_extensions == null && ($this->file_extensions_mime_types == null || empty($this->file_extensions_mime_types))) {
            // it is not set to limit uploaded file extensions and mime types.
            return true;
        }

        // get only file extension of uploaded file.
        $file_name_explode = explode('.', $this->files[$this->input_file_name]['name']);
        if (!is_array($file_name_explode)) {
            unset($file_name_explode);
            $this->setErrorMessage(
                sprintf(static::__('Unable to validate extension for the file %s.'), $this->files[$this->input_file_name]['name']),
                'RDU_UNABLE_VALIDATE_EXT',
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['size'],
                $this->files[$this->input_file_name]['type']
            );
            return false;
        }
        $file_extension = strtolower($file_name_explode[count($file_name_explode)-1]);
        unset($file_name_explode);

        // validate allowed extensions.
        if (is_array($this->allowed_file_extensions) && !in_array($file_extension, $this->allowed_file_extensions)) {
            unset($file_extension);
            $this->setErrorMessage(
                sprintf(static::__('You have uploaded the file that is not allowed extension. (%s)'), $this->files[$this->input_file_name]['name']),
                'RDU_NOT_ALLOW_EXT',
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['size'],
                $this->files[$this->input_file_name]['type']
            );
            return false;
        }

        // validate allowed mime types that match uploaded file's extension.
        if (is_array($this->file_extensions_mime_types) && !empty($this->file_extensions_mime_types)) {
            if (!array_key_exists($file_extension, $this->file_extensions_mime_types)) {
                unset($file_extension);
                $this->setErrorMessage(
                    sprintf(static::__('Unable to validate the file extension and mime type. (%s). This file extension was not set in the &quot;file_extensions_mime_types&quot; property.'), $this->files[$this->input_file_name]['name']),
                    'RDU_UNABLE_VALIDATE_EXT_AND_MIME',
                    $this->files[$this->input_file_name]['name'],
                    $this->files[$this->input_file_name]['name'],
                    $this->files[$this->input_file_name]['size'],
                    $this->files[$this->input_file_name]['type']
                );
                return false;
            } else {
                $Finfo = new \finfo();
                $file_mimetype = $Finfo->file($this->files[$this->input_file_name]['tmp_name'], FILEINFO_MIME_TYPE);
                if (is_array($this->file_extensions_mime_types[$file_extension]) && !in_array(strtolower($file_mimetype), array_map('strtolower', $this->file_extensions_mime_types[$file_extension]))) {
                    unset($file_extension, $Finfo);
                    $this->setErrorMessage(
                        sprintf(static::__('The uploaded file has invalid mime type. (%s : %s).'), $this->files[$this->input_file_name]['name'], $file_mimetype),
                        'RDU_INVALID_MIME',
                        $this->files[$this->input_file_name]['name'] . ' : ' . $file_mimetype,
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $file_mimetype
                    );
                    unset($file_mimetype);
                    return false;
                } elseif (!is_array($this->file_extensions_mime_types[$file_extension])) {
                    unset($file_extension, $file_mimetype, $Finfo);
                    $this->setErrorMessage(
                        static::__('Unable to validate mime type. The format of &quot;file_extensions_mime_types&quot; property is incorrect.'),
                        'RDU_UNABLE_VALIDATE_MIME',
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                }
                unset($file_mimetype, $Finfo);
            }
        }

        unset($file_extension);
        return true;
    }
608513
public function filesFrom($folder, $extension)
    {

        $all_files  = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($folder));
        $files = new \RegexIterator($all_files, '/\.'.$extension.'$/');
        $fileList = array();
        foreach ($files as $file) {
            $fileList[$file->getPathName()]['path'] = $file->getPathName();
            $fileList[$file->getPathName()]['name'] = $file->getFileName();
        }
        return $fileList;
    }
58721
protected function filterExtension(string $extension): string
    {
        $extension = $this->filterString($extension);
        if (0 === strpos($extension, '.') || false !== strpos($extension, '/')) {
            throw new Exception(
                'extension must be string sequence without a leading `.` and the path separator `/` characters'
            );
        }

        return trim($extension);
    }
1074636
public function getTypeByExtension($extension)
    {
        if ($this->isValidExtension($extension)) {

            // We get back flipped copy
            $list = $this->getList(true);
            return $list[$extension];

        } else {

            // For all unknown extensions, the default Mime-Type is used
            return 'application/octet-stream';
        }
    }
89207
public function getExtension()
    {
        if (is_null($this->extension) === true) {
            $filename = parent::getFilename();
            $str = new StringWrapper($filename);
            $this->extension = $str->getFirstEndMatch($this->predefinedExtensions);
            $this->hasPredefinedExt = true;

            if ($this->extension === '') {
                $this->hasPredefinedExt = false;
                $this->extension = parent::getExtension();
            }
        }

        return $this->extension;
    }
889504
public function getFormatForFileExtension($extension)
    {
        $format = $this->getConfiguredFormat();
        if ($format === static::FORMAT_AUTO) {
            $format = $this->getAutomaticFormatForFileExtension((string) $extension);
        }

        return $format;
    }
1014133
protected function setHandlerByExtension($extension)
    {
        if (!in_array($extension, $this->file->supportedExtensions())) {
            throw new RuntimeException($this->translation->text('Unsupported file extension'));
        }

        return $this->handler = $this->file->getHandler(".$extension");
    }
203660
public static function getTypeForExtension($extension) {
		static::ensureDataLoaded();

		$extension = strtolower($extension);
		foreach (static::$mime_types as $mime_type => $extensions) {
			if (is_array($extensions)) {
				if (in_array($extension, $extensions, true)) {
					return $mime_type;
				}
			} else if ($extension === $extensions) {
				return $mime_type;
			}
		}
	}
1148475
public static function hasExtension($extension) {
		static::ensureDataLoaded();

		$extension = strtolower($extension);
		foreach (static::$mime_types as $extensions) {
			if (is_array($extensions)) {
				if (in_array($extension, $extensions, true)) {
					return true;
				}
			} else if ($extension === $extensions) {
				return true;
			}
		}

		return false;
	}
297389
public static function for_extensions($extensions)
    {
        foreach ($extensions as $extension) {
            if ($formatter = self::for_extension($extension)) {
                return $formatter;
            }
        }

        return false;
    }
281591
private function loadFileExtensions($extensions)
    {
        foreach ($extensions as $extension) {
            $extension_name = preg_replace('/^\.?/', '', (string)$extension['name']);
            $this->file_extensions[] = $extension_name;

            if (isset($extension['scanner'])) {
                $path = $this->base_dir . (string)$extension['scanner'];

                if (!file_exists($path)) {
                    throw new Exception\ConfigException('Error parsing config: cannot find file ' . $path);
                }

                $this->filetype_scanner_paths[$extension_name] = $path;
            }

            if (isset($extension['checker'])) {
                $path = $this->base_dir . (string)$extension['checker'];

                if (!file_exists($path)) {
                    throw new Exception\ConfigException('Error parsing config: cannot find file ' . $path);
                }

                $this->filetype_analyzer_paths[$extension_name] = $path;
            }
        }
    }
212998
public function validate($path, $filename = null)
    {
        $pathinfo = isset($filename) ? pathinfo($filename) : pathinfo($path);

        if (empty($pathinfo['filename'])) {
            return $this->translation->text('Unknown filename');
        }

        if (empty($pathinfo['extension'])) {
            return $this->translation->text('Unknown file extension');
        }

        if ($this->handler === false) {
            return true;
        }

        if (!isset($this->handler)) {
            try {
                $this->setHandlerByExtension($pathinfo['extension']);
            } catch (Exception $ex) {
                return $ex->getMessage();
            }
        }

        if (!isset($this->destination) && isset($this->handler['path'])) {
            $this->destination = $this->handler['path'];
        }

        try {
            return $this->validateHandler($path, $pathinfo['extension']);
        } catch (Exception $ex) {
            return $ex->getMessage();
        }
    }