1<?php 2 3/** 4 * PSR-4 autoloader implementation for the MaxMind\DB namespace. 5 * First we define the 'mmdb_autoload' function, and then we register 6 * it with 'spl_autoload_register' so that PHP knows to use it. 7 * 8 * @param mixed $class 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 */ 17function mmdb_autoload($class) 18{ 19 /* 20 * A project-specific mapping between the namespaces and where 21 * they're located. By convention, we include the trailing 22 * slashes. The one-element array here simply makes things easy 23 * to extend in the future if (for example) the test classes 24 * begin to use one another. 25 */ 26 $namespace_map = ['MaxMind\\Db\\' => __DIR__ . '/src/MaxMind/Db/']; 27 28 foreach ($namespace_map as $prefix => $dir) { 29 /* First swap out the namespace prefix with a directory... */ 30 $path = str_replace($prefix, $dir, $class); 31 32 /* replace the namespace separator with a directory separator... */ 33 $path = str_replace('\\', '/', $path); 34 35 /* and finally, add the PHP file extension to the result. */ 36 $path = $path . '.php'; 37 38 /* $path should now contain the path to a PHP file defining $class */ 39 if (file_exists($path)) { 40 include $path; 41 } 42 } 43} 44 45spl_autoload_register('mmdb_autoload'); 46