LoginSignup
6
6

More than 5 years have passed since last update.

Composer のオートロードを自作関数に閉じ込めて使う

Posted at
// 通常
// require_once __DIR__ . 'path/to/vendor/autoload.php';
my_composer_autoloader();

/**
 * @return Composer\Autoload\ClassLoader
 */
function my_composer_autoloader() {
    static $loader;
    return $loader ?: $loader = require __DIR__ . '/path/to/vendor/autoload.php';
}

// composer.json を記述するほどでは無いクラスなど
$loader = my_composer_autoloader();
$loader->setPsr4( 'MyClass\\', __DIR__ . '/my/class' );

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6