PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.13.1
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.13.1
3.1.0 3.0.0 2.13.2 2.13.1 2.13.0 trunk 1.0.0 2.1.0 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.1 2.5.3 2.5.4 2.5.5 2.6.1 All 56 releases
slider-blocks / includes / Autoloader.php

Autoloader.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 2.13.1, at includes/Autoloader.php

83 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PSR-4 Autoloader for the GutSlider namespace.
4 *
5 * Maps GutSlider\Foo\Bar to includes/Foo/Bar.php.
6 *
7 * @package GutSlider
8 * @since 3.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class GutSlider_Autoloader
17 *
18 * Handles PSR-4 autoloading for all classes within the GutSlider namespace.
19 * This class is intentionally not namespaced because it must be loaded via
20 * require_once before the autoloader is registered.
21 *
22 * @since 3.0.0
23 */
24 final class GutSlider_Autoloader {
25
26 /**
27 * The namespace prefix for GutSlider classes.
28 *
29 * @var string
30 */
31 private const NAMESPACE_PREFIX = 'GutSlider\\';
32
33 /**
34 * Base directory for the namespace prefix.
35 *
36 * @var string
37 */
38 private string $base_dir;
39
40 /**
41 * Constructor.
42 *
43 * @since 3.0.0
44 *
45 * @param string $base_dir The base directory where namespaced classes reside.
46 */
47 public function __construct( string $base_dir ) {
48 $this->base_dir = rtrim( $base_dir, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
49 }
50
51 /**
52 * Register the autoloader with spl_autoload_register.
53 *
54 * @since 3.0.0
55 *
56 * @return void
57 */
58 public function register(): void {
59 spl_autoload_register( array( $this, 'autoload' ) );
60 }
61
62 /**
63 * Autoload a class file based on its fully-qualified class name.
64 *
65 * @since 3.0.0
66 *
67 * @param string $class The fully-qualified class name.
68 * @return void
69 */
70 public function autoload( string $class ): void {
71 if ( strpos( $class, self::NAMESPACE_PREFIX ) !== 0 ) {
72 return;
73 }
74
75 $relative_class = substr( $class, strlen( self::NAMESPACE_PREFIX ) );
76 $file = $this->base_dir . str_replace( '\\', DIRECTORY_SEPARATOR, $relative_class ) . '.php';
77
78 if ( file_exists( $file ) ) {
79 require_once $file;
80 }
81 }
82 }
83