mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-22 14:42:23 +03:00
Added PSR4 autoload function for the project.
This commit is contained in:
parent
d31535627b
commit
ad59ffeb35
2 changed files with 56 additions and 0 deletions
44
src/autoload.php
Normal file
44
src/autoload.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2016, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.2.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
function register($namespace, $path) {
|
||||
spl_autoload_register(function ($class) {
|
||||
// project-specific namespace prefix
|
||||
$prefix = 'EA\\' . $namespace . '\\';
|
||||
|
||||
// base directory for the namespace prefix
|
||||
$base_dir = __DIR__ . '/' . $path;
|
||||
|
||||
// does the class use the namespace prefix?
|
||||
$len = strlen($prefix);
|
||||
if (strncmp($prefix, $class, $len) !== 0) {
|
||||
// no, move to the next registered autoloader
|
||||
return;
|
||||
}
|
||||
|
||||
// get the relative class name
|
||||
$relative_class = substr($class, $len);
|
||||
|
||||
// replace the namespace prefix with the base directory, replace namespace
|
||||
// separators with directory separators in the relative class name, append
|
||||
// with .php
|
||||
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
||||
|
||||
// if the file exists, require it
|
||||
if (file_exists($file)) {
|
||||
require $file;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
register('Engine', __DIR__ . '/engine');
|
|
@ -49,6 +49,18 @@
|
|||
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
/*
|
||||
*---------------------------------------------------------------
|
||||
* EASY!APPOINTMENTS AUTOLOAD FILE
|
||||
*---------------------------------------------------------------
|
||||
*
|
||||
* Include Easy!Appointments autoload file so that namespace
|
||||
* classes are loaded automatically.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/autoload.php';
|
||||
|
||||
|
||||
/*
|
||||
*---------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue