Subversion Repositories oidplus

Rev

Rev 1069 | Rev 1146 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1069 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
20
spl_autoload_register(function ($class_name) {
21
        static $class_refs = null;
22
 
23
        // We only load based on the last element of the class name (ignore namespace)
24
        // If there are multiple classes matching that name we just include all class files
25
        $path = explode('\\',$class_name);
26
        $class_name = end($path);
27
 
28
        if (is_null($class_refs)) {
29
                $valid_plugin_folders = array(
30
                        'adminPages',
31
                        'auth',
32
                        'database',
33
                        'design',
34
                        'language',
35
                        'logger',
36
                        'objectTypes',
37
                        'publicPages',
38
                        'raPages',
39
                        'sqlSlang',
40
                        'captcha'
41
                );
42
 
43
                $func = function(&$class_refs, $class_files, $namespace='') {
44
                        foreach ($class_files as $filename) {
45
                                $cn = strtolower(basename($filename));
46
                                $cn = preg_replace('@(\\.class){0,1}\\.phps{0,1}$@', '', $cn);
47
                                if (!empty($namespace)) {
48
                                        if (substr($namespace,-1,1) !== '\\') $namespace .= '\\';
49
                                        $cn = strtolower($namespace) . $cn;
50
                                }
51
                                if (!isset($class_refs[$cn])) {
52
                                        $class_refs[$cn] = array($filename);
53
                                } else {
1116 daniel-mar 54
                                        $class_refs[$cn][] = $filename;
1069 daniel-mar 55
                                }
56
                        }
57
                };
58
 
59
                $class_files = array();
60
 
61
                // Global namespace / OIDplus
62
                // (the last has the highest priority)
63
                foreach ($valid_plugin_folders as $folder) {
64
                        $class_files = array_merge($class_files, glob(__DIR__ . '/../plugins/'.'*'.'/'.$folder.'/'.'*'.'/'.'*'.'.class.php'));
65
                }
66
                $class_files = array_merge($class_files, glob(__DIR__ . '/classes/'.'*'.'.class.php'));
67
                $class_files = array_merge($class_files, glob(__DIR__ . '/../vendor/danielmarschall/fileformats/'.'*'.'.class.php'));
68
                $class_files = array_merge($class_files, glob(__DIR__ . '/../vendor/danielmarschall/php_utils/'.'*'.'.class.php'));
69
                $class_files = array_merge($class_files, glob(__DIR__ . '/../vendor/danielmarschall/oidconverter/php/'.'*'.'.class.phps'));
70
                $func($class_refs, $class_files);
71
        }
72
 
73
        $class_name = strtolower($class_name);
74
        if (isset($class_refs[$class_name])) {
75
                foreach ($class_refs[$class_name] as $inc) {
76
                        require $inc;
77
                }
78
                unset($class_refs[$class_name]); // this emulates a "require_once" and is faster
79
        }
80
});