Check the request before executing

@param   string  $type
@param   string  $file
@return  string
@throws  \Exception
435999
public function checkRequest($type, $file)
    {
        // no checks for getters
        if(in_array($type, ['detectors', 'mime-types', 'parsers', 'version']))
        {
            //
        }
        // invalid local file
        elseif(!preg_match('/^http/', $file) && !file_exists($file))
        {
            throw new Exception("File $file can't be opened");
        }
        // invalid remote file
        elseif(preg_match('/^http/', $file) && !preg_match('/200/', get_headers($file)[0]))
        {
            throw new Exception("File $file can't be opened", 2);
        }
        // download remote file if required only for integrated downloader
        elseif(preg_match('/^http/', $file) && $this->downloadRemote)
        {
            $file = $this->downloadFile($file);
        }

        return $file;
    }
1300077
protected function requireFile($file)
    {
        switch ($this->type)
        {
            case PHP:
                return require $file;

            case YML:
                return \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));

            case JSON:
                return $this->helper->json()->decode(file_get_contents($file));
        }

        throw new Exceptions\TypeNotFound();
    }
1241336
public function getUrl($file, $type): string
    {
        if (!$this->checkPermission($type)) {
            $file = $this->noImage;
        }

        $filePath = $this->getCachePath($file, $type);

        if (file_exists($filePath['system']) && (time() - filemtime($filePath['system']) < $this->cacheTime)) {
            return $filePath['public'];
        }

        return Url::toRoute([$this->imageAction, 'path' => urlencode($file), 'type' => $type]);
    }
1218566
public function readImage( $file, $type) {
		switch ($type) {
			case 2:	//JPEG
			return(ImageCreateFromJPEG($file));
			break;
			
			case 3:	//PNG
			return(ImageCreateFromPNG($file));
			break;
			
			default:
			$this->errorMsg="File format not supported.";
			return(false);
		}
	}
651129
public function load($file, $type = null)
    {
        $path   = $this->locator->locate($file);
        $config = array();

        $result = parse_ini_file($path, true);
        if (false === $result || array() === $result) {
            throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $file));
        }

        if (isset($result['parameters']) && is_array($result['parameters'])) {
            $config['parameters'] = array();
            foreach ($result['parameters'] as $key => $value) {
                $config['parameters'][$key] = $value;
            }
        }
    }
240848
public static function scanFile($file, DOMDocument $dom = null)
    {
        if (!file_exists($file)) {
            throw new Exception(
                "The file $file specified doesn't exist"
            );
        }
        return self::scan(file_get_contents($file), $dom);
    }
157918
public function execute($type)
    {
        switch (strtolower($type)) {
        case 'markup':
            $curlOptArray = $this->getMarkupOpts();
            break;

        case 'file':
            $curlOptArray = $this->getFileOpts();
            break;

        case 'url':
            $curlOptArray = $this->getUrlOpts();
            break;

        default:
            throw new \PHPUnit_Framework_Exception('Invalid type: '.$type);
            break;
        }

        $curlOptArray = $curlOptArray + array(CURLOPT_RETURNTRANSFER => true,
                                              CURLOPT_TIMEOUT => 10, );

        // Throttle calls (if necessary).
        Throttle::delay(get_class($this));

        $curl = curl_init();
        curl_setopt_array($curl, $curlOptArray);

        if (!$response = curl_exec($curl)) {
            throw new \PHPUnit_Framework_Exception('Unable to validate. Error: '.
                                                   curl_error($curl));
        }

        curl_close($curl);

        return $response;
    }
1045092
public function save($file, $type = 'guess', $quality = 80)
    {
        if ($file) {
            $directory = dirname($file);

            if (!is_dir($directory)) {
                @mkdir($directory, 0777, true);
            }
        }

        if (is_int($type)) {
            $quality = $type;
            $type = 'jpeg';
        }

        if ($type == 'guess') {
            $type = $this->guessType();
        }

        if (!isset(self::$types[$type])) {
            throw new \InvalidArgumentException('Given type ('.$type.') is not valid');
        }

        $type = self::$types[$type];

        try {
            $this->init();
            $this->applyOperations();

            $success = false;

            if (null == $file) {
                ob_start();
            }

            if ($type == 'jpeg') {
                $success = $this->getAdapter()->saveJpeg($file, $quality);
            }

            if ($type == 'gif') {
                $success = $this->getAdapter()->saveGif($file);
            }

            if ($type == 'png') {
                $success = $this->getAdapter()->savePng($file);
            }

            if ($type == 'webp') {
                $success = $this->getAdapter()->saveWebP($file, $quality);
            }

            if (!$success) {
                return false;
            }

            return null === $file ? ob_get_clean() : $file;
        } catch (\Exception $e) {
            if ($this->useFallbackImage) {
                return null === $file ? file_get_contents($this->fallback) : $this->getCacheFallback();
            } else {
                throw $e;
            }
        }
    }
