Creates a PHP trait from a file

@param string $filename
@return PhpTrait
433803
public static function fromFile(string $filename): PhpTrait {
		$trait = new PhpTrait();
		$parser = new FileParser($filename);
		$parser->addVisitor(new TraitParserVisitor($trait));
		$parser->addVisitor(new MethodParserVisitor($trait));
		$parser->addVisitor(new ConstantParserVisitor($trait));
		$parser->addVisitor(new PropertyParserVisitor($trait));
		$parser->parse();

		return $trait;
	}
1213000
protected function parse($filename)
	{
		// Capture hidden PHP errors from the parsing.
		if ($this->debug)
		{
			// See https://www.php.net/manual/en/reserved.variables.phperrormsg.php
			$php_errormsg = null;
			$trackErrors  = ini_get('track_errors');
			ini_set('track_errors', true);
		}

		$strings = @parse_ini_file($filename);

		// Restore error tracking to what it was before.
		if ($this->debug)
		{
			ini_set('track_errors', $trackErrors);

			// Initialise variables for manually parsing the file for common errors.
			$blacklist   = array('YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE');
			$this->debug = false;
			$errors      = array();

			// Open the file as a stream.
			$file = new \SplFileObject($filename);

			foreach ($file as $lineNumber => $line)
			{
				// Avoid BOM error as BOM is OK when using parse_ini.
				if ($lineNumber == 0)
				{
					$line = str_replace("\xEF\xBB\xBF", '', $line);
				}

				$line = trim($line);

				// Ignore comment lines.
				if (!\strlen($line) || $line[0] == ';')
				{
					continue;
				}

				// Ignore grouping tag lines, like: [group]
				if (preg_match('#^\[[^\]]*\](\s*;.*)?$#', $line))
				{
					continue;
				}

				// Remove the "_QQ_" from the equation
				$line       = str_replace('"_QQ_"', '', $line);
				$realNumber = $lineNumber + 1;

				// Check for any incorrect uses of _QQ_.
				if (strpos($line, '_QQ_') !== false)
				{
					$errors[] = $realNumber;

					continue;
				}

				// Check for odd number of double quotes.
				if (substr_count($line, '"') % 2 != 0)
				{
					$errors[] = $realNumber;

					continue;
				}

				// Check that the line passes the necessary format.
				if (!preg_match('#^[A-Z][A-Z0-9_\*\-\.]*\s*=\s*".*"(\s*;.*)?$#', $line))
				{
					$errors[] = $realNumber;

					continue;
				}

				// Check that the key is not in the blacklist.
				$key = strtoupper(trim(substr($line, 0, strpos($line, '='))));

				if (\in_array($key, $blacklist))
				{
					$errors[] = $realNumber;
				}
			}

			// Check if we encountered any errors.
			if (\count($errors))
			{
				$this->errorfiles[$filename] = $filename . ' - error(s) in line(s) ' . implode(', ', $errors);
			}
			elseif ($php_errormsg)
			{
				// We didn't find any errors but there's probably a parse notice.
				$this->errorfiles['PHP' . $filename] = 'PHP parser errors -' . $php_errormsg;
			}

			$this->debug = true;
		}

		return \is_array($strings) ? $strings : array();
	}
1342184
public function fromFile($filename)
    {
        if (function_exists('opcache_get_status') && function_exists('opcache_get_configuration')) {
            if (empty($GLOBALS['openapi_opcache_warning'])) {
                $GLOBALS['openapi_opcache_warning'] = true;
                $status = opcache_get_status();
                $config = opcache_get_configuration();
                if ($status['opcache_enabled'] && $config['directives']['opcache.save_comments'] == false) {
                    Logger::warning("php.ini \"opcache.save_comments = 0\" interferes with extracting annotations.\n[LINK] http://php.net/manual/en/opcache.configuration.php#ini.opcache.save-comments");
                }
            }
        }
        $tokens = token_get_all(file_get_contents($filename));

        return $this->fromTokens($tokens, new Context(['filename' => $filename]));
    }
1135536
public function createPHPExcelObject($filename = null)
    {
        return (null === $filename) ? new \PHPExcel() : call_user_func(array($this->phpExcelIO, 'load'), $filename);
    }
419576
public function createPHPWordObject($filename = null)
    {
        return (null === $filename) ? new PhpWord() : call_user_func(array($this->phpWordIO, 'load'), $filename);
    }
276797
public static function fromFile($filename): self
    {
        if (!is_readable($filename) ||
             false === ($str = file_get_contents($filename))) {
            throw new \RuntimeException("Failed to read $filename.");
        }
        return self::fromString($str);
    }
425625
public static function load($filename)
	{
		$btree = null;

		if (!file_exists($filename))
		{
			return null;
		}
		$lines = file($filename);

		foreach ($lines as $i=>$linha)
		{
			if (substr($linha,0,1) != '+')
			{
				$bnode = new BTreeNode($linha);
				$btree = BTree::insert($bnode, $btree);
			}
			else
			{
				$bnode->addValue(substr($linha,1));
			}
		}
		return $btree;
	}
1009418
protected function getContentType($fileName)
    {
        // Just grabbing the extension
        $extension = strtolower(substr($fileName, strrpos($fileName, '.') + 1));
        if (isset($this->extensionMap[$extension])) {
            return $this->extensionMap[$extension];
        }

        return 'application/octet-stream';
    }
526963
public static function parser($filename)
    {
        $builder = new self($filename);
        $builder->engine = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
        // Parse
        $builder->parse();
        return $builder;
    }
213190
static public function touch($filename)
	{
	    $ret = true;
	    if ($filename && !file_exists($filename)) {
	        $ret = static::write($filename, '');
	    }
	    return $ret;
	}
