Skip to content

Instantly share code, notes, and snippets.

@lstrojny
Created April 16, 2013 11:27
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lstrojny/5395218 to your computer and use it in GitHub Desktop.
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.
<?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()
{}
}
@elfeffe
Copy link

elfeffe commented Apr 18, 2019

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