lib/Pico.php
public function parseFileMeta($rawContent, array $headers)
    {
        $meta = array();
        $pattern = "/^(\/(\*)|---)[[:blank:]]*(?:\r)?\n"
            . "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s";
        if (preg_match($pattern, $rawContent, $rawMetaMatches) && isset($rawMetaMatches[3])) {
            $meta = $this->getYamlParser()->parse($rawMetaMatches[3]) ?: array();
            $meta = is_array($meta) ? $meta : array('title' => $meta);

            foreach ($headers as $name => $key) {
                if (isset($meta[$name])) {
                    // rename field (e.g. remove whitespaces)
                    if ($key != $name) {
                        $meta[$key] = $meta[$name];
                        unset($meta[$name]);
                    }
                } elseif (!isset($meta[$key])) {
                    // guarantee array key existance
                    $meta[$key] = '';
                }
            }

            if (!empty($meta['date']) || !empty($meta['time'])) {
                // workaround for issue #336
                // Symfony YAML interprets ISO-8601 datetime strings and returns timestamps instead of the string
                // this behavior conforms to the YAML standard, i.e. this is no bug of Symfony YAML
                if (is_int($meta['date'])) {
                    $meta['time'] = $meta['date'];
                    $meta['date'] = '';
                }

                if (empty($meta['time'])) {
                    $meta['time'] = strtotime($meta['date']) ?: '';
                } elseif (empty($meta['date'])) {
                    $rawDateFormat = (date('H:i:s', $meta['time']) === '00:00:00') ? 'Y-m-d' : 'Y-m-d H:i:s';
                    $meta['date'] = date($rawDateFormat, $meta['time']);
                }
            } else {
                $meta['date'] = $meta['time'] = '';
            }

            if (empty($meta['date_formatted'])) {
                $dateFormat = $this->getConfig('date_format');
                $meta['date_formatted'] = $meta['time'] ? utf8_encode(strftime($dateFormat, $meta['time'])) : '';
            }
        } else {
            // guarantee array key existance
            $meta = array_fill_keys($headers, '');
        }

        return $meta;
    }
public function parseFileMeta($rawContent, array $headers)
    {
        $meta = array();
        $pattern = "/^(\/(\*)|---)[[:blank:]]*(?:\r)?\n"
            . "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s";
        if (preg_match($pattern, $rawContent, $rawMetaMatches) && isset($rawMetaMatches[3])) {
            $meta = $this->getYamlParser()->parse($rawMetaMatches[3]) ?: array();
            $meta = is_array($meta) ? $meta : array('title' => $meta);

            foreach ($headers as $name => $key) {
                if (isset($meta[$name])) {
                    // rename field (e.g. remove whitespaces)
                    if ($key != $name) {
                        $meta[$key] = $meta[$name];
                        unset($meta[$name]);
                    }
                } elseif (!isset($meta[$key])) {
                    // guarantee array key existance
                    $meta[$key] = '';
                }
            }

            if (!empty($meta['date']) || !empty($meta['time'])) {
                // workaround for issue #336
                // Symfony YAML interprets ISO-8601 datetime strings and returns timestamps instead of the string
                // this behavior conforms to the YAML standard, i.e. this is no bug of Symfony YAML
                if (is_int($meta['date'])) {
                    $meta['time'] = $meta['date'];
                    $meta['date'] = '';
                }

                if (empty($meta['time'])) {
                    $meta['time'] = strtotime($meta['date']) ?: '';
                } elseif (empty($meta['date'])) {
                    $rawDateFormat = (date('H:i:s', $meta['time']) === '00:00:00') ? 'Y-m-d' : 'Y-m-d H:i:s';
                    $meta['date'] = date($rawDateFormat, $meta['time']);
                }
            } else {
                $meta['date'] = $meta['time'] = '';
            }

            if (empty($meta['date_formatted'])) {
                $dateFormat = $this->getConfig('date_format');
                $meta['date_formatted'] = $meta['time'] ? utf8_encode(strftime($dateFormat, $meta['time'])) : '';
            }
        } else {
            // guarantee array key existance
            $meta = array_fill_keys($headers, '');
        }

        return $meta;
    }
public function parseFileMeta ( $ rawContent , array $ headers ) { $ meta = array ( ) ; $ pattern = "/^(\/(\*)|---)[[:blank:]]*(?:\r)?\n" . "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s" ; if ( preg_match ( $ pattern , $ rawContent , $ rawMetaMatches ) && isset ( $ rawMetaMatches [ 3 ] ) ) { $ meta = $ this -> getYamlParser ( ) -> parse ( $ rawMetaMatches [ 3 ] ) ? : array ( ) ; $ meta = is_array ( $ meta ) ? $ meta : array ( 'title' => $ meta ) ; foreach ( $ headers as $ name => $ key ) { if ( isset ( $ meta [ $ name ] ) ) { // rename field (e.g. remove whitespaces) if ( $ key != $ name ) { $ meta [ $ key ] = $ meta [ $ name ] ; unset ( $ meta [ $ name ] ) ; } } elseif ( ! isset ( $ meta [ $ key ] ) ) { // guarantee array key existance $ meta [ $ key ] = '' ; } } if ( ! empty ( $ meta [ 'date' ] ) || ! empty ( $ meta [ 'time' ] ) ) { // workaround for issue #336 // Symfony YAML interprets ISO-8601 datetime strings and returns timestamps instead of the string // this behavior conforms to the YAML standard, i.e. this is no bug of Symfony YAML if ( is_int ( $ meta [ 'date' ] ) ) { $ meta [ 'time' ] = $ meta [ 'date' ] ; $ meta [ 'date' ] = '' ; } if ( empty ( $ meta [ 'time' ] ) ) { $ meta [ 'time' ] = strtotime ( $ meta [ 'date' ] ) ? : '' ; } elseif ( empty ( $ meta [ 'date' ] ) ) { $ rawDateFormat = ( date ( 'H:i:s' , $ meta [ 'time' ] ) === '00:00:00' ) ? 'Y-m-d' : 'Y-m-d H:i:s' ; $ meta [ 'date' ] = date ( $ rawDateFormat , $ meta [ 'time' ] ) ; } } else { $ meta [ 'date' ] = $ meta [ 'time' ] = '' ; } if ( empty ( $ meta [ 'date_formatted' ] ) ) { $ dateFormat = $ this -> getConfig ( 'date_format' ) ; $ meta [ 'date_formatted' ] = $ meta [ 'time' ] ? utf8_encode ( strftime ( $ dateFormat , $ meta [ 'time' ] ) ) : '' ; } } else { // guarantee array key existance $ meta = array_fill_keys ( $ headers , '' ) ; } return $ meta ; }
Parses the file meta from raw file contents

Meta data MUST start on the first line of the file, either opened and
closed by `---` or C-style block comments (deprecated). The headers are
parsed by the YAML component of the Symfony project. If you're a plugin
developer, you MUST register new headers during the `onMetaHeaders`
event first. The implicit availability of headers is for users and
pure (!) theme developers ONLY.

@see Pico::getFileMeta()

@param string   $rawContent the raw file contents
@param string[] $headers    known meta headers

@return array parsed meta data

@throws \Symfony\Component\Yaml\Exception\ParseException thrown when the
meta data is invalid
Parses the file meta from raw file contents