phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
63 stars 3 forks source link

Allow multiple extensions to handle the same event #29

Closed kylekatarnls closed 6 years ago

kylekatarnls commented 6 years ago

Right now, an event listener option can pass only one event callback and if an extension use it, it erase previous callback possibly put by an other extension.

Tasks:

Allow array (multiple callbacks) arguments for all event options.

...
'on_format' => [$callback1, $callback2, $callback3],
...

Merge events from extensions into an array

class Extension1 extends \Phug\AbstractExtension
{
  public function getEvents()
  {
    return [
      'on_format' => [$c1, $c2],
      'on_parse' => $c3,
    ];
  }
}
class Extension2 extends \Phug\AbstractExtension
{
  public function getEvents()
  {
    return [
      'on_format' => $c4,
      'on_output' => [$c5],
    ];
  }
}
Phug::addExtension(Extension1::class);
Phug::addExtension(Extension2::class);

Phug::getOptions() should then contains:

[
  'on_format' => [$c1, $c2, $c4],
  'on_parse'  => [$c3],
  'on_output' => [$c5],
]

Documents new event option feature

https://phug-lang.com/#events

kylekatarnls commented 6 years ago

Available in 0.3.2