Loads sitemap index XML file and returns array of Urlset objects

@param string $filename

@return Urlset[]
@throws \InvalidArgumentException
356403
protected function loadCurrentSitemapIndex($filename)
    {
        if (!file_exists($filename)) {
            return array();
        }

        $urlsets = array();
        $index = simplexml_load_file($filename);
        foreach ($index->children() as $child) {
            /** @var $child \SimpleXMLElement */
            if ($child->getName() == 'sitemap') {
                if (!isset($child->loc)) {
                    throw new \InvalidArgumentException(
                        "One of referenced sitemaps in $filename doesn't contain 'loc' attribute"
                    );
                }
                $basename = preg_replace(
                    '/^' . preg_quote($this->sitemapFilePrefix) . '\.(.+)\.xml(?:\.gz)?$/',
                    '\1',
                    basename($child->loc)
                ); // cut .xml|.xml.gz

                if (!isset($child->lastmod)) {
                    throw new \InvalidArgumentException(
                        "One of referenced sitemaps in $filename doesn't contain 'lastmod' attribute"
                    );
                }
                $lastmod = new \DateTime($child->lastmod);
                $urlsets[$basename] = $this->newUrlset($basename, $lastmod);
            }
        }

        return $urlsets;
    }
723210
public function loadYamlFile($filename)
    {
        if (!file_exists($filename)) {
            $this->output->writeln("<error>The file $filename does not exist.</error>");

            return false;
        }

        try {
            $contents = Yaml::parse(file_get_contents($filename));
        } catch (\Exception $e) {
            $this->output->writeln("<error>There was an error parsing $filename. The contents are not valid YAML.</error>");
            $this->output->writeln($e->getMessage());

            return false;
        }

        return $contents;
    }
758549
protected static function loadXml( $fileName )
	{
		$xml	= XML_ElementReader::readFile( $fileName );
		foreach( $xml as $sectionNode )
		{
			$sectionName	= $sectionNode->getAttribute( 'name' );
			foreach( $sectionNode as $valueNode )
			{
				$item	= array(
					'key'		=> $valueNode->getAttribute( 'name' ),
					'value'		=> (string) $valueNode,
					'type'		=> $valueNode->getAttribute( 'type' ),
				);
	
				if( $valueNode->hasAttribute( 'comment' ) )
					$item['comment']	= $valueNode->getAttribute( 'comment' );
				settype( $item['value'], $item['type'] );
				$data[$sectionName][]	= $item;
			}
		}
		return $data;
	}
480941
public function getAttribute(string $attributeName) : array
    {
        if ($this->isEmpty()) {
            return [];
        }

        $entries = $this->toArray();
        if (!array_key_exists($attributeName, $entries[0])) {
            throw new InvalidAttributeException($attributeName);
        }

        return array_column($entries, $attributeName);
    }
1261413
protected function getData( $filename )
    {

        $matches = [];

        $regex = '/(.+)-([0-9_]+)x([0-9_]+)(-resize)*(\-\[([\-\d\.]+)x([\-\d\.]+)\])*\.([A-z]+)$/';

        preg_match( $regex, $filename, $matches );


        $path = $matches[1];
        $extension = $matches[8];
        $imagePath = sprintf( '%s/%s.%s', dirname( $filename ), basename( $path ), $extension );

        $width = $matches[2];
        $height = $matches[3];

        $focusX = $matches[6];
        $focusY = $matches[7];

        return [
            'filepath'=> $imagePath,
            'resize'=> $matches[4] != '',

            'width'=> $width != '_' ? $width : null,
            'height'=> $height != '_' ? $height : null,

            'focusX' => $focusX != '' ? $focusX : null,
            'focusY' => $focusY != '' ? $focusY : null,
        ];

    }
518687
public static function getFile($sName) {
		$sFile        =& static::$_lFile[$sName];
		$sFileDefault =& static::$_lFileDefault[$sName];
		return [
			'file' => $sFile,
			'file_default' => $sFileDefault,
		];
	}
158657
public static function read( $fileName )
	{
		$list	= array();
		if( !file_exists( $fileName ) )
			throw new RuntimeException( 'File "'.$fileName.'" is not existing' );
		$reader	= new FS_File_Reader( $fileName );
		$lines	= $reader->readArray();
		foreach( $lines as $line )
			if( $line = trim( $line ) )
				if( !preg_match( self::$commentPattern, $line ) )
					$list[]	= $line;
		return $list;
	}
