@param $filename

@return bool|resource
@throws ExtensionException
10636
private function openStream($filename)
    {
        if (!file_exists($filename)) {
            throw new ExtensionException(sprintf('File path (%s) doesn\'t exist', $filename));
        }
        
        if (!is_readable($filename)) {
            throw new ExtensionException(sprintf('File path (%s) doesn\'t readable', $filename));
        }
        
        return fopen($filename, 'a+');
    }
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;
    }
699929
public function get($filename)
    {
        if (!$stream = $this->readStream($filename)) {
            return false;
        }

        $contents = stream_get_contents($stream);

        fclose($stream);

        return $contents;
    }
88986
protected function load($filename)
    {
        $success = false;

        if (file_exists($filename)) {
            /** @noinspection PhpIncludeInspection */
            require $filename;
            $success = true;
        }

        return $success;
    }
1099631
public function client($filename)
    {
        $path = $this->clientPath($filename, false);
        return Eresus_Template::loadFromFile($path);
    }
478873
static function filenameWithoutExtension($filename) {
		$filename=self::filename($filename);
		if (preg_match('~(.*)\.(\w{1,10})$~',$filename,$parts)) {
			return $parts[1];
		}
		return $filename;
	}
461546
public function matchSerializerByExtension($fileName)
    {
        /** @var \Thelia\Core\Serializer\AbstractSerializer $serializer */
        foreach ($this->serializerManager->getSerializers() as $serializer) {
            if (stripos($fileName, '.' . $serializer->getExtension()) !== false) {
                return $serializer;
            }
        }

        return null;
    }
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';
    }
408152
protected function replaceExtension($filename, $ext)
    {
        $ext = str_replace('.', '', $ext);
        $filename = $this->removeExtension($filename);

        return $filename.'.'.$ext;
    }
937484
public function open($filename)
    {

        if (!is_file($filename)) return false;

        $this->file       = @(string)$filename;
        $this->group      = @(int)filegroup($filename);
        $this->owner      = @(int)fileowner($filename);
        $this->size       = @(int)filesize($filename);
        $this->type       = @(string)filetype($filename);
        $this->accessed   = @(int)fileatime($filename);
        $this->changed    = @(int)filectime($filename);
        $this->modified   = @(int)filemtime($filename);
        $this->permission = @(int)fileperms($filename);
        $this->f_inode    = @ fileinode($filename);
        $this->writeable  = @(bool)is_writable($filename);
        $this->readable   = @(bool)is_readable($filename);
        $this->mime_type  = @(string)mime_content_type($filename);
        $this->_get_path();
        $this->_extract_filename();
        $this->_extract_file_extension();

        return true;
    }
1345447
protected function get_mimetype_from_filename($filename) {
        $mimetype = 'application/unknown';
        $types = core_filetypes::get_types();
        $fileextension = '.bin';
        if (strpos($filename, '.') !== false) {
            $fileextension = substr($filename, strrpos($filename, '.') + 1);
        }

        if (isset($types[$fileextension])) {
            $mimetype = $types[$fileextension]['type'];
        }
        return $mimetype;
    }
497752
public static function open($fileName)
    {
        self::checkRequirements();

        if (!file_exists($fileName) || !is_readable($fileName))
            throw new Exception('Could not open file: '.$fileName);

        $type = self::detectArchiveType($fileName);
        if (!self::canOpenType($type)) {
            return null;
        }

        return new self($fileName, $type);
    }
125131
protected function isPhpFilename(string $filename) : bool
    {
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
        return (strtolower($extension) == 'php');
    }
786610
public static function jsonFileContent($filename)
    {
        $fileFullname = Config::getResourceFilePath($filename);

        if (!File::exists($fileFullname)) {
            throw new Exception('The resource file ' . $fileFullname . ' was not found! Perhaps, you need to run PHP artisan resource-file:create [model-name]  or resource-file:from-database [model-name] ');
        }

        return File::get($fileFullname);
    }
811418
static function fetchDOMFromFile( $filename )
    {
        if ( file_exists( $filename ) )
        {
            $dom = new DOMDocument( '1.0', 'utf-8' );
            $dom->preserveWhiteSpace = false;
            $success = $dom->load( $filename );

            if ( !$success )
            {
                return false;
            }
            else
            {
                return $dom;
            }
        }
        return false;
    }
1024778
static public function tryCreateFromFile($filename) {
		try {
			$instance = self::createFromFile($filename);
			return $instance;
		} catch (\Exception $exception) {
			return null;
		}
	}
106383
public function getFileResource($fileName)
    {
        $resource = fopen('php://temp', 'r+');
        $entry = $this->sevenZip->getEntry($fileName);

        fwrite($resource, $entry->getContent());
        rewind($resource);
        return $resource;
    }