[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_scheduler/src/Task/ -> TaskOption.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_scheduler
   6   *
   7   * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Scheduler\Administrator\Task;
  12  
  13  use Joomla\CMS\Language\Text;
  14  use Joomla\CMS\Log\Log;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('_JEXEC') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * The TaskOption class is used as a utility container for available plugin-provided task routines.
  22   * Each task-supporting plugin calls the {@see TaskOptions::addOptions()} method with an array of TaskOption constructor
  23   * argument pairs as argument. Internally, the TaskOption object generates the routine title and description from the
  24   * language constant prefix.
  25   *
  26   * @since  4.1.0
  27   *
  28   * @property-read  string $desc             The routine description.
  29   * @property-read  string $id               The routine ID.
  30   * @property-read  string $langConstPrefix  The routine's language constant prefix.
  31   * @property-read  string $title            The routine title.
  32   */
  33  class TaskOption
  34  {
  35      /**
  36       * Task routine title
  37       *
  38       * @var string
  39       * @since  4.1.0
  40       */
  41      protected $title;
  42  
  43      /**
  44       * Task routine description.
  45       *
  46       * @var string
  47       * @since  4.1.0
  48       */
  49      protected $desc;
  50  
  51      /**
  52       * Routine type-ID.
  53       *
  54       * @var string
  55       * @since  4.1.0
  56       */
  57      protected $id;
  58  
  59      /**
  60       * @var string
  61       * @since  4.1.0
  62       */
  63      protected $langConstPrefix;
  64  
  65      /**
  66       * TaskOption constructor.
  67       *
  68       * @param   string  $type             A unique ID string for a plugin task routine.
  69       * @param   string  $langConstPrefix  The Language constant prefix $p. Expects $p . _TITLE and $p . _DESC to exist.
  70       *
  71       * @since  4.1.0
  72       */
  73      public function __construct(string $type, string $langConstPrefix)
  74      {
  75          $this->id              = $type;
  76          $this->title           = Text::_("$langConstPrefix}_TITLE");
  77          $this->desc            = Text::_("$langConstPrefix}_DESC");
  78          $this->langConstPrefix = $langConstPrefix;
  79      }
  80  
  81      /**
  82       * Magic method to allow read-only access to private properties.
  83       *
  84       * @param   string  $name  The object property requested.
  85       *
  86       * @return  ?string
  87       *
  88       * @since  4.1.0
  89       */
  90      public function __get(string $name)
  91      {
  92          if (property_exists($this, $name)) {
  93              return $this->$name;
  94          }
  95  
  96          // Trigger a deprecation for the 'type' property (replaced with {@see id}).
  97          if ($name === 'type') {
  98              try {
  99                  Log::add(
 100                      sprintf(
 101                          'The %1$s property is deprecated. Use %2$s instead.',
 102                          $name,
 103                          'id'
 104                      ),
 105                      Log::WARNING,
 106                      'deprecated'
 107                  );
 108              } catch (\RuntimeException $e) {
 109                  // Pass
 110              }
 111  
 112              return $this->id;
 113          }
 114  
 115          return null;
 116      }
 117  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer