[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\cron; 15 16 use phpbb\cron\task\wrapper; 17 use phpbb\routing\helper; 18 use Symfony\Component\DependencyInjection\ContainerInterface; 19 20 /** 21 * Cron manager class. 22 * 23 * Finds installed cron tasks, stores task objects, provides task selection. 24 */ 25 class manager 26 { 27 /** 28 * @var ContainerInterface 29 */ 30 protected $phpbb_container; 31 32 /** 33 * @var helper 34 */ 35 protected $routing_helper; 36 37 /** 38 * Set of \phpbb\cron\task\wrapper objects. 39 * Array holding all tasks that have been found. 40 * 41 * @var array 42 */ 43 protected $tasks = []; 44 45 /** 46 * Flag indicating if $this->tasks contains tasks registered in the container 47 * 48 * @var bool 49 */ 50 protected $is_initialised_from_container = false; 51 52 /** 53 * @var string 54 */ 55 protected $phpbb_root_path; 56 57 /** 58 * @var string 59 */ 60 protected $php_ext; 61 62 /** 63 * @var \phpbb\template\template 64 */ 65 protected $template; 66 67 /** 68 * Constructor. Loads all available tasks. 69 * 70 * @param ContainerInterface $phpbb_container Container 71 * @param helper $routing_helper Routing helper 72 * @param string $phpbb_root_path Relative path to phpBB root 73 * @param string $php_ext PHP file extension 74 * @param \phpbb\template\template $template 75 */ 76 public function __construct(ContainerInterface $phpbb_container, helper $routing_helper, $phpbb_root_path, $php_ext, $template) 77 { 78 $this->phpbb_container = $phpbb_container; 79 $this->routing_helper = $routing_helper; 80 $this->phpbb_root_path = $phpbb_root_path; 81 $this->php_ext = $php_ext; 82 $this->template = $template; 83 } 84 85 /** 86 * Loads tasks given by name, wraps them 87 * and puts them into $this->tasks. 88 * 89 * @param array|\Traversable $tasks Array of instances of \phpbb\cron\task\task 90 */ 91 public function load_tasks($tasks) 92 { 93 foreach ($tasks as $task) 94 { 95 $this->tasks[] = $this->wrap_task($task); 96 } 97 } 98 99 /** 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |