1<?php 2 3declare(strict_types=1); 4 5/** 6 * PSR-4 autoloader implementation for the DeviceDetector namespace. 7 * First we define the 'dd_autoload' function, and then we register 8 * it with 'spl_autoload_register' so that PHP knows to use it. 9 */ 10 11/** 12 * Automatically include the file that defines <code>class</code>. 13 * 14 * @param string $class 15 * the name of the class to load 16 * 17 * @return void 18 */ 19function dd_autoload(string $class): void 20{ 21 if (false === strpos($class, 'DeviceDetector\\')) { 22 return; 23 } 24 25 $namespaceMap = ['DeviceDetector\\' => __DIR__ . '/']; 26 27 foreach ($namespaceMap as $prefix => $dir) { 28 /* First swap out the namespace prefix with a directory... */ 29 $path = str_replace($prefix, $dir, $class); 30 /* replace the namespace separator with a directory separator... */ 31 $path = str_replace('\\', '/', $path); 32 /* and finally, add the PHP file extension to the result. */ 33 $path .= '.php'; 34 /* $path should now contain the path to a PHP file defining $class */ 35 require $path; 36 } 37} 38 39spl_autoload_register('dd_autoload'); 40