Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.
/ soil Public archive

Commit 5036bf6

Browse files
authored
fix(autoload): register fallback autoload as needed (#255)
x-ref #254
1 parent e88ee19 commit 5036bf6

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 4.0.1: August 31st, 2020
2+
* Add fallback autoloader when Composer isn't present
3+
14
### 4.0.0: August 29th, 2020
25
* BREAKING CHANGE - Refactor entire code base
36
* Add options support for modules

soil.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: Soil
55
* Plugin URI: https://roots.io/plugins/soil/
66
* Description: A collection of modules to apply theme-agnostic front-end modifications to WordPress.
7-
* Version: 4.0.0
7+
* Version: 4.0.1
88
* Author: Roots
99
* Author URI: https://roots.io/
1010
* GitHub Plugin URI: https://github.com/roots/soil
@@ -15,9 +15,13 @@
1515

1616
namespace Roots\Soil;
1717

18-
require_once __DIR__ . '/vendor/autoload.php';
19-
2018
add_action('plugins_loaded', function () {
19+
if (!class_exists(Soil::class)) {
20+
require_once file_exists($autoloader = __DIR__ . '/vendor/autoload.php')
21+
? $autoloader
22+
: __DIR__ . '/src/autoload.php';
23+
}
24+
2125
$modules = Soil::discoverModules();
2226

2327
add_action('after_setup_theme', new Soil($modules), 100);

src/autoload.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
require_once __DIR__ . '/helpers.php';
4+
5+
spl_autoload_register(function ($className) {
6+
$relativeClassName = array_slice(explode('\\', $className), 2);
7+
$file = __DIR__ . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $relativeClassName) . '.php';
8+
if (file_exists($file)) {
9+
require $file;
10+
return true;
11+
}
12+
return false;
13+
});

0 commit comments

Comments
 (0)