Fire onMetaHeaders event only once, cache results of Pico::getMetaHeaders()

This commit is contained in:
Daniel Rudolf 2016-12-06 20:01:38 +01:00
parent 82c6dd9795
commit bc5729629d
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538

View file

@ -153,6 +153,14 @@ class Pico
*/
protected $is404Content = false;
/**
* List of known meta headers
*
* @see Pico::getMetaHeaders()
* @var string[]|null
*/
protected $metaHeaders;
/**
* Meta data of the page to serve
*
@ -344,10 +352,11 @@ class Pico
$this->triggerEvent('onContentLoaded', array(&$this->rawContent));
// parse file meta
$headers = $this->getMetaHeaders();
$this->metaHeaders = $this->getMetaHeaders();
$this->triggerEvent('onMetaHeaders', array(&$this->metaHeaders));
$this->triggerEvent('onMetaParsing', array(&$this->rawContent, &$headers));
$this->meta = $this->parseFileMeta($this->rawContent, $headers);
$this->triggerEvent('onMetaParsing', array(&$this->rawContent, &$this->metaHeaders));
$this->meta = $this->parseFileMeta($this->rawContent, $this->metaHeaders);
$this->triggerEvent('onMetaParsed', array(&$this->meta));
// register parsedown
@ -960,10 +969,7 @@ class Pico
}
/**
* Returns known meta headers and triggers the onMetaHeaders event
*
* Heads up! Calling this method triggers the `onMetaHeaders` event.
* Keep this in mind to prevent a infinite loop!
* Returns known meta headers
*
* @return string[] known meta headers; the array value specifies the
* YAML key to search for, the array key is later used to access the
@ -971,7 +977,11 @@ class Pico
*/
public function getMetaHeaders()
{
$headers = array(
if ($this->metaHeaders !== null) {
return $this->metaHeaders;
}
return array(
'title' => 'Title',
'description' => 'Description',
'author' => 'Author',
@ -979,9 +989,6 @@ class Pico
'robots' => 'Robots',
'template' => 'Template'
);
$this->triggerEvent('onMetaHeaders', array(&$headers));
return $headers;
}
/**