PHP Classes

File: classes/autoload.php

Recommend this page to a friend!
  Classes of Gonzalo Chumillas   DbTable   classes/autoload.php   Download  
File: classes/autoload.php
Role: Auxiliary script
Content type: text/plain
Description: Class source
Class: DbTable
Update table records in multiple related tables
Author: By
Last change:
Date: 9 years ago
Size: 1,088 bytes
 

Contents

Class file image Download
<?php
/**
 * This file contains an autoload function.
 *
 * PHP Version 5.3
 *
 * @category XML
 * @package XmlQuery
 * @author Gonzalo Chumillas <gonzalo@soloproyectos.com>
 * @license https://raw.github.com/soloproyectos/core/master/LICENSE BSD 2-Clause License
 * @link https://github.com/soloproyectos/core
 */

spl_autoload_register(
    function (
$classname) {
        if (
preg_match_all("/[A-Z][a-z,0-9]*/", $classname, $matches)) {
           
// script filename
           
$dir = __DIR__;
           
$name = "";
           
$items = $matches[0];
            foreach (
$items as $item) {
               
$item = strtolower($item);
               
$d = "$dir/$item";
                if (
is_dir($d)) {
                   
$dir = $d;
                }
               
$name .= strlen($name) > 0? "-$item" : $item;
            }
           
$filename = "$dir/$name.php";
           
            if (!
is_file($filename)) {
                throw new
Exception("Script not found: $filename");
            }
           
            include_once
$filename;
        }
    }
);