PHP Classes

File: preloads/autoloader.php

Recommend this page to a friend!
  Packages of Michael Beck   XOOPS Publisher Module   preloads/autoloader.php   Download  
File: preloads/autoloader.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: XOOPS Publisher Module
Publish static HTML content and article with XOOPS
Author: By
Last change: Merge branch 'master' of https://github.com/XoopsModules25x/publisher
Low performing filesystem operations
Missing strict types declaration
Merge branch 'master' of https://github.com/XoopsModules25x/publisher
Date: 8 months ago
Size: 1,011 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

/**
 * @see http://www.php-fig.org/psr/psr-4/examples/
 */
spl_autoload_register(
    static function (
$class) {
       
// project-specific namespace prefix
       
$prefix = 'XoopsModules\\' . ucfirst(basename(dirname(__DIR__)));

       
// base directory for the namespace prefix
       
$baseDir = \dirname(__DIR__) . '/class/';

       
// does the class use the namespace prefix?
       
$len = mb_strlen($prefix);

        if (
0 !== strncmp($prefix, $class, $len)) {
            return;
        }

       
// get the relative class name
       
$relativeClass = mb_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 = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';

       
// if the file exists, require it
       
if (is_file($file)) {
            require
$file;
        }
    }
);