dolibarr/htdocs/includes/mike42/escpos-php/autoload.php

27 lines
804 B
PHP
Raw Normal View History

2019-11-02 21:15:48 +01:00
<?php
/**
* Users who do not have 'composer' to manage dependencies, include this
2020-12-07 20:25:54 +01:00
* file to provide auto-loading of the classes in this library.
2019-11-02 21:15:48 +01:00
*/
2020-12-07 20:25:54 +01:00
spl_autoload_register ( function ($class) {
2019-11-02 21:15:48 +01:00
/*
* PSR-4 autoloader, based on PHP Framework Interop Group snippet (Under MIT License.)
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
*/
$prefix = "Mike42\\";
$base_dir = __DIR__ . "/src/Mike42/";
2020-12-07 20:25:54 +01:00
2019-11-02 21:15:48 +01:00
/* Only continue for classes in this namespace */
2020-12-07 20:25:54 +01:00
$len = strlen ( $prefix );
if (strncmp ( $prefix, $class, $len ) !== 0) {
2019-11-02 21:15:48 +01:00
return;
}
2020-12-07 20:25:54 +01:00
2019-11-02 21:15:48 +01:00
/* Require the file if it exists */
2020-12-07 20:25:54 +01:00
$relative_class = substr ( $class, $len );
$file = $base_dir . str_replace ( '\\', '/', $relative_class ) . '.php';
if (file_exists ( $file )) {
2019-11-02 21:15:48 +01:00
require $file;
}
} );