PHP Classes
elePHPant
Icontem

File: autoloader.php

Recommend this page to a friend!
  Classes of Yerfry Ramirez  >  Basic Controller Framework  >  autoloader.php  >  Download  
File: autoloader.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Basic Controller Framework
Framework to route requests configured controllers
Author: By
Last change:
Date: 6 months ago
Size: 803 bytes
 

Contents

Class file image Download
<?php

spl_autoload_register
(function ($className) {
    static
$modules;

    if(!isset(
$modules)) {
       
$find = function($directory) use (&$find) {
           
$modules = array();

            foreach(
scandir($directory) as $fileName) {
                if(
$fileName === '.' || $fileName === '..') {
                    continue;
                }

               
$path = $directory . '/' . $fileName;

                if(!
is_dir($path)) {
                    continue;
                }

                if(
$fileName === 'resources') {
                   
$modules[] = realpath($path);
                    continue;
                }

                foreach (
$find($path) as $path) {
                   
$modules[] = $path;
                }
            }

            return
$modules;
        };

       
$modules = $find(__DIR__);
    }

   
$path = str_replace('\\', '/', $className) . '.php';

    foreach(
$modules as $module) {
       
$fileName = $module . '/' . $path;
       
        if(!
is_file($fileName)) {
            continue;
        }

        require
$fileName;
    }
});