PluginProbe
Image Source Control Lite – Show Image Credits and Captions / trunk
Image Source Control Lite – Show Image Credits and Captions vtrunk
3.12.0 3.11.0 trunk 1.1 1.1.1 1.1.2 1.1.2.1 1.1.3 1.10 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.2 1.2.0.1 1.2.0.2 1.2.0.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.4.1 1.3.5 All 110 releases
image-source-control-isc / includes / class-autoloader.php

class-autoloader.php in Image Source Control Lite – Show Image Credits and Captions trunk, at includes/class-autoloader.php

95 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The class is responsible for locating and loading the autoloader file used in the plugin.
4 */
5
6 namespace ISC;
7
8 /**
9 * Autoloader.
10 */
11 class Autoloader {
12
13 /**
14 * Hold autoloader.
15 *
16 * @var mixed
17 */
18 private $autoloader;
19
20 /**
21 * Main instance
22 *
23 * Ensure only one instance is loaded or can be loaded.
24 *
25 * @return Autoloader
26 */
27 public static function get(): Autoloader {
28 static $instance;
29
30 if ( null === $instance ) {
31 $instance = new Autoloader();
32 }
33
34 return $instance;
35 }
36
37 /**
38 * Get hold autoloader.
39 *
40 * @return mixed
41 */
42 public function get_autoloader() {
43 return $this->autoloader;
44 }
45
46 /**
47 * Get plugin directory.
48 *
49 * @return string
50 */
51 public function get_directory(): string {
52 return ISCPATH;
53 }
54
55 /**
56 * Runs this initializer.
57 *
58 * @return void
59 */
60 public function initialize(): void {
61 $this->autoloader = require $this->locate();
62 }
63
64 /**
65 * Locate the autoload file
66 *
67 * This function searches for the autoload file in the packages directory and vendor directory.
68 *
69 * @return bool|string
70 */
71 private function locate() {
72 $directory = $this->get_directory();
73 $lib = $directory . 'lib/autoload.php';
74 $vendors = $directory . 'vendor/autoload.php';
75
76 if ( is_readable( $lib ) && ( ! self::is_test() ) ) {
77 return $lib;
78 }
79
80 if ( is_readable( $vendors ) ) {
81 return $vendors;
82 }
83
84 return false;
85 }
86
87 /**
88 * Check if this is a test run.
89 *
90 * @return bool
91 */
92 public static function is_test(): bool {
93 return ( isset( $_SERVER['TEST_SITE_USER_AGENT'] ) && $_SERVER['TEST_SITE_USER_AGENT'] === 'ISC_Test' ); // wp-browser unit test
94 }
95 }