Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Symfony/Installer/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ protected function updateComposerJson()

file_put_contents($filename, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");

$this->syncComposerLockFile();

return $this;
}

Expand Down Expand Up @@ -412,4 +414,19 @@ protected function getRemoteFileUrl()
{
return 'http://symfony.com/download?v=Symfony_Standard_Vendors_'.$this->version;
}

/**
* Updates the 'hash' value stored in composer.lock to avoid out-of-sync
* problems when the composer.json file contents are changed.
*/
private function syncComposerLockFile()
{
$composerFileContents = file_get_contents($this->projectDir.'/composer.json');
$lockFileContents = json_decode(file_get_contents($this->projectDir.'/composer.lock'), true);

$hash = md5($composerFileContents);
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did you find this behavior? In Composer itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

I found it here: https://github.com/composer/composer/blob/69210d5bc130f8cc9f96f99582a041254d7b9833/src/Composer/Factory.php#L309 But to be sure I made an md5 of several composer.json files and they matched the values stored in composer.lock.

$lockFileContents['hash'] = $hash;

file_put_contents($this->projectDir.'/composer.lock', json_encode($lockFileContents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

This will throw an error for PHP5.3 because the two constants do not exist. You might better use the 192 value which is the combination of these two constants.

Copy link
Member Author

Choose a reason for hiding this comment

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

The installer doesn't work with PHP 5.3. We prevent that here: https://github.com/symfony/symfony-installer/blob/master/symfony#L4

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tested the behavior to be sure the hash is correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! Here it is the summarized console output:

$ ./symfony new before

 Downloading Symfony...
 [...]

$ cd before/
$ composer install
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
[...]

$ cd ..
$ ./symfony new after

 Downloading Symfony...
 [...]

$ cd after
$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
[...]

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome then! 👍

}
}