PHP Classes

File: classes/autoload.php

Recommend this page to a friend!
  Classes of Gonzalo Chumillas   HttpRequest   classes/autoload.php   Download  
File: classes/autoload.php
Role: Class source
Content type: text/plain
Description: Class source
Class: HttpRequest
Send HTTP requests to remote servers
Author: By
Last change:
Date: 9 years ago
Size: 1,062 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;
        }
    }
);