Guest User

Untitled

a guest
Feb 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2. function import(string $module, string $from): void {
  3. /**
  4. * This is like an autoloader, inspired by python
  5. * Can include a new file without overhead
  6. * @var string $module 'the name of the file';
  7. * @var string from the location of the file [parent dir]
  8. */
  9. $source = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$from.DIRECTORY_SEPARATOR;
  10. $module = $module . '.php';
  11. if(!file_exists($module)){
  12. foreach ($iterator = new \RecursiveIteratorIterator(
  13. new \RecursiveDirectoryIterator($source)) as $item){
  14. if($item->isDir()){}
  15. if($iterator->getFilename() === $module){
  16. require_once($source.$iterator->getSubPath().DIRECTORY_SEPARATOR.$iterator->getFilename());
  17. }
  18. }
  19. }
  20. else require_once($module);
  21. }
Add Comment
Please, Sign In to add comment