Make WordPress Core


Ignore:
Timestamp:
09/30/2024 10:48:16 PM (6 weeks ago)
Author:
SergeyBiryukov
Message:

External Libraries: Update the SimplePie library to version 1.8.0.

The most notable change in this update is that all code is now namespaced and uses PSR-4 classes, though there is a compatibility layer available for extenders using the older class names, so plugin or theme authors directly using SimplePie can decide for themselves when they want to change to using the namespaced names for SimplePie classes.

Note: This commit includes additional fixes for PHP 8.4 compatibility (PR 875, PR 888) from the one-dot-eight branch of SimplePie, which is expected to be released as SimplePie 1.8.1 soon.

References:

Follow-up to [47733], [49176], [52393], [52413].

Props jrf, peterwilsoncc, chaion07, cu121, markparnell, audrasjb, costdev, Presskopp, desrosj, faisal03, mukesh27, SergeyBiryukov.
See #55604.

Location:
trunk/src/wp-includes/SimplePie/src
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/SimplePie/src/Cache.php

    r59140 r59141  
    11<?php
     2
    23/**
    34 * SimplePie
     
    67 * Takes the hard work out of managing a complete RSS/Atom solution.
    78 *
    8  * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
     9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
    910 * All rights reserved.
    1011 *
     
    4243 */
    4344
     45namespace SimplePie;
     46
     47use SimplePie\Cache\Base;
     48
    4449/**
    4550 * Used to create cache objects
     
    5156 * @package SimplePie
    5257 * @subpackage Caching
     58 * @deprecated since SimplePie 1.8.0, use "SimplePie\SimplePie::set_cache()" instead
    5359 */
    54 class SimplePie_Cache
     60class Cache
    5561{
    56     /**
    57     * Cache handler classes
    58     *
    59     * These receive 3 parameters to their constructor, as documented in
    60     * {@see register()}
    61     * @var array
    62     */
    63     protected static $handlers = array(
    64         'mysql'     => 'SimplePie_Cache_MySQL',
    65         'memcache'  => 'SimplePie_Cache_Memcache',
    66         'memcached' => 'SimplePie_Cache_Memcached',
    67         'redis'     => 'SimplePie_Cache_Redis'
    68     );
     62    /**
     63    * Cache handler classes
     64    *
     65    * These receive 3 parameters to their constructor, as documented in
     66    * {@see register()}
     67    * @var array
     68    */
     69    protected static $handlers = [
     70        'mysql'     => 'SimplePie\Cache\MySQL',
     71        'memcache'  => 'SimplePie\Cache\Memcache',
     72        'memcached' => 'SimplePie\Cache\Memcached',
     73        'redis'     => 'SimplePie\Cache\Redis'
     74    ];
    6975
    70     /**
    71      * Don't call the constructor. Please.
    72      */
    73     private function __construct() { }
     76    /**
     77     * Don't call the constructor. Please.
     78     */
     79    private function __construct()
     80    {
     81    }
    7482
    75     /**
    76      * Create a new SimplePie_Cache object
    77      *
    78      * @param string $location URL location (scheme is used to determine handler)
    79      * @param string $filename Unique identifier for cache object
    80      * @param string $extension 'spi' or 'spc'
    81      * @return SimplePie_Cache_Base Type of object depends on scheme of `$location`
    82      */
    83     public static function get_handler($location, $filename, $extension)
    84     {
    85         $type = explode(':', $location, 2);
    86         $type = $type[0];
    87         if (!empty(self::$handlers[$type]))
    88         {
    89             $class = self::$handlers[$type];
    90             return new $class($location, $filename, $extension);
    91         }
     83    /**
     84     * Create a new SimplePie\Cache object
     85     *
     86     * @param string $location URL location (scheme is used to determine handler)
     87     * @param string $filename Unique identifier for cache object
     88     * @param Base::TYPE_FEED|Base::TYPE_IMAGE $extension 'spi' or 'spc'
     89     * @return Base Type of object depends on scheme of `$location`
     90     */
     91    public static function get_handler($location, $filename, $extension)
     92    {
     93        $type = explode(':', $location, 2);
     94        $type = $type[0];
     95        if (!empty(self::$handlers[$type])) {
     96            $class = self::$handlers[$type];
     97            return new $class($location, $filename, $extension);
     98        }
    9299
    93         return new SimplePie_Cache_File($location, $filename, $extension);
    94     }
     100        return new \SimplePie\Cache\File($location, $filename, $extension);
     101    }
    95102
    96     /**
    97      * Create a new SimplePie_Cache object
    98      *
    99      * @deprecated Use {@see get_handler} instead
    100      */
    101     public function create($location, $filename, $extension)
    102     {
    103         trigger_error('Cache::create() has been replaced with Cache::get_handler(). Switch to the registry system to use this.', E_USER_DEPRECATED);
    104         return self::get_handler($location, $filename, $extension);
    105     }
     103    /**
     104     * Create a new SimplePie\Cache object
     105     *
     106     * @deprecated since SimplePie 1.3.1, use {@see get_handler()} instead
     107     */
     108    public function create($location, $filename, $extension)
     109    {
     110        trigger_error('Cache::create() has been replaced with Cache::get_handler() since SimplePie 1.3.1, use the registry system instead.', \E_USER_DEPRECATED);
    106111
    107     /**
    108      * Register a handler
    109      *
    110      * @param string $type DSN type to register for
    111      * @param string $class Name of handler class. Must implement SimplePie_Cache_Base
    112      */
    113     public static function register($type, $class)
    114     {
    115         self::$handlers[$type] = $class;
    116     }
     112        return self::get_handler($location, $filename, $extension);
     113    }
    117114
    118     /**
    119      * Parse a URL into an array
    120      *
    121      * @param string $url
    122      * @return array
    123      */
    124     public static function parse_URL($url)
    125     {
    126         $params = parse_url($url);
    127         $params['extras'] = array();
    128         if (isset($params['query']))
    129         {
    130             parse_str($params['query'], $params['extras']);
    131         }
    132         return $params;
    133     }
     115    /**
     116     * Register a handler
     117     *
     118     * @param string $type DSN type to register for
     119     * @param class-string<Base> $class Name of handler class. Must implement Base
     120     */
     121    public static function register($type, $class)
     122    {
     123        self::$handlers[$type] = $class;
     124    }
     125
     126    /**
     127     * Parse a URL into an array
     128     *
     129     * @param string $url
     130     * @return array
     131     */
     132    public static function parse_URL($url)
     133    {
     134        $params = parse_url($url);
     135        $params['extras'] = [];
     136        if (isset($params['query'])) {
     137            parse_str($params['query'], $params['extras']);
     138        }
     139        return $params;
     140    }
    134141}
     142
     143class_alias('SimplePie\Cache', 'SimplePie_Cache');
Note: See TracChangeset for help on using the changeset viewer.