MENU

Composer中移除自动加载的文件

November 20, 2017 • PHP

composer.json中增加了autoload块中加了autoload部分。我本地是php5.3

{
  ....
    "require": {
        .....
        "symfony/var-dumper": "^3.3"
    },
    "autoload": {
        "files": [
                "/home/vagrant/.composer/vendor/dd_helper.php"
        ]
    }
}

由于上面的dd_helper.php语法要>=5.5.9所以我本地无法使用。于是我习惯性的执行了下面的操作:

cd /home/vagrant/.composer
rm -rf vendor/dd_helper.php
composer global dump-autoload

composer报错

这是因为使用了全局global后,执行的composer命令每次都回去读取这个文件,而这个文件又被手动删除了,所以报错。

解决方法

最简单的办法就是重新创建一个空白文件,名字要和被删除的文件名一样,这里就是dd_helper.php。
然后将composer.json里的autoload块删除。最后执行

touch vendor/dd_helper.php
composer global dump-autoload

即可。


移出之前的autoload_file.php

[vagrant@localhost .composer]$ cat vendor/composer/autoload_files.php 
<?php

// autoload_files.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
    '667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
    '0a503c548965677117c773709cff5065' => $vendorDir . '/dd_helper.php',
);

移出之后的autoload_file.php

[vagrant@localhost .composer]$ cat vendor/composer/autoload_files.php 
<?php

// autoload_files.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
    '667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
);