-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPlugin.php
executable file
·131 lines (115 loc) · 3.15 KB
/
Plugin.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* Webiny Framework (http://www.webiny.com/framework)
*
* @copyright Copyright Webiny LTD
*/
namespace Webiny\Component\TemplateEngine;
use Webiny\Component\StdLib\StdLibTrait;
/**
* Template engine plugin class.
* This class is used by template engines to register plugins.
* Based on the template engine a plugin can be a modifier, a tag, a filter or something else.
*
* @package Webiny\Component\TemplateEngine
*/
class Plugin
{
use StdLibTrait;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $type;
/**
* @var callable|string
*/
private $callbackFunction;
/**
* @var array
*/
private $params;
/**
* @var \Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject
*/
private $attributes;
/**
* Base constructor.
*
* @param string $name Plugin Name of the plugin.
* @param string $type Plugin type. The type value depends on the current template engine driver.
* They usually have values like "function", "tag", "modifier"..etc.
* Basically they define the type of the plugin.
* @param \Closure|string $callbackFunction Callback function that holds the plugin logic.
* @param array $params Optional parameters that can be passed to the plugin.
*/
public function __construct($name, $type, $callbackFunction, $params = [])
{
$this->name = $name;
$this->type = $type;
$this->callbackFunction = $callbackFunction;
$this->params = $params;
$this->attributes = $this->arr([]);
}
/**
* Sets an optional attribute to the plugin.
*
* @param string $key Attribute key.
* @param mixed $value Attribute value.
*/
public function setAttribute($key, $value)
{
$this->attributes->key($key, $value);
}
/**
* Return the attribute value under the defined $key.
*
* @param string $key Attribute key.
* @param mixed $defaultValue Default value that the method should return if $key is not found among the attributes.
*
* @return mixed
*/
public function getAttribute($key, $defaultValue = false)
{
return $this->attributes->key($key, $defaultValue, true);
}
/**
* Get plugin name.
*
* @return string Plugin name.
*/
public function getName()
{
return $this->name;
}
/**
* Get plugin type.
*
* @return string Plugin type.
*/
public function getType()
{
return $this->type;
}
/**
* Get the callable function.
*
* @return callable|string Plugin callable function.
*/
public function getCallbackFunction()
{
return $this->callbackFunction;
}
/**
* Get plugin parameters.
*
* @return array Plugin params.
*/
public function getParams()
{
return $this->params;
}
}