Create a bunch of snippets from a file

@param string $file
@return bool
483831
protected function _createFromFile($file) {
        if (!file_exists($file)) {
            Garp_Cli::errorOut("File not found: {$file}. Adding no snippets.");
            return false;
        }
        $config = new Garp_Config_Ini($file, APPLICATION_ENV);
        if (!isset($config->snippets)) {
            Garp_Cli::lineOut('Could not find any snippets. I\'m stopping now... This is awkward.');
            return true;
        }

        $snippetNoun = 'snippets';
        $snippetCount = count($config->snippets);
        if ($snippetCount === 1) {
            $snippetNoun = 'snippet';
        }
        Garp_Cli::lineOut("About to add {$snippetCount} {$snippetNoun} from {$file}");
        Garp_Cli::lineOut('');
        $this->_createSnippets($config->snippets);
        Garp_Cli::lineOut('Done.');
        Garp_Cli::lineOut('');
        return true;
    }
985035
public function read($file)
    {
        $this->lines = [];

        $section = '';

        foreach (file($file) as $line) {
            if (preg_match('/^\s*(;.*)?$/', $line)) {
                // comment or whitespace
                $this->lines[] = [
                    'type' => 'comment',
                    'data' => $line,
                    'section' => $section
                ];
            } elseif (preg_match('/^\s?\[(.*)\]/', $line, $match)) {
                // section
                $section = $match[1];
                $this->lines[] = [
                    'type' => 'section',
                    'data' => $line,
                    'section' => $section
                ];
            } elseif (preg_match('/^\s*(.*?)\s*=\s*(.*?)\s*$/', $line, $match)) {
                // entry
                $this->lines[] = [
                    'type' => 'entry',
                    'data' => $line,
                    'section' => $section,
                    'key' => $match[1],
                    'value' => $match[2]
                ];
            }
        }
    }
903942
function readFile($file)
	{
		$fh = @fopen($file, 'r');

		$lines = false;
		if ($fh !== false) {
			$lines = array();
			while (!feof($fh)) {
				$lines[] = fgets($fh);
			}
			fclose($fh);
		}
		return $lines;
	}
144596
protected function processLines(SplFileObject $file)
    {
        $extension = $file->getExtension();

        $totalLines = 0;
        $totalBlankLines = 0;
        $totalComments = 0;
        $isMultilines = false;
        while ($file->valid()) {
            $currentLine = $file->fgets();
            $trimLine = trim($currentLine);

            // Ignoring the last new line
            if ($file->eof() && empty($trimLine)) {
                break;
            }

            $totalLines ++;
            if (empty($trimLine)) {
                $totalBlankLines ++;
            }

            // Detecting comments
            if (strpos($trimLine, '//') === 0
                || strpos($trimLine, '#') === 0) {
                $totalComments ++;
            }

            // Detecting multilines comments
            if (strpos($trimLine, '/*') === 0) {
                $isMultilines = true;
            }
            if ($isMultilines) {
                $totalComments ++;
            }
            if (strpos($trimLine, '*/') === 0) {
                $isMultilines = false;
            }
        }

        if (!isset($this->extensions[$extension])) {
            return;
        }

        $this->setStats($extension, [
            'language' => $this->extensions[$extension],
            'files' => 1,
            'blank' => $totalBlankLines,
            'comment' => $totalComments,
            'code' => $totalLines - ($totalBlankLines + $totalComments),
        ]);
    }
894850
function load(string $file = null)
    {
        if ($file == null) {
            $file = static::$configFile;
        }
        if (!file_exists($file)) {
            return false;
        }

        $a = json_decode(file_get_contents($file));

        if (isset($a->css)) {
            $this->css = $a->css;
        }

        if (isset($a->js)) {
            $this->js = $a->js;
        }
        
        if (isset($a->jss)) {
            $this->jss = $a->jss;
        }
        
        return true;
    }
