PluginProbe
Selection Lite / 1.2
Selection Lite v1.2
trunk 1.0 1.1 1.10 1.11 1.12 1.14 1.15 1.16 1.17 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
selection-lite / src / autoload.php

autoload.php in Selection Lite 1.2, at src/autoload.php

146 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Selection Lite
4 * Carefully selected Elementor addons bundle, for building the most awesome websites
5 *
6 * @encoding UTF-8
7 * @version 1.0
8 * @copyright (C) 2018 - 2021 Merkulove ( https://merkulov.design/ ). All rights reserved.
9 * @license GPLv3
10 * @contributors merkulove, vladcherviakov, phoenixmkua, podolianochka, viktorialev01
11 * @support help@merkulov.design
12 **/
13
14 namespace Merkulove\SelectionLite;
15
16 /** Exit if accessed directly. */
17 if ( ! defined( 'ABSPATH' ) ) {
18 header( 'Status: 403 Forbidden' );
19 header( 'HTTP/1.1 403 Forbidden' );
20 exit;
21 }
22
23 /**
24 * Autoload class used to register custom __autoload() implementation for plugin.
25 *
26 * @since 1.0
27 *
28 **/
29 final class Autoload {
30
31 /**
32 * Plugin root Namespace.
33 *
34 * @since 1.0
35 * @var string
36 **/
37 private static $namespace = 'Merkulove\\';
38
39 /**
40 * Shorthand for DIRECTORY_SEPARATOR.
41 * Brevity is the Soul of Wit.
42 *
43 * @since 1.0
44 * @var string
45 **/
46 private static $DS = DIRECTORY_SEPARATOR;
47
48 /**
49 * Custom autoloader for plugin.
50 *
51 * @param string $class - Called class name.
52 *
53 * @static
54 * @since 1.0
55 * @access public
56 *
57 * @return void
58 **/
59 public static function load( $class ) {
60
61 /** Bail if the class is not in our namespace. */
62 if ( 0 !== strpos( $class, self::$namespace ) ) { return; }
63
64 /** Classes from Selection Lite. */
65 $file_p = self::get_plugin_class_file( $class );
66
67 /** If Class exists in Selection Lite - load it. */
68 self::include_class( $file_p );
69
70 /** Classes from Unity. */
71 $file_u = self::get_unity_class_file( $class );
72
73 /** Secondly we load classes from Unity. */
74 self::include_class( $file_u );
75
76 }
77
78 /**
79 * Build file path for classes from Unity directory.
80 *
81 * @param string $class - Called class name.
82 *
83 * @static
84 * @since 1.0
85 * @access private
86 *
87 * @return string - Path to class file.
88 **/
89 private static function get_unity_class_file( $class ) {
90
91 /** Build the filename. */
92 $file = realpath( __DIR__ );
93
94 return $file . self::$DS . str_replace( ['SelectionLite\\', '\\'], ['', self::$DS], $class ) . '.php';
95
96 }
97
98 /**
99 * Build file path for classes from Selection Lite directory.
100 *
101 * @param string $class - Called class name.
102 *
103 * @static
104 * @since 1.0
105 * @access private
106 *
107 * @return string - Path to class file.
108 **/
109 private static function get_plugin_class_file( $class ) {
110
111 /** Build the filename. */
112 $file = realpath( __DIR__ );
113
114 return $file . self::$DS . str_replace( '\\', self::$DS, $class ) . '.php';
115
116 }
117
118 /**
119 * Includes and evaluates the specified file only once.
120 *
121 * @param string $file - Path to class file.
122 *
123 * @static
124 * @since 1.0
125 * @access private
126 *
127 * @return string - Path to class file.
128 **/
129 private static function include_class( $file ) {
130
131 /** If Class file exists - load it. */
132 if ( file_exists( $file ) ) {
133
134 /** @noinspection PhpIncludeInspection */
135 include_once( $file );
136
137 }
138
139 }
140
141 }
142
143 /** Register plugin custom autoloader. */
144 spl_autoload_register( __NAMESPACE__ .'\Autoload::load' );
145
146