1248089
protected function loadFromCache(string $fileName): array
    {
        $content     = file_get_contents($fileName);
        $loadedItems = unserialize($content);

        return $loadedItems;
    }
1150293
protected function getContentType($filename)
    {
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
        $contentType = Psr7\mimetype_from_extension($extension);

        return ['contentType' => $contentType];
    }
1309987
public function getNamesWithDifferentExtension(string $fileName)
    {
        if (! file_exists($this->basePath)) {
            return [];
        }

        $extension = pathinfo($fileName, PATHINFO_EXTENSION);

        $baseName = substr($fileName, 0, strlen($fileName) - strlen($extension) - 1);

        $allNames = scandir($this->basePath);

        $namesWithDifferentExtension = array_filter($allNames, function ($existingName) use ($baseName, $extension) {
            $existingExtension = pathinfo($existingName, PATHINFO_EXTENSION);

            $existingBaseName = substr($existingName, 0, strlen($existingName) - strlen($existingExtension) - 1);

            return $existingBaseName === $baseName && $existingExtension !== $extension;
        });

        return array_values($namesWithDifferentExtension);
    }
1150856
protected function fileOrUrl($filename)
    {
        $options = array();
        if (!empty($this->httpBasicAuth) || !empty($this->httpUserAgent)) {
            $options['http'] = array();
            $options['http']['header'] = array();

            if (!empty($this->httpBasicAuth)) {
                $username  = $this->httpBasicAuth['username'];
                $password  = $this->httpBasicAuth['password'];
                $basicAuth = base64_encode("{$username}:{$password}");

                array_push($options['http']['header'], "Authorization: Basic {$basicAuth}");
            }

            if (!empty($this->httpUserAgent)) {
                array_push($options['http']['header'], "User-Agent: {$this->httpUserAgent}");
            }
        }

        $context = stream_context_create($options);

        if (($lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES, $context)) === false) {
            throw new \Exception("The file path or URL '{$filename}' does not exist.");
        }

        return $lines;
    }
1146365
protected function getTrans($filename)
    {
        if (is_file($filename)) {
            $trans = Yaml::parse(file_get_contents($filename));
        } else {
            $trans = array();
        }

        $keys = array('breadcrumb', 'list', 'filter', 'show', 'form');
        foreach ($keys as $key) {
            if (!array_key_exists($key, $trans)) {
                $trans[$key] = array();
            }
        }

        return $trans;
    }
1189387
public function load($filename)
    {
        $json = file_get_contents($filename);
        if (false === $json) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException("Unable to load file {$filename}");
            // @codeCoverageIgnoreEnd
        }

        $data = Utils::jsonDecode($json, true);
        if (is_array($data)) {
            foreach (Utils::jsonDecode($json, true) as $cookie) {
                $this->setCookie(new SetCookie($cookie));
            }
        } elseif (strlen($data)) {
            throw new \RuntimeException("Invalid cookie file: {$filename}");
        }
    }
705793
public static function loadFile($fileName)
  {
    if (!preg_match('/\.ini$/i', $fileName)) {
      $fileName .= '.ini';
    }
    if (!static::isFileLoaded($fileName)) {
      self::$files[] = $fileName;
      return static::loadFileInMemory($fileName);
    }
    return false;
  }
961156
public function getArray()
    {
        $parsed = @simplexml_load_file($this->context);

        if (! $parsed) {
            throw new InvalidFileException('Unable to parse invalid XML file at ' . $this->context);
        }

        return json_decode(json_encode($parsed), true);
    }
380595
public function fromFile(string $filename = '', bool $returnArray = false)
    {
        if (empty($filename)) {
            throw new InvalidArgumentException('File name must be specified');
        }

        \set_error_handler(
            function ($error, $message = '') use ($filename) {
                $exMsg = \sprintf('Error reading from "%s": %s', $filename, $message);
                throw new RuntimeException($exMsg, $error);
            },
            E_WARNING
        );

        try {
            $config = $this->transform(\file_get_contents($filename));
            \restore_error_handler();
            return $returnArray ? $config : new Config($config);
        } catch (RuntimeException $e) {
            \restore_error_handler();
            throw $e;
        }
    }
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
        ];
    }