59878
public static function parseFromFile($filename)
    {
        if (file_exists($filename) && is_readable($filename)) {
            return new self(file_get_contents($filename));
        } else {
            throw new \RuntimeException(sprintf("File %s is not readable, or doesn't exist.", $filename));
        }
    }
797168
private function getFileContentSafety($filename) {
        $file = fopen($filename, 'r');
        flock($file, LOCK_SH);
        $content = file_get_contents($filename);
        flock($file, LOCK_UN);
        fclose($file);

        return $content;
    }
1227567
public function parse($filename)
    {
        $tokens = token_get_all(file_get_contents($filename));
        $classNames = [];
        $interfaceNames = [];
        $traitNames = [];
        $namespace = [];
        $curleys = 0;
        $isInNamespace = false;
        $totalTokens = count($tokens);

        for ($i = 0; $i <= $totalTokens; $i++) {
            if (!isset($tokens[$i])) {
                break;
            }

            $token = $tokens[$i];
            if (is_string($token)) {
                if (in_array($token[0], ['{'])) {
                    $curleys++;
                }

                if (in_array($token[0], ['}'])) {
                    $curleys--;
                }
                $token = [0 => $token];
            }

            // iterate until space to get FQ NS name.
            if ($token[0] == T_NAMESPACE) {
                $namespace = [];
                $i = $i + 2; 
                for (; $i <= $totalTokens; $i++) {
                    if (!isset($tokens[$i])) {
                        break;
                    }
                    $token = $tokens[$i];

                    if ($token[0] == T_STRING) {
                        $namespace[] = $token[1];
                    }

                    if ($token[0] == ';') {
                        $isInNamespace = true;
                        break;
                    }

                    if ($token[0] == '{') {
                        $curleys++;
                        break;
                    }

                    if ($token[0] == '{') {
                        $curleys--;
                    }
                }
            }

            if ($token[0] == T_CLASS) {
                $prevToken = $tokens[$i - 1];
                if (is_array($prevToken) && $prevToken[0] == T_DOUBLE_COLON) {
                    continue;
                }
                
                $i = $i + 2;
                for (; $i <= count($tokens); $i++) {
                    $token = $tokens[$i];
                    if ($token[0] == T_STRING) {
                        if ($curleys == 0 && !$isInNamespace) {
                            $namespace = [];
                        }
                        $classParts = array_merge($namespace, [$token[1]]);
                        $classNames[] = join('\\', $classParts);
                        break;
                    }
                }
            }

            if ($token[0] == T_INTERFACE) {
                $i = $i + 2;
                for (; $i <= count($tokens); $i++) {
                    $token = $tokens[$i];
                    if ($token[0] == T_STRING) {
                        if ($curleys == 0 && !$isInNamespace) {
                            $namespace = [];
                        }
                        $interfaceParts = array_merge($namespace, [$token[1]]);
                        $interfaceNames[] = join('\\', $interfaceParts);
                        break;
                    }
                }
            }

            if ($token[0] == T_TRAIT) {
                $i = $i + 2;
                for (; $i <= count($tokens); $i++) {
                    $token = $tokens[$i];
                    if ($token[0] == T_STRING) {
                        if ($curleys == 0 && !$isInNamespace) {
                            $namespace = [];
                        }
                        $traitParts = array_merge($namespace, [$token[1]]);
                        $traitNames[] = join('\\', $traitParts);
                        break;
                    }
                }
            }
        }
        return [
            'classes' => $classNames,
            'interfaces' => $interfaceNames,
            'traits' => $traitNames
        ];
    }
1185073
public function imageCreateJpegfromExif($filename)
    {
        $img  = imagecreatefromjpeg($filename);
        $exif = exif_read_data($filename);
        if (!$exif || !isset($exif['Orientation'])) {
            return $img;
        }
        $orientation = $exif['Orientation'];
        if ($orientation === 6 || $orientation === 5) {
            $img = imagerotate($img, 270, null);
        } elseif ($orientation === 3 || $orientation === 4) {
            $img = imagerotate($img, 180, null);
        } elseif ($orientation === 8 || $orientation === 7) {
            $img = imagerotate($img, 90, null);
        }
        if ($orientation === 5 || $orientation === 4 || $orientation === 7) {
            imageflip($img, IMG_FLIP_HORIZONTAL);
        }
        
        return $img;
    }
77360
public function createFile(string $fileName): \SplFileInfo
    {
        $fileInfo = new \SplFileInfo($this->getTmpFolder() . '/' . $fileName);
        $pathName = $fileInfo->getPathname();
        if (!file_exists(dirname($pathName))) {
            $this->fileSystem->mkdir(dirname($pathName), self::FILE_MODE);
        }
        $this->fileSystem->touch($pathName);
        $this->fileSystem->chmod($pathName, self::FILE_MODE);
        return $fileInfo;
    }
1239699
public function fromFile($filename)
        {
            if (!is_file($filename) || !is_readable($filename)) {
                throw new Exception(sprintf(
                    "File '%s' doesn't exist or not readable",
                    $filename
                ));
            }

            $this->directory = dirname($filename);

            set_error_handler(
                function ($error, $message = '', $file = '', $line = 0) use ($filename) {
                    throw new Exception(sprintf(
                        'Error reading INI file "%s": %s',
                        $filename, $message
                    ), $error);
                }, E_WARNING
            );
            $ini = parse_ini_file($filename, true);
            restore_error_handler();

            return $this->process($ini);
        }
92395
abstract protected function __construct($filename);
    /**
     * @param string $filename
     * @return mixed
     */
    protected function loadYaml($filename)
    {
        $ymlParser = new Parser();
        return $ymlParser->parse(file_get_contents($filename));
    }