Skip to content

Commit

Permalink
Merge pull request #183 from alprs/fix-autoloader
Browse files Browse the repository at this point in the history
Ensure compatibility with multiple composer autoloaders
  • Loading branch information
nikic committed Mar 14, 2015
2 parents 251e689 + d225555 commit 68defc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/PhpParser/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@
*/
class Autoloader
{
/**
* Whether the autoloader has been registered.
*
* @var boolean
*/
protected static $registered = false;

/**
* Registers PhpParser\Autoloader as an SPL autoloader.
*
* @param bool $prepend Whether to prepend the autoloader instead of appending
*/
static public function register($prepend = false) {
if (static::$registered === true) {
return;
}
ini_set('unserialize_callback_func', 'spl_autoload_call');
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
static::$registered = true;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

require __DIR__ . '/PhpParser/Autoloader.php';
PhpParser\Autoloader::register();
if (!class_exists('PhpParser\Autoloader')) {
require __DIR__ . '/PhpParser/Autoloader.php';
}
PhpParser\Autoloader::register();

0 comments on commit 68defc2

Please sign in to comment.