1<?php 2 3/** 4 * Simple PSR-4 autoloader 5 * 6 * Based on PSR-4 example code 7 * 8 * @link http://www.php-fig.org/psr/psr-4/examples/ 9 * @param string $class The fully-qualified class name. 10 * @return void 11 */ 12spl_autoload_register(function($class) { 13 $namespaces = array( 14 'Psr\\Log\\' => __DIR__ . '/subtree/php-fig/log/Psr/Log/', 15 'Tx\\' => __DIR__ . '/subtree/txtthinking/Mailer/src/', 16 'splitbrain\\dokuwiki\\plugin\\smtp\\' => __DIR__ . '/classes/' 17 ); 18 19 foreach($namespaces as $prefix => $base_dir) { 20 // does the class use the namespace prefix? 21 $len = strlen($prefix); 22 if (strncmp($prefix, $class, $len) !== 0) { 23 // no, move to the next 24 continue; 25 } 26 27 // get the relative class name 28 $relative_class = substr($class, $len); 29 30 // replace the namespace prefix with the base directory, replace namespace 31 // separators with directory separators in the relative class name, append 32 // with .php 33 $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; 34 35 // if the file exists, require it 36 if (file_exists($file)) { 37 require $file; 38 } 39 } 40}); 41