Completes parsing of PHP data

@param  array $data
@param  string $filename

@return array|null
@throws UnsupportedFormatException
179172
protected function parse($data = null, $filename = null)
    {
        // If we have a callable, run it and expect an array back
        if (is_callable($data)) {
            $data = call_user_func($data);
        }

        // Check for array, if its anything else, throw an exception
        if (!is_array($data)) {
            throw new UnsupportedFormatException('PHP data does not return an array');
        }

        return $data;
    }
922107
public function render($filename, array $data = [])
    {
        $filename = $this->checkParseFile($filename, false);

        return $this->template->render($filename, $data);
    }
426329
public static function parse($filename = null)
    {
        // fetch netrc filename if it is not specified
        if (!$filename) {
            if (!$homePath = getenv('HOME')) {
                throw new ParseException("HOME environment variable must be set for correctly netrc handling");
            }
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $filename = strtr($homePath, '\\', '/') . '/_netrc';
            } else {
                $filename = rtrim($homePath, '/') . '/.netrc';
            }
        }
        $filename = realpath($filename);

        // check that netrc file is available
        if (!file_exists($filename) || !is_readable($filename) || !$content = file_get_contents($filename)) {
            throw new ParseException("netrc file does not exist or is not readable");
        }

        // parse file
        $parser = new Parser();
        return $parser->parse($content);
    }
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;
    }
877072
protected function _parseIniFile($filename)
    {
        set_error_handler(array($this, '_loadFileErrorHandler'));
        $iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed
        restore_error_handler();

        // Check if there was a error while loading file
        if ($this->_loadFileErrorStr !== null) {
            /**
             * @see Zend_Config_Exception
             */
            // require_once 'Zend/Config/Exception.php';
            throw new Zend_Config_Exception($this->_loadFileErrorStr);
        }

        return $iniArray;
    }
641052
public function getLogFilenameList($filename = null)
    {
        $data = [];

        if (empty($filename)) {
            $filename = '*.*';
        }

        $files = $this->getLogFileList($filename);

        if (is_array($files)) {
            foreach ($files as $file) {
                $basename = pathinfo($file, PATHINFO_BASENAME);
                $data[$basename] = $file;
            }
        }

        return $data;
    }
30296
static function read($filename) {
        if (file_exists($filename) && self::isReadable($filename)) {
            return file_get_contents($filename);
        }

        return NULL;
    }
877663
private function loadFile(string $filename) : array
    {
        Assertion::file($filename, 'File "' . $filename . '" does not exist.');
        Assertion::readable($filename, 'File "' . $filename . '" is not readable.');

        /** @var string $fileContent */
        $fileContent = file_get_contents($filename);

        Assertion::string($fileContent);

        if (preg_match('/[^ -~\s]/', $fileContent)) {
            throw new \RuntimeException('File "' . $filename . '" contains Non-ASCII-Characters.');
        }

        $jsonParser = new JsonParser();

        try {
            return $jsonParser->parse($fileContent, JsonParser::DETECT_KEY_CONFLICTS | JsonParser::PARSE_TO_ASSOC);
        } catch (ParsingException $e) {
            throw new \RuntimeException(
                'File "' . $filename . '" had invalid JSON.',
                0,
                $e
            );
        }
    }
179754
public function writeYamlFile($filename, $data)
    {
        try {
            // @todo Allow the inline and indent variables to be set via command line option.
            $yaml = Yaml::dump($data->export(), 3, 2);
        } catch (\Exception $e) {
            $this->output->writeln("<error>There was an error dumping the YAML contents for $filename.</error>");
            $this->output->writeln($e->getMessage());

            return false;
        }

        try {
            // @todo Use Symfony file system instead so that exceptions can be caught.
            file_put_contents($filename, $yaml);
        } catch (\Exception $e) {
            $this->output->writeln("<error>There was an writing to $filename.</error>");
            $this->output->writeln($e->getMessage());

            return false;
        }

        return true;
    }
486515
public function load($fname)
    {
        $this->fname = $fname;
        if (file_exists($this->fname)) {
            $contents = file_get_contents($this->fname);
            $this->data = json_decode($contents);
        } else {
            $this->data = json_decode("[]");
        }

        $data =& $this->data;
        return $data;
    }
400306
public function dataContainsImportFile($data, $filename)
    {
        if (!is_array($data) || !isset($data['imports']) || !is_array($data['imports'])) {
            return false;
        }

        foreach ($data['imports'] as $value) {
            if ($value['resource'] === $filename) {
                return true;
            }
        }

        return false;
    }
835893
public function getTemplateFile($filename, $data)
    {
        $data['getRegion'] = function($name) { 
            return $this->getRegion($name); 
            }; // This is for mustache compatibility

        // Push the data into regions and then pass a pointer to this class to the layout
        // $this->setRegions($data);
        return parent::getTemplateFile($filename, $data); // Pass in layout object to template
    }
842289
public function getView($filename, $data = null)
    {
        // $data = ($data === null) ? $this->_data : $data;
        return $this->getTemplateFile($this->getTemplateFolder().$filename, $data);
    }
301373
public function parse($stream, $filename = null)
    {
        $this->stream = $stream;
        $this->filename = $filename;
        $this->variables = array();

        return $this->parseMain();
    }
1246749
public function parse(string $filename): array
    {
        $urls = json_decode(file_get_contents($filename), true);

        if($urls === null) {
            throw new \ParseError('Could not parse ' . $filename);
        }

        return array_map(function($value) {
            $url = $this->getUrl($value['url']);

            return new Url(
                $url,
                $value['status'],
                $value['content'] ?? null,
                $value['content-type'] ?? null,
                $value['connect-timeout'] ?? $this->connectTimeout,
                $value['timeout'] ?? $this->timeout
            );
        }, $urls);
    }
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,
        ];

    }
1188920
public static function getYamlContents(string $filename)
    {
        $result = null;
        if (file_exists($filename)) {
            $result = Yaml::parse(file_get_contents($filename));
        }
        return $result;
    }