[ 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\task; 15 16 use phpbb\routing\helper; 17 18 /** 19 * Cron task wrapper class. 20 * Enhances cron tasks with convenience methods that work identically for all tasks. 21 */ 22 class wrapper 23 { 24 /** 25 * @var helper 26 */ 27 protected $routing_helper; 28 29 /** 30 * @var task 31 */ 32 protected $task; 33 34 /** 35 * @var string 36 */ 37 protected $phpbb_root_path; 38 39 /** 40 * @var string 41 */ 42 protected $php_ext; 43 44 /** 45 * @var \phpbb\template\template 46 */ 47 protected $template; 48 49 /** 50 * Constructor. 51 * 52 * Wraps a task $task, which must implement cron_task interface. 53 * 54 * @param task $task The cron task to wrap. 55 * @param helper $routing_helper Routing helper for route generation 56 * @param string $phpbb_root_path Relative path to phpBB root 57 * @param string $php_ext PHP file extension 58 * @param \phpbb\template\template $template 59 */ 60 public function __construct(task $task, helper $routing_helper, $phpbb_root_path, $php_ext, $template) 61 { 62 $this->task = $task; 63 $this->routing_helper = $routing_helper; 64 $this->phpbb_root_path = $phpbb_root_path; 65 $this->php_ext = $php_ext; 66 $this->template = $template; 67 } 68 69 /** 70 * Returns whether the wrapped task is parametrised. 71 * 72 * Parametrized tasks accept parameters during initialization and must 73 * normally be scheduled with parameters. 74 * 75 * @return bool Whether or not this task is parametrized. 76 */ 77 public function is_parametrized() 78 { 79 return $this->task instanceof parametrized; 80 } 81 82 /** 83 * Returns whether the wrapped task is ready to run. 84 * 85 * A task is ready to run when it is runnable according to current configuration 86 * and enough time has passed since it was last run. 87 * 88 * @return bool Whether the wrapped task is ready to run. 89 */ 90 public function is_ready() 91 { 92 return $this->task->is_runnable() && $this->task->should_run(); 93 } 94 95 /** 96 * Returns a url through which this task may be invoked via web. 97 * 98 * When system cron is not in use, running a cron task is accomplished 99 * by outputting an image with the url returned by this function as 100 * source. 101 * 102 * @return string URL through which this task may be invoked. 103 */ 104 public function get_url() 105 { 106 $params['cron_type'] = $this->get_name(); 107 if ($this->is_parametrized()) 108 { 109 $params = array_merge($params, $this->task->get_parameters()); 110 } 111 112 return $this->routing_helper->route('phpbb_cron_run', $params); 113 } 114 115 /** 116 * Returns HTML for an invisible `img` tag that can be displayed on page 117 * load to trigger a request to the relevant cron task endpoint. 118 * 119 * @return string HTML to render to trigger cron task 120 */ 121 public function get_html_tag() 122 { 123 $this->template->set_filenames([ 124 'cron_html_tag' => 'cron.html', 125 ]); 126 127 $this->template->assign_var('CRON_TASK_URL', $this->get_url()); 128 129 return $this->template->assign_display('cron_html_tag'); 130 } 131 132 /** 133 * Forwards all other method calls to the wrapped task implementation. 134 * 135 * @return mixed 136 */ 137 public function __call($name, $args) 138 { 139 return call_user_func_array(array($this->task, $name), $args); 140 } 141 }
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 |