1 | <?php |
||
18 | class TaskManager |
||
19 | { |
||
20 | /** |
||
21 | * All registered tasks to run on shutdown, after the response is sent. |
||
22 | * |
||
23 | * @see TaskManager::addTask() To add a TaskInterface class |
||
24 | * @var TaskInterface[] |
||
25 | */ |
||
26 | private $tasks = []; |
||
27 | |||
28 | /** |
||
29 | * All enabled plugins to be executed on kernel.response and kernel.terminate events. |
||
30 | * |
||
31 | * @see TaskManager::addPlugin() |
||
32 | * @var PluginInterface[] |
||
33 | */ |
||
34 | private $plugins = []; |
||
35 | |||
36 | /** |
||
37 | * @var boolean |
||
38 | */ |
||
39 | private $masterRequest = true; |
||
40 | |||
41 | /** |
||
42 | * Determines whether Tasks should be executed |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $enabled = true; |
||
47 | |||
48 | /** |
||
49 | * Adds a registered task. |
||
50 | * Tasks can be added by: |
||
51 | * 1. Tagging TaskInterface services through DI. |
||
52 | * 2. Implementing a TaskInterface class and mannually adding it |
||
53 | * |
||
54 | * All tasks must be registered before Response::send() is called by Symfony. |
||
55 | * |
||
56 | * @param TaskInterface $task The task to run |
||
57 | * @param int $priority The priority: a higher value runs first. Default 0. |
||
58 | * @return self |
||
59 | */ |
||
60 | public function addTask(TaskInterface $task, $priority = 0) |
||
74 | |||
75 | /** |
||
76 | * Adds an enabled plugin to be utilized in relevant methods below. |
||
77 | * |
||
78 | * @see TaskManager::execute() |
||
79 | * @see TaskManager::filterResponse() |
||
80 | * |
||
81 | * @param PluginInterface $plugin The plugin to add |
||
82 | * @return self |
||
83 | */ |
||
84 | public function addPlugin(PluginInterface $plugin) |
||
89 | |||
90 | /** |
||
91 | * Gets all registered tasks |
||
92 | * |
||
93 | * @return TaskInterface[] |
||
94 | */ |
||
95 | public function getTasks() |
||
103 | |||
104 | /** |
||
105 | * Gets all registered tasks |
||
106 | * |
||
107 | * @return PluginInterface[] |
||
108 | */ |
||
109 | public function getPlugins() |
||
113 | |||
114 | /** |
||
115 | * Determines if tasks are registered |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | public function hasTasks() |
||
124 | |||
125 | /** |
||
126 | * Determines if plugins are registered |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function hasPlugins() |
||
135 | |||
136 | /** |
||
137 | * Enables the TaskManager for executing Tasks |
||
138 | * |
||
139 | * @return self |
||
140 | */ |
||
141 | public function enable() |
||
146 | |||
147 | /** |
||
148 | * Disables the TaskManager from executing Tasks |
||
149 | * |
||
150 | * @return self |
||
151 | */ |
||
152 | public function disable() |
||
157 | |||
158 | /** |
||
159 | * Determines if the TaskManager is enabled for executing Tasks |
||
160 | * |
||
161 | * @return bool |
||
162 | */ |
||
163 | public function isEnabled() |
||
167 | |||
168 | /** |
||
169 | * Executes the post-response Tasks. |
||
170 | * Is called via Symfony's kernel.terminate event. |
||
171 | * |
||
172 | * @param PostResponseEvent $event |
||
173 | */ |
||
174 | public function execute(PostResponseEvent $event) |
||
193 | |||
194 | /** |
||
195 | * Sets the HTTP headers required to execute post-response Tasks. |
||
196 | * Is called via Symfony's kernel.response event. |
||
197 | * |
||
198 | * @param FilterResponseEvent $event |
||
199 | * @return Response |
||
200 | */ |
||
201 | public function filterResponse(FilterResponseEvent $event) |
||
244 | } |
||
245 |