839787
public static function load(string $file, ?string $type = null) : array
    {
        if (isset($type))
        {
            if (isset(self::$classMap[$type]))
            {
                $class = self::$classMap[$type];

                $data = $class::load($file);
            }
            else
            {
                throw new Exception(
                    "There is no registered handler for the specified type "
                    .$type
                );
            }
        }
        else
        {
            self::registerSymfonyYaml();

            foreach (self::$classMap as $ext => $class)
            {
                if (preg_match('/[.]'.preg_quote($ext, '/').'$/i', $file))
                {
                    $data = $class::load($file);
                    break;
                }
            }
        }

        if ( ! isset($data))
        {
            throw new OptionLoaderException(
                "File $file does not appear to be valid"
            );
        }

        return $data;
    }
108719
public function fetchData($filename, $type) {
        $absPath = $this->_getAbsPath($filename, $type);

        if ($absPath === false) {
            throw new Exception($absPath . ' does not exist');
        }

        $content = file_get_contents($absPath);

        if ($content !== false) {
            return $content;
        } else throw new Exception("Could not read {$absPath} on " . $this->getEnvironment());
    }
1252461
protected function getDataFromFile($file, $type = 'application/json')
    {
        if (file_exists($file)) {
            $opts = [
                'http' => [
                    'header' => 'Content-Type: '.$type.'; charset=utf-8',
                ],
            ];

            $context = stream_context_create($opts);
            $data = file_get_contents($file, 0, $context);
            $json = $this->isJson($data, true);
            
            if (!$json) {
                throw new InvalidJsonException();
            }
            
            return $json;
        }

        throw new FileNotFoundException();
    }
1051047
protected function listFiles($type)
    {
        if (!isset($this->cache['files'][$type])) {
            $path = sprintf('%s/%s', $this->directory, $type);

            if (!$this->files->exists($path)) {
                throw new Exception(sprintf(
                    'No content directory found for type "%s" (in "%s").',
                    $type,
                    $this->directory
                ));
            }

            $finder = new Finder();

            $this->cache['files'][$type] = $finder->files()->in($path);
        }

        return clone $this->cache['files'][$type];
    }
90544
public static function addToQueue($path, $type)
    {
        if ($type != self::TYPE_DIR && $type != self::TYPE_FILE) {
            throw new \Exception(sprintf('Invalid $type parameter "%s"', $type));
        }

        self::$cleanupQueue[] = ['path' => $path, 'type' => $type];
    }
909171
public function uploadFrom($file, $type = 'image')
    {
        if (!$file || !$type) {
            $this->setError('参数缺失');

            return false;
        }

        $this->setPostQueryStr('type', $type);

        $name        = 'media'; // 设置上传文件键名 固定为media
        $filename    = $file['name']; // 设置上传文件名
        $filetype    = $file['type'];
        $filecontent = file_get_contents($file['tmp_name']); // 读取临时文件里 上传文件的信息
        $key         = "name=\"{$name}\"; filename=\"{$filename}\"\r\nContent-Type: {$filetype}\r\n"; // curl设置上传文件的一种方法.

        $param       = [];
        $param[$key] = $filecontent;

        $node = 'upload';

        $res = $this->_post($node, $param, false);

        return $res;
    }
153229
public static function changeDate(String $file, String $type = 'd.m.Y G:i:s') : String
    {
        $file = self::rpath($file);

        if( ! file_exists($file) )
        {
            throw new Exception\FileNotFoundException(NULL, $file);
        }

        $date = filemtime($file);

        return date($type, $date);
    }
154295
public function getAction($file)
    {
        if (!is_dir($this->source_directory) || !isset($this->file_extension, $this->response_type)) {
            throw new Exception("Controller is not configured!");
        }
        $source_file = $this->source_directory . "/" . $file . "." . $this->file_extension;
        if (!is_readable($source_file)) {
            throw new Error404Exception;
        }
        $this->response->setHeader("Content-Type", $this->response_type);
        return $this->view->display($source_file);
    }
375359
public function request($type, $file = null)
    {
        // check if not checked
        $this->check();

        // check if is cached
        if(isset($this->cache[sha1($file)][$type]))
        {
            return $this->cache[sha1($file)][$type];
        }

        // command arguments
        $arguments = $this->getArguments($type, $file);

        // check the request
        $file = parent::checkRequest($type, $file);

        // add last argument
        if($file)
        {
            $arguments[] = escapeshellarg($file);
        }

        // build command
        $jar = escapeshellarg($this->path);
        $command = ($this->java ?: 'java') . " -jar $jar " . implode(' ', $arguments);

        // run command
        $response = $this->exec($command);

        // metadata response
        if($type == 'meta')
        {
            // fix for invalid? json returned only with images
            $response = str_replace(basename($file) . '"}{', '", ', $response);

            // on Windows, response comes in another charset
            if(defined('PHP_WINDOWS_VERSION_MAJOR'))
            {
                $response = utf8_encode($response);
            }

            $response = Metadata::make($response, $file);
        }

        // cache certain responses
        if(in_array($type, ['lang', 'meta']))
        {
            $this->cache[sha1($file)][$type] = $response;
        }

        return $response;
    }