<?php
class autoload {
    
    public function __construct() {
        require(APP_ROOT.'/config.php');
        require(APP_ROOT.'/src/router.php');
        $this->auto_require_files(APP_ROOT.'/src/model');
        $this->auto_require_files(APP_ROOT.'/src/controller');
    }
    
    private function auto_require_files($dir) {
        foreach ($this->scan_dir_files($dir) as $file) require($file);
    }
    
    private function scan_dir_files($dir) {
        foreach (scandir($dir) as $item) {
            if ($item != '..' && $item != '.') {
                if (is_dir($dir.'/'.$item)) {
                    $files = array_merge($files, $this->scan_dir_files($dir.'/'.$item));
                } else $files[] = $dir.'/'.$item; 
            }
        }
        return $files;
    }
    
}