PluginProbe ʕ •ᴥ•ʔ
Orbit Fox: Duplicate Page, Menu Icons, SVG Support, Cookie Notice, Custom Fonts & More / 2.10.32
Orbit Fox: Duplicate Page, Menu Icons, SVG Support, Cookie Notice, Custom Fonts & More v2.10.32
3.0.7 3.0.6 2.8.11 2.8.12 2.8.13 2.8.14 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 2.0.0 2.0.1 2.0.10 2.0.11 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.10.0 2.10.1 2.10.10 2.10.11 2.10.12 2.10.13 2.10.14 2.10.15 2.10.16 2.10.17 2.10.18 2.10.19 2.10.2 2.10.20 2.10.21 2.10.22 2.10.23 2.10.24 2.10.25 2.10.26 2.10.27 2.10.28 2.10.29 2.10.3 2.10.30 2.10.31 2.10.32 2.10.33 2.10.34 2.10.35 2.10.36 2.10.37 2.10.38 2.10.39 2.10.40 2.10.41 2.10.42 2.10.43 2.10.44 2.10.45 2.10.46 2.10.47 2.10.5 2.10.6 2.10.7 2.10.8 2.10.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.10
themeisle-companion / class-autoloader.php
themeisle-companion Last commit date
core 2 years ago dashboard 3 years ago images 8 years ago languages 2 years ago obfx_modules 2 years ago vendor 2 years ago .eslintrc 4 years ago CHANGELOG.md 2 years ago CONTRIBUTING.md 2 years ago LICENSE.txt 8 years ago class-autoloader.php 6 years ago index.php 8 years ago readme.md 2 years ago readme.txt 2 years ago themeisle-companion.php 2 years ago uninstall.php 8 years ago
class-autoloader.php
220 lines
1 <?php
2 /**
3 * The file that defines autoload class
4 *
5 * A simple autoloader that loads class files recursively starting in the directory
6 * where this class resides. Additional options can be provided to control the naming
7 * convention of the class files.
8 *
9 * @link https://themeisle.com
10 * @copyright Copyright (c) 2017, Bogdan Preda
11 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
12 *
13 * @since 1.0.0
14 * @package Orbit_Fox
15 */
16
17 /**
18 * The Autoloader class.
19 *
20 * @since 1.0.0
21 * @package Orbit_Fox
22 * @author Themeisle <friends@themeisle.com>
23 */
24 class Autoloader {
25
26 /**
27 * File extension as a string. Defaults to ".php".
28 *
29 * @since 1.0.0
30 * @access protected
31 * @var string $file_ext The file extension to look for.
32 */
33 protected static $file_ext = '.php';
34
35 /**
36 * The top level directory where recursion will begin. Defaults to the current
37 * directory.
38 *
39 * @since 1.0.0
40 * @access protected
41 * @var string $path_top The root directory.
42 */
43 protected static $path_top = __DIR__;
44
45 /**
46 * The plugin directory where recursion will begin. Defaults to empty ( No module will be loaded ).
47 *
48 * @since 1.0.0
49 * @access protected
50 * @var string $plugins_path The installation plugins directory.
51 */
52 protected static $plugins_path = '';
53
54 /**
55 * Holds an array of namespaces to filter in autoloading if set.
56 *
57 * @since 1.0.0
58 * @access protected
59 * @var array $namespaces The namespace array, used if not empty on autoloading.
60 */
61 protected static $namespaces = array();
62
63 /**
64 * An array of files to exclude when looking to autoload.
65 *
66 * @since 1.0.0
67 * @access protected
68 * @var array $excluded_files The excluded files list.
69 */
70 protected static $excluded_files = array();
71
72 /**
73 * A placeholder to hold the file iterator so that directory traversal is only
74 * performed once.
75 *
76 * @since 1.0.0
77 * @access protected
78 * @var RecursiveIteratorIterator $file_iterator Holds an instance of the iterator class.
79 */
80 protected static $file_iterator = null;
81
82 /**
83 * Method to check in allowed namespaces.
84 *
85 * @since 1.0.0
86 * @access protected
87 * @param string $class_name the class name to check with the namespaces.
88 * @return bool
89 */
90 protected static function check_namespaces( $class_name ) {
91 $found = false;
92 foreach ( static::$namespaces as $namespace ) {
93 if ( substr( $class_name, 0, strlen( $namespace ) ) === $namespace ) {
94 $found = true;
95 }
96 if ( $namespace === 'OBFX_Module' && substr( $class_name, strlen( $namespace ) * ( -1 ), strlen( $namespace ) ) === $namespace ) {
97 return static::module_loader( $class_name );
98 }
99 }
100 return $found;
101 }
102
103 /**
104 * Autoload function for registration with spl_autoload_register
105 *
106 * Looks recursively through project directory and loads class files based on
107 * filename match.
108 *
109 * @since 1.0.0
110 * @access public
111 * @param string $class_name The class name requested.
112 * @return mixed
113 */
114 public static function loader( $class_name ) {
115
116 if ( ! empty( static::$namespaces ) ) {
117 $found = static::check_namespaces( $class_name );
118 if ( ! $found ) {
119 return $found;
120 }
121 }
122
123 $directory = new RecursiveDirectoryIterator( static::$path_top . DIRECTORY_SEPARATOR . 'core', RecursiveDirectoryIterator::SKIP_DOTS );
124
125 if ( is_null( static::$file_iterator ) ) {
126 $iterator = new RecursiveIteratorIterator( $directory );
127 $regex = new RegexIterator( $iterator, '/^.+\.php$/i', RecursiveRegexIterator::MATCH );
128 static::$file_iterator = iterator_to_array( $regex, false );
129 }
130
131 $filename = 'class-' . str_replace( '_', '-', strtolower( $class_name ) ) . static::$file_ext;
132 foreach ( static::$file_iterator as $file ) {
133 if ( strtolower( $file->getFileName() ) === strtolower( $filename ) && is_readable( $file->getPathName() ) ) {
134 require $file->getPathName();
135 return true;
136 }
137 }
138 }
139
140 /**
141 * Method used for loading required module init file.
142 *
143 * @since 1.0.0
144 * @access public
145 * @param string $class_name The class name requested.
146 * @return bool
147 */
148 public static function module_loader( $class_name ) {
149 $module_name = str_replace( '_', '-', strtolower( str_replace( '_OBFX_Module', '', $class_name ) ) );
150 if ( static::$plugins_path !== '' ) {
151 $directories = glob( static::$plugins_path . '*' . DIRECTORY_SEPARATOR . 'obfx_modules' . DIRECTORY_SEPARATOR . $module_name, GLOB_ONLYDIR );
152 foreach ( $directories as $directory ) {
153 $filename = $directory . DIRECTORY_SEPARATOR . 'init.php';
154 if ( is_readable( $filename ) ) {
155 require $filename;
156 return true;
157 }
158 }
159 }
160 return false;
161 }
162
163 /**
164 * Sets the $file_ext property
165 *
166 * @since 1.0.0
167 * @access public
168 * @param string $file_ext The file extension used for class files. Default is "php".
169 */
170 public static function set_file_ext( $file_ext ) {
171 static::$file_ext = $file_ext;
172 }
173
174 /**
175 * Sets the $plugins_path property
176 *
177 * @since 1.0.0
178 * @access public
179 * @param string $path The path representing the top level where recursion should
180 * begin for plugins. Defaults to empty ( does not look in plugins ).
181 */
182 public static function set_plugins_path( $path ) {
183 static::$plugins_path = $path;
184 }
185
186 /**
187 * Sets the $path property
188 *
189 * @since 1.0.0
190 * @access public
191 * @param string $path The path representing the top level where recursion should
192 * begin. Defaults to the current directory.
193 */
194 public static function set_path( $path ) {
195 static::$path_top = $path;
196 }
197
198 /**
199 * Adds a new file to the exclusion list.
200 *
201 * @since 1.0.0
202 * @access public
203 * @param string $file_name The file name to exclude from autoload.
204 */
205 public static function exclude_file( $file_name ) {
206 static::$excluded_files[] = $file_name;
207 }
208
209 /**
210 * Sets the namespaces used in autoloading if any.
211 *
212 * @since 1.0.0
213 * @access public
214 * @param array $namespaces The namespaces to use.
215 */
216 public static function define_namespaces( $namespaces = array() ) {
217 static::$namespaces = $namespaces;
218 }
219 }
220