问题
My goal is to run a Composer's require
command to initialise a Symfony Console project.
When running composer's require
command, I believe it is possible to restrict the required package to specific a version.
I am considering using this to stick to the Long Term Release version of Symfony which will be supported for longer.
According to the Symfony Release Process the current LTS version is 3.4
.
According to Composer's require command documentation and Composer's version constraints documentation, the package and version can be specified as: symfony/console:~3.4
.
However, when I run the composer
command to install symfony/console 3.4 in an empty directory I get the following errors. (I have PHP and Composer is installed on my MacOS High Sierra):
$ mkdir foo
$ cd foo
$ composer self-update
You are already using composer version 1.6.2 (stable channel).
Johns-MBP:foo jw$ php --version
PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
I have created a new directory, changed into it, ensured composer is updated to the latest version and ensured PHP is 7.*.
$ composer require symfony/console:~3.4
No composer.json in current directory, do you want to use the one at /Users/me/Documents/Projects/FilterProject/filter-environment? [Y,n]? Y
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: don't install symfony/console v3.4.3
- Conclusion: don't install symfony/console v3.4.2
- Conclusion: don't install symfony/console v3.4.1
- symfony/process v2.6.4 conflicts with symfony/console[v3.4.0].
- symfony/console v3.4.0 conflicts with symfony/process[v2.6.4].
- Installation request for symfony/console ~3.4 -> satisfiable by symfony/console[v3.4.0, v3.4.1, v3.4.2, v3.4.3].
- Installation request for symfony/process (locked at v2.6.4, required as ~2.0) -> satisfiable by symfony/process[v2.6.4].
Installation failed, reverting ./composer.json to its original content.
I am quite new to Symfony and so may be misunderstanding the connection between the version number used for Symfony core versus the version number used by Symfony/console.
Which composer command does one run to require
the LTS version of Symfony Console in fresh project?
回答1:
I have managed to get this to work, thanks to @Cerad's comment.
First, I ensured that I have the latest version of composer and PHP 7.
Then I re-ran the command and spotted the problem:
I was installing this application in a sub-folder of a Homestead Improved project and composer was interactively asking me to use its composer.json
file!
I was being sloppy and did not read the interactive question fully. I assumed it was asking me to create a new composer.json
file. But instead it was asking if I wanted to ammend the composer.json file of the parent project above.
$ composer require symfony/console:~3.4
No composer.json in current directory, do you want to use
the one at /Users/me/Documents/Projects/FilterProject/filter-environment? [Y,n]? Y
If I answered Y
then my choice conflicts with some dependencies in the parent project.
By choosing the correct answer of n
I did not have a problem and it worked OK.
回答2:
Installation request for symfony/process (locked at v2.6.4).
This message means that your symfony/process
is locked at v2.6.4 (in your composer.lock
). Which is confusing, since Composer reported No composer.json
in current directory.
Since you've chosen Y
to load composer.json
from another folder (probably from the different non-related project), so next time try to not select it (by choosing n
). So you can install it on the empty folder. If you mean to install it globally, run: composer global require symfony/console
.
When you're working with the existing composer.json
and composer.lock
, try to update your dependencies by:
composer update --with-dependencies
Otherwise, consider removing composer.lock
and installing from scratch by composer install
.
来源:https://stackoverflow.com/questions/48429060/how-to-initialise-a-symfony-console-project-using-composer-in-a-way-that-constra