add event for rendering header & footer

This commit is contained in:
printempw 2016-12-10 19:36:01 +08:00
parent 91ff0fd2a7
commit 05edc193ae
3 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace App\Events;
class RenderingFooter extends Event
{
public $contents;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(array &$contents)
{
// pass array by reference
$this->contents = &$contents;
}
public function addContent($content)
{
if ($content) {
if (!is_string($content)) {
throw new \Exception("Can not add non-string content", 1);
}
$this->contents[] = $content;
}
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Events;
class RenderingHeader extends Event
{
public $contents;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(array &$contents)
{
// pass array by reference
$this->contents = &$contents;
}
public function addContent($content)
{
if ($content) {
if (!is_string($content)) {
throw new \Exception("Can not add non-string content", 1);
}
$this->contents[] = $content;
}
}
}

View File

@ -109,6 +109,12 @@ if (! function_exists('bs_footer')) {
}
echo '<script>'.Option::get("custom_js").'</script>';
$extra_contents = [];
Event::fire(new App\Events\RenderingFooter($extra_contents));
echo implode(PHP_EOL, $extra_contents);
}
}
@ -130,6 +136,12 @@ if (! function_exists('bs_header')) {
}
echo '<style>'.Option::get("custom_css").'</style>';
$extra_contents = [];
Event::fire(new App\Events\RenderingHeader($extra_contents));
echo implode(PHP_EOL, $extra_contents);
}
}