irubi/autoload

There is no license information available for the latest version (v1.1.2-alpha) of this package.

v1.1.2-alpha 2017-12-22 00:22 UTC

This package is auto-updated.

Last update: 2024-05-16 07:43:04 UTC


README

How to autoload classes.

<?php

spl_autoload_register(function($class) {
	$prefix = 'app\\';
	
	$length = strlen($prefix);
  
  $base_directory = __DIR__ . '/app/';
	
	if(strncmp($prefix, $class, $length) !== 0) {
    return;
  }
  
  $class_end = substr($class, $length);
  
  $file = $base_directory . str_replace('\\', '/', $class_end) . '.php';
  
  if(file_exists($file)) {
    require $file;
  }
});