generated from helsingborg-stad/Wordpress-Plugin-Boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
load.php
63 lines (56 loc) · 1.51 KB
/
load.php
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
<?php
/**
* Class ComponentLibraryAutoLoad
*
* This class is responsible for autoloading the Component Library.
*/
Class ComponentLibraryAutoLoad {
/**
* ComponentLibraryAutoLoad constructor.
*
* Initializes the autoloader if it is not already loaded.
*/
public function __construct() {
if(!$this->isLoaded() && $this->autoloadExists()) {
$this->load();
}
}
/**
* Get the path of a file or directory.
*
* @param string $append (optional) The path to append to the base path.
* @return string The full path.
*/
private function getPath(string $append = ''): string
{
return dirname(__FILE__) . '/' . $append;
}
/**
* Check if the Component Library is already loaded.
*
* @return bool True if the Component Library is loaded, false otherwise.
*/
private function isLoaded(): bool
{
return class_exists('ComponentLibrary\Init');
}
/**
* Check if the autoloader file exists.
*
* @return bool True if the autoloader file exists, false otherwise.
*/
private function autoloadExists(): bool
{
return file_exists($this->getPath('vendor/autoload.php'));
}
/**
* Load the Component Library.
*
* @return bool True if the Component Library is successfully loaded, false otherwise.
*/
private function load(): void
{
require_once $this->getPath('vendor/autoload.php');
}
}
new ComponentLibraryAutoLoad();