Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   1  <?php
   2  
   3  declare(strict_types=1);
   4  /**
   5   * SimplePie
   6   *
   7   * A PHP-Based RSS and Atom Feed Framework.
   8   * Takes the hard work out of managing a complete RSS/Atom solution.
   9   *
  10   * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
  11   * All rights reserved.
  12   *
  13   * Redistribution and use in source and binary forms, with or without modification, are
  14   * permitted provided that the following conditions are met:
  15   *
  16   * 	 * Redistributions of source code must retain the above copyright notice, this list of
  17   * 	   conditions and the following disclaimer.
  18   *
  19   * 	 * Redistributions in binary form must reproduce the above copyright notice, this list
  20   * 	   of conditions and the following disclaimer in the documentation and/or other materials
  21   * 	   provided with the distribution.
  22   *
  23   * 	 * Neither the name of the SimplePie Team nor the names of its contributors may be used
  24   * 	   to endorse or promote products derived from this software without specific prior
  25   * 	   written permission.
  26   *
  27   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  28   * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  29   * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  30   * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  34   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35   * POSSIBILITY OF SUCH DAMAGE.
  36   *
  37   * @package SimplePie
  38   * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
  39   * @author Ryan Parman
  40   * @author Sam Sneddon
  41   * @author Ryan McCue
  42   * @link http://simplepie.org/ SimplePie
  43   * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  44   */
  45  
  46  namespace SimplePie;
  47  
  48  use SimplePie\Cache\Base;
  49  
  50  /**
  51   * Used to create cache objects
  52   *
  53   * This class can be overloaded with {@see SimplePie::set_cache_class()},
  54   * although the preferred way is to create your own handler
  55   * via {@see register()}
  56   *
  57   * @package SimplePie
  58   * @subpackage Caching
  59   * @deprecated since SimplePie 1.8.0, use "SimplePie\SimplePie::set_cache()" instead
  60   */
  61  class Cache
  62  {
  63      /**
  64       * Cache handler classes
  65       *
  66       * These receive 3 parameters to their constructor, as documented in
  67       * {@see register()}
  68       * @var array
  69       */
  70      protected static $handlers = [
  71          'mysql'     => 'SimplePie\Cache\MySQL',
  72          'memcache'  => 'SimplePie\Cache\Memcache',
  73          'memcached' => 'SimplePie\Cache\Memcached',
  74          'redis'     => 'SimplePie\Cache\Redis'
  75      ];
  76  
  77      /**
  78       * Don't call the constructor. Please.
  79       */
  80      private function __construct()
  81      {
  82      }
  83  
  84      /**
  85       * Create a new SimplePie\Cache object
  86       *
  87       * @param string $location URL location (scheme is used to determine handler)
  88       * @param string $filename Unique identifier for cache object
  89       * @param Base::TYPE_FEED|Base::TYPE_IMAGE $extension 'spi' or 'spc'
  90       * @return Base Type of object depends on scheme of `$location`
  91       */
  92      public static function get_handler($location, $filename, $extension)
  93      {
  94          $type = explode(':', $location, 2);
  95          $type = $type[0];
  96          if (!empty(self::$handlers[$type])) {
  97              $class = self::$handlers[$type];
  98              return new $class($location, $filename, $extension);
  99          }
 100  
 101          return new \SimplePie\Cache\File($location, $filename, $extension);
 102      }
 103  
 104      /**
 105       * Create a new SimplePie\Cache object
 106       *
 107       * @deprecated since SimplePie 1.3.1, use {@see get_handler()} instead
 108       */
 109      public function create($location, $filename, $extension)
 110      {
 111          trigger_error('Cache::create() has been replaced with Cache::get_handler() since SimplePie 1.3.1, use the registry system instead.', \E_USER_DEPRECATED);
 112  
 113          return self::get_handler($location, $filename, $extension);
 114      }
 115  
 116      /**
 117       * Register a handler
 118       *
 119       * @param string $type DSN type to register for
 120       * @param class-string<Base> $class Name of handler class. Must implement Base
 121       */
 122      public static function register($type, $class)
 123      {
 124          self::$handlers[$type] = $class;
 125      }
 126  
 127      /**
 128       * Parse a URL into an array
 129       *
 130       * @param string $url
 131       * @return array
 132       */
 133      public static function parse_URL($url)
 134      {
 135          $params = parse_url($url);
 136          $params['extras'] = [];
 137          if (isset($params['query'])) {
 138              parse_str($params['query'], $params['extras']);
 139          }
 140          return $params;
 141      }
 142  }
 143  
 144  class_alias('SimplePie\Cache', 'SimplePie_Cache');