Symfony 2.6 error after using composer: “Vendor libraries must be installed”

青春壹個敷衍的年華 提交于 2019-12-23 11:58:10

问题


After creating or updating a Symfony 2.6.1 project with composer, I get a "Vendor libraries must be installed" error and it suggests running php composer.phar install to install them.

The exact steps I'm taking:-

composer create-project symfony/framework-standard-edition my_new_project/
cd my_new_project

This appears to run without any problems, and as far as I can tell, does download all the necessary vendor packages. However if I then run:-

php app/check.php

This results in:-

* Vendor libraries must be installed
  > Vendor libraries are missing. Install composer following
  > instructions from http://getcomposer.org/. Then run "php
  > composer.phar install" to install them.

I've tried running composer update, composer install, deleting the composer cache, but nothing I have tried so far resolves this error.

From testing numerous versions of Symfony, I get this error with all versions of Symfony >= 2.5.0. Any project I create in the same way using Symfony <= 2.4.8 works just fine.

I'm running PHP 5.6.4 (installed via MacPorts) on OS X.

I'm bit of a noob when it comes to composer, so any help would be much appreciated!


回答1:


This issue is here:

/**
 * In some special setups, the vendor/ directory isn't located in the project's
 * root directory. To make this command work for every case, read Composer's
 * vendor/ directory location directly from composer.json file.
 *
 * @return string
 */
private function getComposerVendorDir()
{
    $composerJson = json_decode(file_get_contents(__DIR__.'/../composer.json'));
    if (isset($composerJson->config)) {
        return $composerJson->config->{'vendor-dir'};
    }

    return __DIR__.'/../vendor/composer';
}

Specifically:

return $composerJson->config->{'vendor-dir'};

The condition on isset($composerJson->config) returns true, which leads to the above statement. However when you look at the generated composer.json:

"config": {
    "bin-dir": "bin"
},

The vendor-dir is missing. Generating the notice:

PHP Notice:  Undefined property: stdClass::$vendor-dir

Therefore the function returns null, so this requirement fails:

$this->addRequirement(
    is_dir($this->getComposerVendorDir()), // <-- HERE
    'Vendor libraries must be installed',
    'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
        'Then run "<strong>php composer.phar install</strong>" to install them.'
);

This is a bug on the symfony/symfony-standard. It's likely it is already in line to be fixed, but you may as well raise it on Github.

EDIT:

It looks like they already have, 2.7 uses:

$this->addRequirement(
    is_dir(__DIR__.'/../vendor/composer'),
    'Vendor libraries must be installed',
    'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
    'Then run "<strong>php composer.phar install</strong>" to install them.'
);

There is nothing wrong with your project, its just a bug in the standard edition. So long as you are autoloading classes properly you are fine.



来源:https://stackoverflow.com/questions/27744855/symfony-2-6-error-after-using-composer-vendor-libraries-must-be-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!