Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function import(string $module, string $from): void {
- /**
- * This is like an autoloader, inspired by python
- * Can include a new file without overhead
- * @var string $module 'the name of the file';
- * @var string from the location of the file [parent dir]
- */
- $source = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$from.DIRECTORY_SEPARATOR;
- $module = $module . '.php';
- if(!file_exists($module)){
- foreach ($iterator = new \RecursiveIteratorIterator(
- new \RecursiveDirectoryIterator($source)) as $item){
- if($item->isDir()){}
- if($iterator->getFilename() === $module){
- require_once($source.$iterator->getSubPath().DIRECTORY_SEPARATOR.$iterator->getFilename());
- }
- }
- }
- else require_once($module);
- }
Add Comment
Please, Sign In to add comment