<?php
session_start();
setlocale(LC_ALL, 'pt_BR');

date_default_timezone_set("America/Sao_Paulo");

error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);

ini_set('max_execution_time', 300);
ini_set('memory_limit', '-1');

defined('BASE')      or define('BASE', __DIR__.DIRECTORY_SEPARATOR);
defined('NAMEAPP')   or define('NAMEAPP', 'sis/');
defined('APP')       or define('APP', 'app/');
defined('TIMESTAMP') or define('TIMESTAMP', time());

spl_autoload_register(function ($classe) {
    $dirs = dirToArray(__DIR__.DIRECTORY_SEPARATOR);
    foreach($dirs as $diretorio){
        if(file_exists($diretorio.$classe.'.php')){
            require_once($diretorio.$classe.'.php');
            return;
        }
    }
});

function dirToArray($dir) {
    $fileinfos = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($dir)
    );
    foreach($fileinfos as $pathname => $fileinfo) {
        if(!$fileinfo->isDir()) continue;
        $pathname = str_replace(array(".",".."), "", $pathname);
        if(@is_array($result)){
            if(!in_array($pathname, $result)) $result[] = $pathname;
        }else{
            $result[] = $pathname;
        }
        
    }
    
    return $result;
}