| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 // SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue 4 // SPDX-License-Identifier: BSD-3-Clause 5 6 /** 7 * PSR-4 implementation for SimplePie. 8 * 9 * After registering this autoload function with SPL, the following line 10 * would cause the function to attempt to load the \SimplePie\SimplePie class 11 * from /src/SimplePie.php: 12 * 13 * new \SimplePie\SimplePie(); 14 * 15 * @param string $class The fully-qualified class name. 16 * @return void 17 */ 18 spl_autoload_register(function ($class) { 19 20 // project-specific namespace prefix 21 $prefix = 'SimplePie\\'; 22 23 // base directory for the namespace prefix 24 $base_dir = __DIR__ . '/src/'; 25 26 // does the class use the namespace prefix? 27 $len = strlen($prefix); 28 if (strncmp($prefix, $class, $len) !== 0) { 29 // no, move to the next registered autoloader 30 return; 31 } 32 33 // get the relative class name 34 $relative_class = substr($class, $len); 35 36 // replace the namespace prefix with the base directory, replace namespace 37 // separators with directory separators in the relative class name, append 38 // with .php 39 $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; 40 41 // if the file exists, require it 42 if (file_exists($file)) { 43 require $file; 44 } 45 }); 46 47 // autoloader 48 spl_autoload_register(array(new SimplePie_Autoloader(), 'autoload')); 49 50 if (!class_exists('SimplePie')) 51 { 52 exit('Autoloader not registered properly'); 53 } 54 55 /** 56 * Autoloader class 57 */ 58 class SimplePie_Autoloader 59 { 60 protected $path; 61 62 /** 63 * Constructor 64 */ 65 public function __construct() 66 { 67 $this->path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library'; 68 } 69 70 /** 71 * Autoloader 72 * 73 * @param string $class The name of the class to attempt to load. 74 */ 75 public function autoload($class) 76 { 77 // Only load the class if it starts with "SimplePie" 78 if (strpos($class, 'SimplePie') !== 0) 79 { 80 return; 81 } 82 83 $filename = $this->path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; 84 include $filename; 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Oct 25 08:20:05 2025 | Cross-referenced by PHPXref |