Created
April 16, 2013 11:27
-
-
Save lstrojny/5395218 to your computer and use it in GitHub Desktop.
Replace Magento autoloader with composer based autoloader. Note: you are losing the ability to use the compiler.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Classes source autoload | |
*/ | |
class Varien_Autoload | |
{ | |
/** @var \Composer\Autoload\ClassLoader */ | |
private static $autoloader; | |
/** @var self */ | |
private static $instance; | |
/** | |
* Singleton pattern implementation | |
* | |
* @return Varien_Autoload | |
*/ | |
static public function instance() | |
{ | |
if (!self::$instance) { | |
self::$instance = new Varien_Autoload(); | |
} | |
return self::$instance; | |
} | |
/** | |
* Register composer autoloader | |
*/ | |
static public function register() | |
{ | |
if (!static::$autoloader) { | |
static::$autoloader = require __DIR__ . '/../../../../vendor/autoload.php'; | |
} | |
} | |
/** | |
* Load class source code | |
* | |
* @param string $class | |
* @return bool | |
*/ | |
public function autoload($class) | |
{ | |
return static::$autoloader->loadClass($class); | |
} | |
public function registerScope($scope) | |
{} | |
public static function getScope() | |
{} | |
} |
Being able to have external, non-Magento, libraries brought in via composer.
This is really great!
Thank you
I will just change require for require_once, just in case you have some plugin like Hackaton one, that also load autoloader
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
benefit?