19366
protected function _fileGetContents($file)
    {
        $result = false;
        if (!is_file($file)) {
            return false;
        }
        $f = @fopen($file, 'rb');
        if ($f) {
            if ($this->_options['file_locking']) @flock($f, LOCK_SH);
            $result = stream_get_contents($f);
            if ($this->_options['file_locking']) @flock($f, LOCK_UN);
            @fclose($f);
        }
        return $result;
    }
1283529
public function create(string $file) : ModularParser
    {
        $clone = clone $this;
        $clone->valid = null;
        $clone->file = false;
        $clone->class = null;
        return $clone->setFileToLoad($file);
    }
611196
public static function from($file, $prefix = 'php-tmp-file')
    {
        $tmpFile = static::generate($prefix);

        copy($file, $tmpFile);

        return $tmpFile;
    }
381922
private function compile($file)
    {
        $this->dispatchEvent('before.compile', $file);

        $compiled = $this->getCompiler()->compile(file_get_contents($file));

        $this->dispatchEvent('after.compile', $file);

        return $compiled;
    }
1096073
public function generateExtension($file = null)
    {
        if (is_string($file)) {
            if (in_array($file, $this->acceptedMimetypes())) {
                $mime = $file;
            } else {
                $mime = $this->mimetypeFor($file);
            }
        } else {
            $mime = $this->mimetype();
        }

        switch ($mime) {
            case 'image/gif':
                return 'gif';

            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                return 'jpg';

            case 'image/png':
                return 'png';

            case 'image/svg+xml':
                return 'svg';

            case 'image/webp':
                return 'webp';
        }
    }
424962
public function create($file = '')
    {
        $this->file   = $file;
        $this->memory = '';
        $this->fh     = 0;

        if ($this->file) {
            // determine compression
            if ($this->comptype == Archive::COMPRESS_AUTO) {
                $this->setCompression($this->complevel, $this->filetype($file));
            }

            if ($this->comptype === Archive::COMPRESS_GZIP) {
                $this->fh = @gzopen($this->file, 'wb'.$this->complevel);
            } elseif ($this->comptype === Archive::COMPRESS_BZIP) {
                $this->fh = @bzopen($this->file, 'w');
            } else {
                $this->fh = @fopen($this->file, 'wb');
            }

            if (!$this->fh) {
                throw new ArchiveIOException('Could not open file for writing: '.$this->file);
            }
        }
        $this->writeaccess = true;
        $this->closed      = false;
    }
1177484
public static function createFile($file, $mode = 0775)
    {
        if (empty($file)) return false;
        if (is_file($file)) {
            return true;
        }
        $dir = dirname($file);
        self::createDir($dir);
        $fh = @fopen($file, 'a');
        if ($fh) {
            fclose($fh);
            return true;
        }
        return false;
    }
372359
public static function extension($file = false) {

        if ($file && self::isFile($file)) {

            return pathinfo($file, PATHINFO_EXTENSION);
        }

        return false;
    }
785102
public function createFileName($file)
    {
        if ( ! is_null($this->elfinderFilePath) ) {
            return $this->getFileName();
        }
        if ( is_string($file) ) {
            return substr( strrchr( $file, '/' ), 1 );
        }

        $filename = $file->getClientOriginalName();
        $mime = $file->getClientOriginalExtension();
        $parts = explode('.',$filename);
        array_pop($parts);
        return str_slug( implode(' ', $parts), '-' ) . '_' . time() .  '.' . $mime;
    }
730779
protected function _fileGetContents($file)
    {
        if (!is_file($file)) {
            return false;
        }

        if ($this->_options['mode'] == 1) {
            $f = @fopen($file, 'r');
            @$data = fread($f, filesize($file));
            @fclose($f);
            return unserialize($data);
        } else {
            return include $file;
        }
    }
581555
public static function createFromFile($file) {
    $jsonConfig = json_decode(file_get_contents($file), true);
    return self::createFromConfig($jsonConfig);
  }
1325657
protected function isPartOfJoomla($file)
    {
        foreach (static::$joomlaPaths as $joomlaPath) {
            $file = realpath($file);

            if (strpos($file, $joomlaPath) === 0) {
                return true;
            }
        }

        return false;
    }