PluginProbe
Datafeedr API / 1.2.12
Datafeedr API v1.2.12
1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 All 181 releases
datafeedr-api / src / Autoloader.php

Autoloader.php in Datafeedr API 1.2.12, at src/Autoloader.php

62 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace Datafeedr\Api;
2
3 /**
4 * Autoloads Datafeedr API classes.
5 *
6 * @since 2.0.0
7 */
8 class Autoloader {
9
10 /**
11 * Handles the autoloading of the Datafeedr API classes.
12 *
13 * @since 2.0.0
14 *
15 * @param string $class_name Name of class requested.
16 */
17 function autoload( $class_name ) {
18
19 // If $class_name does not contain the Datafeedr\Api namespace, return. It's not our class.
20 if ( 0 !== strpos( $class_name, __NAMESPACE__ ) ) {
21 return;
22 }
23
24 // Set default directory separator.
25 $ds = \DIRECTORY_SEPARATOR;
26
27 // Remove namespace "Datafeedr\Api" from $class_name
28 $class_name = str_replace( __NAMESPACE__, '', $class_name );
29
30 // Trim any leading or trailing backslashes
31 $class_name = trim( $class_name, '\\' );
32
33 // Replace any remaining backslashes with proper directory separator and append with PHP extension.
34 $class_name = str_replace( '\\', $ds, $class_name ) . '.php';
35
36 // Get full path to classes directory: ~/wp-content/plugins/datafeedr-api-v2/src
37 $classes_dir = untrailingslashit( dirname( __FILE__ ) );
38
39 // Full path to file to be included.
40 $full_path = $classes_dir . $ds . $class_name;
41
42 require_once( $full_path );
43 }
44
45 /**
46 * Registers Autoloader as an SPL autoloader.
47 *
48 * @since 2.0.0
49 *
50 * @param bool $prepend
51 */
52 public static function register( $prepend = false ) {
53 spl_autoload_register( array( new self(), 'autoload' ), true, $prepend );
54 }
55 }
56
57 /**
58 * Register the Autoloader.
59 *
60 * @since 2.0.0
61 */
62 Autoloader::register();