Refactor onMetaHeaders event
This commit is contained in:
parent
f4332a247c
commit
80c88f2a7d
2 changed files with 31 additions and 29 deletions
32
lib/Pico.php
32
lib/Pico.php
|
@ -401,11 +401,8 @@ class Pico
|
|||
$this->triggerEvent('onContentLoaded', array(&$this->rawContent));
|
||||
|
||||
// parse file meta
|
||||
$this->metaHeaders = $this->getMetaHeaders();
|
||||
$this->triggerEvent('onMetaHeaders', array(&$this->metaHeaders));
|
||||
|
||||
$this->triggerEvent('onMetaParsing', array(&$this->rawContent, &$this->metaHeaders));
|
||||
$this->meta = $this->parseFileMeta($this->rawContent, $this->metaHeaders);
|
||||
$this->triggerEvent('onMetaParsing', array(&$this->rawContent));
|
||||
$this->meta = $this->parseFileMeta($this->rawContent, $this->getMetaHeaders());
|
||||
$this->triggerEvent('onMetaParsed', array(&$this->meta));
|
||||
|
||||
// parse file content
|
||||
|
@ -1091,24 +1088,29 @@ class Pico
|
|||
/**
|
||||
* Returns known meta headers
|
||||
*
|
||||
* This method triggers the `onMetaHeaders` event when the known meta
|
||||
* headers weren't assembled yet.
|
||||
*
|
||||
* @return string[] known meta headers; the array value specifies the
|
||||
* YAML key to search for, the array key is later used to access the
|
||||
* found value
|
||||
*/
|
||||
public function getMetaHeaders()
|
||||
{
|
||||
if ($this->metaHeaders !== null) {
|
||||
return $this->metaHeaders;
|
||||
if ($this->metaHeaders === null) {
|
||||
$this->metaHeaders = array(
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
'author' => 'Author',
|
||||
'date' => 'Date',
|
||||
'robots' => 'Robots',
|
||||
'template' => 'Template'
|
||||
);
|
||||
|
||||
$this->triggerEvent('onMetaHeaders', array(&$this->metaHeaders));
|
||||
}
|
||||
|
||||
return array(
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
'author' => 'Author',
|
||||
'date' => 'Date',
|
||||
'robots' => 'Robots',
|
||||
'template' => 'Template'
|
||||
);
|
||||
return $this->metaHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -162,20 +162,6 @@ class DummyPlugin extends AbstractPicoPlugin
|
|||
// your code
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered when Pico reads its known meta header fields
|
||||
*
|
||||
* @see Pico::getMetaHeaders()
|
||||
* @param string[] &$headers list of known meta header
|
||||
* fields; the array value specifies the YAML key to search for, the
|
||||
* array key is later used to access the found value
|
||||
* @return void
|
||||
*/
|
||||
public function onMetaHeaders(array &$headers)
|
||||
{
|
||||
// your code
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered before Pico parses the meta header
|
||||
*
|
||||
|
@ -387,6 +373,20 @@ class DummyPlugin extends AbstractPicoPlugin
|
|||
// your code
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered when Pico reads its known meta header fields
|
||||
*
|
||||
* @see Pico::getMetaHeaders()
|
||||
* @param string[] &$headers list of known meta header
|
||||
* fields; the array value specifies the YAML key to search for, the
|
||||
* array key is later used to access the found value
|
||||
* @return void
|
||||
*/
|
||||
public function onMetaHeaders(array &$headers)
|
||||
{
|
||||
// your code
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered when Pico registers the YAML parser
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue