-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathHelloWorld.php
55 lines (49 loc) · 1.4 KB
/
HelloWorld.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace lo\plugins\core\helloworld;
use lo\plugins\BasePlugin;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\web\Response;
/**
* Plugin Name: Hello World
* Plugin URI: https://github.com/loveorigami/yii2-plugins-system/tree/master/src/core/helloworld
* Version: 1.9
* Description: A simple hello world plugin
* Author: Andrey Lukyanov
* Author URI: https://github.com/loveorigami
*/
class HelloWorld extends BasePlugin
{
/**
* @var array
*/
public static $config = [
'search' => 'Hello, world!',
'replace' => 'Hello, Yii!',
'color' => '#FFDB51'
];
/**
* @return array
*/
public static function events()
{
return [
Response::class => [
Response::EVENT_AFTER_PREPARE => ['hello', self::$config]
]
];
}
/**
* @param $event
*/
public static function hello($event)
{
if (!$content = $event->sender->content) return;
$search = ArrayHelper::getValue($event->data, 'search', self::$config['search']);
$replace = ArrayHelper::getValue($event->data, 'replace', self::$config['replace']);
$color = ArrayHelper::getValue($event->data, 'color', self::$config['color']);
$event->sender->content = str_replace($search, Html::tag('span', $replace, [
'style' => "background-color:$color;"
]), $content);
}
}