PHP Classes

File: cloader.php

Recommend this page to a friend!
  Classes of Nic Latyshev   PHP Performance Testing Class   cloader.php   Download  
File: cloader.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Performance Testing Class
Measure the speed of execution of PHP code
Author: By
Last change:
Date: 2 years ago
Size: 968 bytes
 

Contents

Class file image Download
<?php
    mb_internal_encoding
('UTF-8');
   
    function
classes_loader ( $classname ) {
       
// class loaded?
       
if ( !class_exists($classname) ) {
           
// classes folder
           
$classes['classes'] = realpath($_SERVER['DOCUMENT_ROOT'].'/classes/');
           
$classes['self'] = getcwd();
           
           
// ClassName.class.php in /classes/ or classname.php in this folder
           
$class_path['classes'] = $classes['classes'].'/'.$classname.'.class.php';
           
$class_path['self'] = $classes['self'].'/'.strtolower($classname).'.php';
           
           
$file_to_include = '';
           
// check this
           
foreach ( $class_path as $class_file ) {
                if (
file_exists($class_file) ) {
                   
$file_to_include = $class_file;
                }
            }
           
           
// load class
           
if ( $file_to_include && !class_exists($classname) ) {
                include_once(
$file_to_include );
            } else {
                echo
'Class '.$classname.' not found in includes path: '.PHP_EOL.implode(PHP_EOL,$classes).PHP_EOL;
            }
        }
    }
   
   
spl_autoload_register('classes_loader');
?>