Fragen\GitHub_Updater\Base::get_file_headers PHP Метод

get_file_headers() защищенный Метод

Take remote file contents as string and parse headers.
protected get_file_headers ( $contents, $type ) : array
$contents
$type
Результат array
    protected function get_file_headers($contents, $type)
    {
        $default_plugin_headers = array('Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path', 'Network' => 'Network');
        $default_theme_headers = array('Name' => 'Theme Name', 'ThemeURI' => 'Theme URI', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'Version' => 'Version', 'Template' => 'Template', 'Status' => 'Status', 'Tags' => 'Tags', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path');
        if (false !== strpos($type, 'plugin')) {
            $all_headers = $default_plugin_headers;
        }
        if (false !== strpos($type, 'theme')) {
            $all_headers = $default_theme_headers;
        }
        /*
         * Make sure we catch CR-only line endings.
         */
        $file_data = str_replace("\r", "\n", $contents);
        /*
         * Merge extra headers and default headers.
         */
        $all_headers = array_merge(self::$extra_headers, (array) $all_headers);
        $all_headers = array_unique($all_headers);
        foreach ($all_headers as $field => $regex) {
            if (preg_match('/^[ \\t\\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $file_data, $match) && $match[1]) {
                $all_headers[$field] = _cleanup_header_comment($match[1]);
            } else {
                $all_headers[$field] = '';
            }
        }
        // Reduce array to only headers with data.
        $all_headers = array_filter($all_headers, function ($e) use(&$all_headers) {
            return !empty($e);
        });
        return $all_headers;
    }