8000 [CreateProject] allowed pretty constraint by bamarni · Pull Request #2431 · composer/composer · GitHub
[go: up one dir, main page]

Skip to content

[CreateProject] allowed pretty constraint #2431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2013

Conversation

bamarni
Copy link
Contributor
@bamarni bamarni commented Nov 19, 2013

This PR allows to put pretty constrains when creating a project. It would make instructions easier for frameworks installable through composer, for example Symfony says :

$ php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/Symfony 2.3.0

"For an exact version, replace "2.3.0" with the latest Symfony version. For details, see the Symfony Installation Page"
http://symfony.com/doc/current/book/installation.html#option-1-composer

With this patch the version could be changed to "2.3.*" or "~2.3" for example, what do you think?

@@ -265,10 +265,13 @@ protected function installRootPackage(IOInterface $io, $config, $packageName, $d
$packageVersion = $requirements[0]['version'];
}

$pool = new Pool($packageVersion ? 'dev' : $stability);
if ('stable' != $packageStability = VersionParser::parseStability($packageVersion)) {
$stability = $packageStability;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would default $stability to null and then always override it with the package's stability only if the stability wasn't set explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what you mean, are you saying command --stability option should win over package explicit stability?

Btw I didn't find a clean way to check whether the stability is explicitely set on the package version, I'm checking VersionParser::parseStability return, if it's not "stable" I can assume it's explicitely set, but it doesn't detects "1.1.*@stable" for example, is there a cleaner way?

Edit: hum actually something like "1.1.*@stable" shouldn't be considered here as stable is the default stability anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To parse @stable you can use: preg_match('{^[^,\s]*?@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $packageVersion, $match)

And yes, I meant that --stability should win over package explicit stability, because it's unlikely that both are given together but if a stability is explicitly given I guess the intent is to set it to that, so keeping it that way means no BC break.

So I would say it should use the first match in this order:

  • --stability if set
  • @.. if found
  • parseStability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't --stabililty always set (as it has a default in the command configuration)?

Edit : well I could remove the default and take care of this at runtime, thanks for your clear explanations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that indeed was the I would default $stability to null part in my somewhat fuzzy original post :)

@bamarni
Copy link
Contributor Author
bamarni commented Nov 19, 2013

It should be ok now, I've also updated a doc example to reflect the change.

@@ -57,7 +57,7 @@ protected function configure()
new InputArgument('package', InputArgument::OPTIONAL, 'Package name to be installed'),
new InputArgument('directory', InputArgument::OPTIONAL, 'Directory where the files should be created'),
new InputArgument('version', InputArgument::OPTIONAL, 'Version, will defaults to latest'),
new InputOption('stability', 's', InputOption::VALUE_REQUIRED, 'Minimum-stability allowed (unless a version is specified).', 'stable'),
new InputOption('stability', 's', InputOption::VALUE_OPTIONAL, 'Minimum-stability allowed (unless a version is specified).'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should leave it to VALUE_REQUIRED, it doesn't mean you have to pass a value, but that if you have --stability then it must be followed by a value, and that --stability by itself is invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely, fixed and squashed.

Seldaek added a commit that referenced this pull request Nov 20, 2013
@Seldaek Seldaek merged commit bbd9b7f into composer:master Nov 20, 2013
@Seldaek
Copy link
Member
Seldaek commented Nov 20, 2013

Thanks!

digitalkaoz pushed a commit to digitalkaoz/composer that referenced this pull request Nov 22, 2013
…onstraint

[CreateProject] allowed pretty constraint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0