PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / 6.1
Floating Button – Easily Create Sticky, Fixed & Floating Buttons v6.1
trunk 2.0.2 3.0 4.0 4.1.2 4.3 5.0 5.0.1 5.1 5.1.1 5.2 5.3 5.3.1 6.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 All 31 releases
floating-button / classes / Autoloader.php

Autoloader.php in Floating Button – Easily Create Sticky, Fixed & Floating Buttons 6.1, at classes/Autoloader.php

60 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FloatingButton;
4
5 // Exit if accessed directly.
6
7 defined( 'ABSPATH' ) || exit;
8
9 class Autoloader {
10 /**
11 * @var mixed
12 */
13 private $namespace;
14 private string $directory;
15
16
17 public function __construct( $namespace ) {
18 $this->namespace = $namespace;
19 $this->directory = __DIR__;
20 spl_autoload_register( [ $this, 'autoload' ] );
21 }
22
23 public function autoload( $class ): void {
24
25 if ( strpos( $class, $this->namespace ) === 0 ) {
26 $file = $this->get_file_path( $class );
27
28 if ( $file && file_exists( $file ) ) {
29 require_once( $file );
30
31 return;
32 }
33 }
34 }
35
36 /**
37 * Get the file path for a class.
38 *
39 * @param string $class The fully qualified name of the class.
40 *
41 * @return string|null The file path, or null if the file could not be found.
42 */
43 public function get_file_path( string $class ): ?string {
44
45 $relativeClass = substr( $class, strlen( $this->namespace ) );
46
47 $file = str_replace( '\\', DIRECTORY_SEPARATOR, $relativeClass ) . '.php';
48
49 $full_path = $this->directory . DIRECTORY_SEPARATOR . $file;
50
51 if ( file_exists( $full_path ) ) {
52 return $full_path;
53 }
54
55
56 return null;
57 }
58
59
60 }