Symfony 2,autoload.php 在错误的目录中生成

Posted

技术标签:

【中文标题】Symfony 2,autoload.php 在错误的目录中生成【英文标题】:Symfony 2, autoload.php generated in wrong directory 【发布时间】:2020-04-02 22:47:47 【问题描述】:

我正在使用 symfony 2 并尝试运行 composer install --ignore-platform-reqs

以前可以,但现在重新设置时出现错误require_once(app/autoload.php): failed to open stream: No such file or directory

下面的完整错误:

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Generating autoload files
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap

Warning: require_once(app/autoload.php): failed to open stream: No such file or directory in /Users/macbook/www/myproject/source/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php on line 29

Fatal error: require_once(): Failed opening required 'app/autoload.php' (include_path='.:') in /Users/macbook/www/myproject/source/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php on line 29
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap handling the post-install-cmd event terminated with an exception


  [RuntimeException]                                     
  An error occurred when generating the bootstrap file.  

问题是它以前工作过。所以看起来app/autoload.php 总是在正确的位置。现在我正在进行全新安装,但它不存在。

我能够在vendors/autoload.php 中找到autoload.php,但不确定为什么它位于错误的位置。

我的 composer.json:


    "name": "symfony/framework-standard-edition",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": 
        "psr-0":  "": "src/" 
    ,
    "require": 
        "php": ">=5.3.3",
        "symfony/symfony": "2.1.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.0.*",
        "twig/extensions": "1.0.*@dev",
        "symfony/assetic-bundle": "2.1.*",
        "symfony/swiftmailer-bundle": "2.1.*",
        "symfony/monolog-bundle": "2.1.*",
        "sensio/distribution-bundle": "2.1.*",
        "sensio/framework-extra-bundle": "2.1.*",
        "sensio/generator-bundle": "2.1.*",
        "jms/security-extra-bundle": "1.2.*",
        "jms/di-extra-bundle": "1.1.*",
        "kriswallsmith/assetic": "1.1.*@dev",
        "doctrine/mongodb-odm-bundle": "3.0.*",
        "snc/redis-bundle": "2.1.*@dev",
        "doctrine/doctrine-fixtures-bundle": "dev-master",
        "incenteev/composer-parameter-handler": "~2.0"
    ,
    "minimum-stability": "dev",
    "scripts": 
        "post-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "update-parameters": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"
        ]
    ,
    "extra": 
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": 
            "file": "app/config/parameters.yml",
            "env-map": 
                "mongodb_server": "MONGODB_SERVER"

            
        
    

【问题讨论】:

“警告:锁文件不是最新的,因为 composer.json 中的最新更改”。看起来有人弄乱了 composer.json 并且没有创建新的锁定文件。可能会尝试删除锁定文件并再次更新。恐怕行不通。 app/autoload.php 应该已经签入到您的源代码存储库中。它不会生成,除非是一个新项目。只需从工作应用中复制即可。 【参考方案1】:

安装后,composer 从这个文件运行一个脚本:ScriptHandler.php,它获取配置键 symfony-app-dir 的路径并从文件中调用下一个脚本:build_bootstrap.php

如果您没有autoload.php 文件,您可能需要从autoload.php.dist 文件中复制它

【讨论】:

是的,应该在那里,但它被意外删除了。

以上是关于Symfony 2,autoload.php 在错误的目录中生成的主要内容,如果未能解决你的问题,请参考以下文章

symfony/workflow

PHP中spl_autoload_register函数的用法

打开失败需要'../vendor/autoload.php'

autoload.php 在那里时丢失

LARAVEL:main():打开失败需要'vendor\autoload.php'

要求(供应商/autoload.php):无法打开流