[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/cron/ -> manager.php (source)

   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  /**
  17  * Cron manager class.
  18  *
  19  * Finds installed cron tasks, stores task objects, provides task selection.
  20  */
  21  class manager
  22  {
  23      /**
  24      * Set of \phpbb\cron\task\wrapper objects.
  25      * Array holding all tasks that have been found.
  26      *
  27      * @var array
  28      */
  29      protected $tasks = array();
  30  
  31      protected $phpbb_root_path;
  32      protected $php_ext;
  33  
  34      /**
  35      * Constructor. Loads all available tasks.
  36      *
  37      * @param array|\Traversable $tasks Provides an iterable set of task names
  38      * @param string $phpbb_root_path Relative path to phpBB root
  39      * @param string $php_ext PHP file extension
  40      */
  41  	public function __construct($tasks, $phpbb_root_path, $php_ext)
  42      {
  43          $this->phpbb_root_path = $phpbb_root_path;
  44          $this->php_ext = $php_ext;
  45  
  46          $this->load_tasks($tasks);
  47      }
  48  
  49      /**
  50      * Loads tasks given by name, wraps them
  51      * and puts them into $this->tasks.
  52      *
  53      * @param array|\Traversable $tasks        Array of instances of \phpbb\cron\task\task
  54      *
  55      * @return null
  56      */
  57  	public function load_tasks($tasks)
  58      {
  59          foreach ($tasks as $task)
  60          {
  61              $this->tasks[] = $this->wrap_task($task);
  62          }
  63      }
  64  
  65      /**
  66      * Finds a task that is ready to run.
  67      *
  68      * If several tasks are ready, any one of them could be returned.
  69      *
  70      * If no tasks are ready, null is returned.
  71      *
  72      * @return \phpbb\cron\task\wrapper|null
  73      */
  74  	public function find_one_ready_task()
  75      {
  76          shuffle($this->tasks);
  77          foreach ($this->tasks as $task)
  78          {
  79              if ($task->is_ready())
  80              {
  81                  return $task;
  82              }
  83          }
  84          return null;
  85      }
  86  
  87      /**
  88      * Finds all tasks that are ready to run.
  89      *
  90      * @return array        List of tasks which are ready to run (wrapped in \phpbb\cron\task\wrapper).
  91      */
  92  	public function find_all_ready_tasks()
  93      {
  94          $tasks = array();
  95          foreach ($this->tasks as $task)
  96          {
  97              if ($task->is_ready())
  98              {
  99                  $tasks[] = $task;
 100              }
 101          }
 102          return $tasks;
 103      }
 104  
 105      /**
 106      * Finds a task by name.
 107      *
 108      * If there is no task with the specified name, null is returned.
 109      *
 110      * Web runner uses this method to resolve names to tasks.
 111      *
 112      * @param string                $name Name of the task to look up.
 113      * @return \phpbb\cron\task\wrapper    A wrapped task corresponding to the given name, or null.
 114      */
 115  	public function find_task($name)
 116      {
 117          foreach ($this->tasks as $task)
 118          {
 119              if ($task->get_name() == $name)
 120              {
 121                  return $task;
 122              }
 123          }
 124          return null;
 125      }
 126  
 127      /**
 128      * Find all tasks and return them.
 129      *
 130      * @return array List of all tasks.
 131      */
 132  	public function get_tasks()
 133      {
 134          return $this->tasks;
 135      }
 136  
 137      /**
 138      * Wraps a task inside an instance of \phpbb\cron\task\wrapper.
 139      *
 140      * @param  \phpbb\cron\task\task             $task The task.
 141      * @return \phpbb\cron\task\wrapper    The wrapped task.
 142      */
 143  	public function wrap_task(\phpbb\cron\task\task $task)
 144      {
 145          return new \phpbb\cron\task\wrapper($task, $this->phpbb_root_path, $this->php_ext);
 146      }
 147  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1