Skip to content

Commit 6445ef3

Browse files
committed
Add standalone autoloader
1 parent 70248b7 commit 6445ef3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

autoload.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
declare(strict_types=1);
3+
/*
4+
* Include this file to use the recipe without composer autoloader (e.g. when running deployer as phar)
5+
*
6+
* Implementation based on https://www.php-fig.org/psr/psr-4/examples/
7+
*/
8+
9+
spl_autoload_register(function ($class) {
10+
11+
$prefix = 'IntegerNet\\DeployerTimer\\';
12+
$base_dir = __DIR__ . '/src/';
13+
14+
$len = strlen($prefix);
15+
if (strncmp($prefix, $class, $len) !== 0) {
16+
return;
17+
}
18+
$relative_class = substr($class, $len);
19+
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
20+
if (file_exists($file)) {
21+
require $file;
22+
}
23+
});

0 commit comments

Comments
 (0)