Skip to content

Commit ccef338

Browse files
committed
Added library autoloading
1 parent 8883408 commit ccef338

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

modules/library.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
namespace Axel\Module;
3+
class Library implements \Axel\Module {
4+
private $libraryDir;
5+
private $axel;
6+
7+
public function __construct(\Axel\Axel $axel, $libraryDir) {
8+
$this->axel = $axel;
9+
$this->libraryDir = $libraryDir;
10+
}
11+
12+
public function locate($className) {
13+
$rootNs = explode('\\', rtrim('\\', $className))[0];
14+
if (file_exists($this->libraryDir . DIRECTORY_SEPARATOR . $rootNs . DIRECTORY_SEPARATOR . 'autoload.json')) {
15+
$json = json_decode(file_get_contents($this->libraryDir . DIRECTORY_SEPARATOR . $rootNs . DIRECTORY_SEPARATOR . 'autoload.json'));
16+
17+
if (isset($json->include)) foreach ($json->include as $file) require_once $this->libaryDir . DIRECTORY_SEPARATOR . $rootNs . DIRECTORY_SEPARATOR . $file;
18+
19+
foreach ($json->modules as $key => $value) $this->axel->addModule(new $key(...$value));
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)