-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweareplanet_autoloader.php
38 lines (31 loc) · 1.07 KB
/
weareplanet_autoloader.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
<?php
/**
* WeArePlanet Prestashop
*
* This Prestashop module enables to process payments with WeArePlanet (https://www.weareplanet.com/).
*
* @author customweb GmbH (http://www.customweb.com/)
* @copyright 2017 - 2024 customweb GmbH
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Software License (ASL 2.0)
*/
spl_autoload_register(
function ($class) {
$prefix = 'WeArePlanet';
// base directory for the prefix
$baseDir = dirname(__FILE__) . '/inc/';
// does the class use the prefix?
$len = Tools::strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}
$cleanName = Tools::substr($class, $len);
// $replaced = str_replace("_", DIRECTORY_SEPARATOR, $cleanName);
$replaced = preg_replace('/([a-z])([A-Z])/', '$1/$2', $cleanName);
$file = $baseDir . $replaced . '.php';
// if the file exists, require it
if (file_exists($file)) {
require $file;
}
}
);