Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
manager.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\cron;
015
016 use phpbb\cron\task\wrapper;
017 use phpbb\routing\helper;
018 use Symfony\Component\DependencyInjection\ContainerInterface;
019
020 /**
021 * Cron manager class.
022 *
023 * Finds installed cron tasks, stores task objects, provides task selection.
024 */
025 class manager
026 {
027 /**
028 * @var ContainerInterface
029 */
030 protected $phpbb_container;
031
032 /**
033 * @var helper
034 */
035 protected $routing_helper;
036
037 /**
038 * Set of \phpbb\cron\task\wrapper objects.
039 * Array holding all tasks that have been found.
040 *
041 * @var array
042 */
043 protected $tasks = [];
044
045 /**
046 * Flag indicating if $this->tasks contains tasks registered in the container
047 *
048 * @var bool
049 */
050 protected $is_initialised_from_container = false;
051
052 /**
053 * @var string
054 */
055 protected $phpbb_root_path;
056
057 /**
058 * @var string
059 */
060 protected $php_ext;
061
062 /**
063 * @var \phpbb\template\template
064 */
065 protected $template;
066
067 /**
068 * Constructor. Loads all available tasks.
069 *
070 * @param ContainerInterface $phpbb_container Container
071 * @param helper $routing_helper Routing helper
072 * @param string $phpbb_root_path Relative path to phpBB root
073 * @param string $php_ext PHP file extension
074 * @param \phpbb\template\template $template
075 */
076 public function __construct(ContainerInterface $phpbb_container, helper $routing_helper, $phpbb_root_path, $php_ext, $template)
077 {
078 $this->phpbb_container = $phpbb_container;
079 $this->routing_helper = $routing_helper;
080 $this->phpbb_root_path = $phpbb_root_path;
081 $this->php_ext = $php_ext;
082 $this->template = $template;
083 }
084
085 /**
086 * Loads tasks given by name, wraps them
087 * and puts them into $this->tasks.
088 *
089 * @param array|\Traversable $tasks Array of instances of \phpbb\cron\task\task
090 */
091 public function load_tasks($tasks)
092 {
093 foreach ($tasks as $task)
094 {
095 $this->tasks[] = $this->wrap_task($task);
096 }
097 }
098
099 /**
100 * Loads registered tasks from the container, wraps them
101 * and puts them into $this->tasks.
102 */
103 public function load_tasks_from_container()
104 {
105 if (!$this->is_initialised_from_container)
106 {
107 $this->is_initialised_from_container = true;
108
109 $tasks = $this->phpbb_container->get('cron.task_collection');
110
111 $this->load_tasks($tasks);
112 }
113 }
114
115 /**
116 * Finds a task that is ready to run.
117 *
118 * If several tasks are ready, any one of them could be returned.
119 *
120 * If no tasks are ready, null is returned.
121 *
122 * @return wrapper|null
123 */
124 public function find_one_ready_task()
125 {
126 $this->load_tasks_from_container();
127
128 shuffle($this->tasks);
129 foreach ($this->tasks as $task)
130 {
131 if ($task->is_ready())
132 {
133 return $task;
134 }
135 }
136 return null;
137 }
138
139 /**
140 * Finds all tasks that are ready to run.
141 *
142 * @return array List of tasks which are ready to run (wrapped in \phpbb\cron\task\wrapper).
143 */
144 public function find_all_ready_tasks()
145 {
146 $this->load_tasks_from_container();
147
148 $tasks = [];
149 foreach ($this->tasks as $task)
150 {
151 if ($task->is_ready())
152 {
153 $tasks[] = $task;
154 }
155 }
156 return $tasks;
157 }
158
159 /**
160 * Finds a task by name.
161 *
162 * If there is no task with the specified name, null is returned.
163 *
164 * Web runner uses this method to resolve names to tasks.
165 *
166 * @param string $name Name of the task to look up.
167 * @return wrapper A wrapped task corresponding to the given name, or null.
168 */
169 public function find_task($name)
170 {
171 $this->load_tasks_from_container();
172
173 foreach ($this->tasks as $task)
174 {
175 if ($task->get_name() == $name)
176 {
177 return $task;
178 }
179 }
180 return null;
181 }
182
183 /**
184 * Find all tasks and return them.
185 *
186 * @return array List of all tasks.
187 */
188 public function get_tasks()
189 {
190 $this->load_tasks_from_container();
191
192 return $this->tasks;
193 }
194
195 /**
196 * Wraps a task inside an instance of \phpbb\cron\task\wrapper.
197 *
198 * @param \phpbb\cron\task\task $task The task.
199 * @return wrapper The wrapped task.
200 */
201 public function wrap_task(\phpbb\cron\task\task $task)
202 {
203 return new wrapper($task, $this->routing_helper, $this->phpbb_root_path, $this->php_ext, $this->template);
204 }
205 }
206