projet-php/autoloader.php

41 lines
1.5 KiB
PHP
Raw Normal View History

2015-12-02 10:29:43 +00:00
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
2015-12-02 10:29:43 +00:00
/*
* fonction d'autoloading : prend en paramètre le nom de la classe et s'occupe d'inclure les fichiers correspondant aux classes
*/
2015-12-02 11:32:57 +00:00
//pour l'inclusion dans le dossier src
$GLOBALS['managers_dir'] = dirname(__FILE__).DIRECTORY_SEPARATOR.'managers';
2015-12-02 11:32:57 +00:00
2015-12-02 10:29:43 +00:00
function autoloader($class) {
2015-12-02 11:32:57 +00:00
//si on charge le StaticRepo
if(strpos($class, 'StaticRepo') !== FALSE){
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'repositories'.DIRECTORY_SEPARATOR.$class . '.php';
}
//si on charge un repos
2015-12-02 11:32:57 +00:00
elseif(strpos($class, 'Repo') !== FALSE){
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'repositories'.DIRECTORY_SEPARATOR.'repos'.DIRECTORY_SEPARATOR.$class . '.php';
//cas particuliers pas identifiable par nom de classe
}else{
//si on charge un manager
if(is_file(dirname(__FILE__).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$class . '.php')){
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$class . '.php';
2015-12-02 10:29:43 +00:00
}elseif(is_file(dirname(__FILE__).DIRECTORY_SEPARATOR.'managers'.DIRECTORY_SEPARATOR.$class . '.class.php')){
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'managers'.DIRECTORY_SEPARATOR.$class . '.class.php';
2015-12-02 11:32:57 +00:00
}
}
2015-12-02 10:29:43 +00:00
}
//enregistrememnt de la fonction tout en bas de la pile pour ne pas casser l'autoloader de phpUnit
spl_autoload_register('autoloader',false,true);
?>