[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Cache/ -> CacheController.php (source)

   1  <?php
   2  /**
   3   * Joomla! Content Management System
   4   *
   5   * @copyright  (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
   6   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  namespace Joomla\CMS\Cache;
  10  
  11  \defined('JPATH_PLATFORM') or die;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Filesystem\Path;
  15  
  16  /**
  17   * Public cache handler
  18   *
  19   * @since  1.7.0
  20   * @note   As of 4.0 this class will be abstract
  21   */
  22  class CacheController
  23  {
  24      /**
  25       * Cache object
  26       *
  27       * @var    Cache
  28       * @since  1.7.0
  29       */
  30      public $cache;
  31  
  32      /**
  33       * Array of options
  34       *
  35       * @var    array
  36       * @since  1.7.0
  37       */
  38      public $options;
  39  
  40      /**
  41       * Constructor
  42       *
  43       * @param   array  $options  Array of options
  44       *
  45       * @since   1.7.0
  46       */
  47  	public function __construct($options)
  48      {
  49          $this->cache = new Cache($options);
  50          $this->options = & $this->cache->_options;
  51  
  52          // Overwrite default options with given options
  53          foreach ($options as $option => $value)
  54          {
  55              if (isset($options[$option]))
  56              {
  57                  $this->options[$option] = $options[$option];
  58              }
  59          }
  60      }
  61  
  62      /**
  63       * Magic method to proxy CacheController method calls to Cache
  64       *
  65       * @param   string  $name       Name of the function
  66       * @param   array   $arguments  Array of arguments for the function
  67       *
  68       * @return  mixed
  69       *
  70       * @since   1.7.0
  71       */
  72  	public function __call($name, $arguments)
  73      {
  74          return \call_user_func_array(array($this->cache, $name), $arguments);
  75      }
  76  
  77      /**
  78       * Returns a reference to a cache adapter object, always creating it
  79       *
  80       * @param   string  $type     The cache object type to instantiate; default is output.
  81       * @param   array   $options  Array of options
  82       *
  83       * @return  CacheController
  84       *
  85       * @since       1.7.0
  86       * @throws      \RuntimeException
  87       * @deprecated  5.0 Use the cache controller factory instead
  88       */
  89  	public static function getInstance($type = 'output', $options = array())
  90      {
  91          @trigger_error(
  92              sprintf(
  93                  '%s() is deprecated. The cache controller should be fetched from the factory.',
  94                  __METHOD__
  95              ),
  96              E_USER_DEPRECATED
  97          );
  98  
  99          try
 100          {
 101              return Factory::getContainer()->get(CacheControllerFactoryInterface::class)->createCacheController($type, $options);
 102          }
 103          catch (\RuntimeException $e)
 104          {
 105              $type  = strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $type));
 106              $class = 'JCacheController' . ucfirst($type);
 107  
 108              if (!class_exists($class))
 109              {
 110                  // Search for the class file in the Cache include paths.
 111                  $path = Path::find(self::addIncludePath(), strtolower($type) . '.php');
 112  
 113                  if ($path !== false)
 114                  {
 115                      \JLoader::register($class, $path);
 116                  }
 117  
 118                  // The class should now be loaded
 119                  if (!class_exists($class))
 120                  {
 121                      throw new \RuntimeException('Unable to load Cache Controller: ' . $type, 500);
 122                  }
 123  
 124                  // Only trigger a deprecation notice if the file and class are found
 125                  @trigger_error(
 126                      'Support for including cache controllers using path lookup is deprecated and will be removed in 5.0.'
 127                      . ' Use a custom cache controller factory instead.',
 128                      E_USER_DEPRECATED
 129                  );
 130              }
 131  
 132              return new $class($options);
 133          }
 134      }
 135  
 136      /**
 137       * Add a directory where Cache should search for controllers. You may either pass a string or an array of directories.
 138       *
 139       * @param   array|string  $path  A path to search.
 140       *
 141       * @return  array  An array with directory elements
 142       *
 143       * @since       1.7.0
 144       * @deprecated  5.0 Use the cache controller factory instead
 145       */
 146  	public static function addIncludePath($path = '')
 147      {
 148          static $paths;
 149  
 150          if (!isset($paths))
 151          {
 152              $paths = array();
 153          }
 154  
 155          if (!empty($path) && !\in_array($path, $paths))
 156          {
 157              // Only trigger a deprecation notice when adding a lookup path
 158              @trigger_error(
 159                  'Support for including cache controllers using path lookup is deprecated and will be removed in 5.0.'
 160                  . ' Use a custom cache controller factory instead.',
 161                  E_USER_DEPRECATED
 162              );
 163  
 164              array_unshift($paths, Path::clean($path));
 165          }
 166  
 167          return $paths;
 168      }
 169  }


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