| 1 |
<?php |
| 2 |
namespace Dompdf; |
| 3 |
|
| 4 |
/** |
| 5 |
* Autoloads Dompdf classes |
| 6 |
* |
| 7 |
* @package Dompdf |
| 8 |
*/ |
| 9 |
class Autoloader |
| 10 |
{ |
| 11 |
const PREFIX = 'Dompdf'; |
| 12 |
|
| 13 |
/** |
| 14 |
* Register the autoloader |
| 15 |
*/ |
| 16 |
public static function register() |
| 17 |
{ |
| 18 |
spl_autoload_register([new self, 'autoload']); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Autoloader |
| 23 |
* |
| 24 |
* @param string |
| 25 |
*/ |
| 26 |
public static function autoload($class) |
| 27 |
{ |
| 28 |
if ($class === 'Dompdf\Cpdf') { |
| 29 |
require_once __DIR__ . "/../lib/Cpdf.php"; |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$prefixLength = strlen(self::PREFIX); |
| 34 |
if (0 === strncmp(self::PREFIX, $class, $prefixLength)) { |
| 35 |
$file = str_replace('\\', '/', substr($class, $prefixLength)); |
| 36 |
$file = realpath(__DIR__ . (empty($file) ? '' : '/') . $file . '.php'); |
| 37 |
if (file_exists($file)) { |
| 38 |
require_once $file; |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
} |