Changeset 60771 for trunk/src/wp-includes/SimplePie/src/Registry.php
- Timestamp:
- 09/16/2025 10:45:37 PM (2 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/SimplePie/src/Registry.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/src/Registry.php
r59141 r60771 1 1 <?php 2 2 3 /** 4 * SimplePie 5 * 6 * A PHP-Based RSS and Atom Feed Framework. 7 * Takes the hard work out of managing a complete RSS/Atom solution. 8 * 9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without modification, are 13 * permitted provided that the following conditions are met: 14 * 15 * * Redistributions of source code must retain the above copyright notice, this list of 16 * conditions and the following disclaimer. 17 * 18 * * Redistributions in binary form must reproduce the above copyright notice, this list 19 * of conditions and the following disclaimer in the documentation and/or other materials 20 * provided with the distribution. 21 * 22 * * Neither the name of the SimplePie Team nor the names of its contributors may be used 23 * to endorse or promote products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 27 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 28 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS 29 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 * 36 * @package SimplePie 37 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue 38 * @author Ryan Parman 39 * @author Sam Sneddon 40 * @author Ryan McCue 41 * @link http://simplepie.org/ SimplePie 42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 43 */ 3 // SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue 4 // SPDX-License-Identifier: BSD-3-Clause 5 6 declare(strict_types=1); 44 7 45 8 namespace SimplePie; 46 9 10 use InvalidArgumentException; 47 11 use SimplePie\Content\Type\Sniffer; 48 12 use SimplePie\Parse\Date; … … 53 17 * 54 18 * Access this via {@see \SimplePie\SimplePie::get_registry()} 55 *56 * @package SimplePie57 19 */ 58 20 class Registry … … 91 53 * 92 54 * @see register() 93 * @var array 55 * @var array<string, class-string> 94 56 */ 95 57 protected $classes = []; … … 148 110 * @return bool Successfulness 149 111 */ 150 public function register( $type, $class,$legacy = false)112 public function register(string $type, $class, bool $legacy = false) 151 113 { 152 114 if (array_key_exists($type, $this->legacyTypes)) { … … 201 163 } 202 164 165 // For PHPStan: values in $default should be subtypes of keys. 166 /** @var class-string<T> */ 203 167 $class = $this->default[$type]; 204 168 205 169 if (array_key_exists($type, $this->classes)) { 170 // For PHPStan: values in $classes should be subtypes of keys. 171 /** @var class-string<T> */ 206 172 $class = $this->classes[$type]; 207 173 } … … 215 181 * @template T class-string $type 216 182 * @param class-string<T> $type 217 * @param array $parameters Parameters to pass to the constructor183 * @param array<mixed> $parameters Parameters to pass to the constructor 218 184 * @return T Instance of class 219 185 */ 220 public function &create($type, $parameters = [])186 public function &create($type, array $parameters = []) 221 187 { 222 188 $class = $this->get_class($type); 189 if ($class === null) { 190 throw new InvalidArgumentException(sprintf( 191 '%s(): Argument #1 ($type) "%s" not found in class list.', 192 __METHOD__, 193 $type 194 ), 1); 195 } 223 196 224 197 if (!method_exists($class, '__construct')) { … … 226 199 } else { 227 200 $reflector = new \ReflectionClass($class); 201 // For PHPStan: $class is T. 202 /** @var T */ 228 203 $instance = $reflector->newInstanceArgs($parameters); 229 204 } … … 235 210 $instance->set_registry($this); 236 211 } 212 237 213 return $instance; 238 214 } … … 243 219 * @param class-string $type 244 220 * @param string $method 245 * @param array $parameters221 * @param array<mixed> $parameters 246 222 * @return mixed 247 223 */ 248 public function &call($type, $method,$parameters = [])224 public function &call($type, string $method, array $parameters = []) 249 225 { 250 226 $class = $this->get_class($type); 227 if ($class === null) { 228 throw new InvalidArgumentException(sprintf( 229 '%s(): Argument #1 ($type) "%s" not found in class list.', 230 __METHOD__, 231 $type 232 ), 1); 233 } 251 234 252 235 if (in_array($class, $this->legacy)) { … … 257 240 // No longer supported as of PHP 8.0. 258 241 if ($method === 'get_handler') { 242 // Fixing this PHPStan error breaks CacheTest::testDirectOverrideLegacy() 243 /** @phpstan-ignore argument.type */ 259 244 $result = @call_user_func_array([$class, 'create'], $parameters); 260 245 return $result; … … 264 249 } 265 250 266 $result = call_user_func_array([$class, $method], $parameters); 251 $callable = [$class, $method]; 252 assert(is_callable($callable), 'For PHPstan'); 253 $result = call_user_func_array($callable, $parameters); 267 254 return $result; 268 255 }
Note: See TracChangeset
for help on using the changeset viewer.