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