-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautoload.php
More file actions
67 lines (56 loc) · 1.6 KB
/
autoload.php
File metadata and controls
67 lines (56 loc) · 1.6 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
<?php
namespace JordJD\CamelCaser;
use JordJD\CamelCaser\Alias\Finder\AliasFinder;
use JordJD\CamelCaser\Alias\Renderer\AliasRenderer;
use JordJD\CamelCaser\Formatter\CamelCaseFormatter;
use JordJD\CamelCaser\Formatter\FunctionFormatter;
use JordJD\CamelCaser\Formatter\NamespacePrefixFormatter;
use JordJD\CamelCaser\Hasher\Md5FunctionHasher;
use ReflectionFunction;
use RuntimeException;
use SplFileObject;
use Throwable;
const INCLUDE_DISABLED = false;
const EXCLUDE_DISABLED_FUNCTIONS = true;
$internalFunctions = array_map(
function (string $function) : ReflectionFunction {
return new ReflectionFunction($function);
},
get_defined_functions(EXCLUDE_DISABLED_FUNCTIONS)['internal'] ?? []
);
$hasher = new Md5FunctionHasher();
$storage = sprintf(
__DIR__.'/aliases.%s.php',
$hasher(...$internalFunctions)
);
if (!file_exists($storage)) {
$finder = new AliasFinder(
new NamespacePrefixFormatter(
new FunctionFormatter()
),
new NamespacePrefixFormatter(
new CamelCaseFormatter()
)
);
$aliases = $finder(...$internalFunctions);
$renderer = new AliasRenderer();
try {
$render = $renderer(...$aliases);
} catch (Throwable $exception) {
$render = null;
}
if (is_string($render)) {
$file = new SplFileObject($storage, 'w+');
$file->fwrite($render);
}
}
try {
require_once $storage;
} catch (Throwable $exception) {
unlink($storage);
throw new RuntimeException(
'Failed to register aliases for internal functions!',
0,
$exception
);
}