Skip to content

Instantly share code, notes, and snippets.

@AndrianD
Created January 20, 2015 20:16
Show Gist options
  • Select an option

  • Save AndrianD/525a5c9271e9aebf99bd to your computer and use it in GitHub Desktop.

Select an option

Save AndrianD/525a5c9271e9aebf99bd to your computer and use it in GitHub Desktop.
SuperC
<?php
class Autoload
{
public static function className($className)
{
$pdo = strpos($className, 'PDO') ;
$model = strpos($className, 'Model') ;
$entity = strpos($className, 'Entity') ;
$controller = strpos($className, 'Controller') ;
if($pdo !== false)
{
$class = substr($className, 0, $pdo) ;
$fichier = ('..' . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'PDO' . DIRECTORY_SEPARATOR . $class . '.php') ;
}
elseif($entity !== false)
{
$class = strtoupper(substr($className, 0, $entity)) ;
$fichier = ('..' . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'Entity' . DIRECTORY_SEPARATOR . $class . '.php') ;
}
elseif($controller !== false)
{
$class = strtolower(substr($className, 0, $controller)) ;
$fichier = ('..' . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR . $class . '.php') ;
}
elseif($model !== false)
{
$class = ucfirst((substr($className, 0, $model))) ;
$fichier = ('..' . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . $class . '.php') ;
}
else
{
$fichier = ('..' . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $className . '.php') ;
}
require_once $fichier ;
}
}
spl_autoload_register(array('Autoload', 'className')) ;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment