-
Notifications
You must be signed in to change notification settings - Fork 428
Expand file tree
/
Copy pathAutoloaderStep.php
More file actions
98 lines (82 loc) · 2.12 KB
/
AutoloaderStep.php
File metadata and controls
98 lines (82 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace EE\Bootstrap;
use EE;
/**
* Abstract class AutoloaderStep.
*
* Abstract base class for steps that include an autoloader.
*
* @package EE\Bootstrap
*/
abstract class AutoloaderStep implements BootstrapStep {
/**
* Store state for subclasses to have access.
*
* @var BootstrapState
*/
protected $state;
/**
* Process this single bootstrapping step.
*
* @param BootstrapState $state Contextual state to pass into the step.
*
* @return BootstrapState Modified state to pass to the next step.
*/
public function process( BootstrapState $state ) {
$this->state = $state;
$found_autoloader = false;
$autoloader_paths = $this->get_autoloader_paths();
if ( false === $autoloader_paths ) {
// Skip this autoloading step.
return $state;
}
foreach ( $autoloader_paths as $autoloader_path ) {
if ( is_readable( $autoloader_path ) ) {
try {
require $autoloader_path;
$found_autoloader = true;
} catch ( \Exception $exception ) {
EE::warning(
"Failed to load autoloader '{$autoloader_path}'. Reason: "
. $exception->getMessage()
);
}
}
}
if ( ! $found_autoloader ) {
$this->handle_failure();
}
return $this->state;
}
/**
* Get the name of the custom vendor folder as set in `composer.json`.
*
* @return string|false Name of the custom vendor folder or false if none.
*/
protected function get_custom_vendor_folder() {
$maybe_composer_json = EE_ROOT . '/../../../composer.json';
if ( ! is_readable( $maybe_composer_json ) ) {
return false;
}
$composer = json_decode( file_get_contents( $maybe_composer_json ) );
if ( ! empty( $composer->config )
&& ! empty( $composer->config->{'vendor-dir'} )
) {
return $composer->config->{'vendor-dir'};
}
return false;
}
/**
* Handle the failure to find an autoloader.
*
* @return void
*/
protected function handle_failure() { }
/**
* Get the autoloader paths to scan for an autoloader.
*
* @return string[]|false Array of strings with autoloader paths, or false
* to skip.
*/
abstract protected function get_autoloader_paths();
}