Skip to content

Conversation

@spk
Copy link

@spk spk commented Dec 5, 2025

Summary

Fixes Composer detection when using Nix package manager, which wraps Composer in a C binary that executes the actual PHP script located at .composer-wrapped.

          W: Run composer recipes at any time to see the status of your Symfony recipes.
          W: 
          W: 
          W:   WARNING: Detected Composer file (/nix/store/vmckm13xcakaiznfzz5mfvlwzs5633ka-composer-2.8.12/bin/composer) is not a valid PHAR or PHP script.
          W:   Downloading Composer for you, but it is recommended to install Composer yourself, instructions available at https://getcomposer.org/download/
          W:   (running php /tmp/web/.symfony5/composer/composer.phar dump-env prod)
          W: 
          W: Successfully dumped .env files in .env.local.php
          W: 
          W:   WARNING: Detected Composer file (/nix/store/vmckm13xcakaiznfzz5mfvlwzs5633ka-composer-2.8.12/bin/composer) is not a valid PHAR or PHP script.
          W:   Downloading Composer for you, but it is recommended to install Composer yourself, instructions available at https://getcomposer.org/download/
          W:   (running php /tmp/web/.symfony5/composer/composer.phar install --prefer-dist --optimize-autoloader --classmap-authoritative --no-progress --no-ansi --no-interaction)

Changes

  • Enhanced isPHPScript() to detect Nix-style wrappers by checking for .{basename}-wrapped sibling files
  • Added isPHPScriptDirect() helper function to validate PHP scripts
  • Added comprehensive test coverage for Nix wrapper scenarios

Test Plan

  • ✅ All existing unit tests pass (13/13 in php package)
  • ✅ New TestIsPHPScriptNixWrapper test validates both valid and invalid Nix wrappers
  • ✅ Verified with actual Nix Composer installation - no more false warning

Nix package manager wraps Composer in a C binary that executes the actual
PHP script located at .composer-wrapped. The previous isPHPScript validation
only checked the wrapper binary itself, which is not a PHP script, causing
a false negative and unnecessary Composer downloads.

This change enhances isPHPScript to detect Nix-style wrappers by checking
for a .{basename}-wrapped sibling file and validating that instead.
@tucksaun
Copy link
Member

tucksaun commented Dec 5, 2025

Thank you for this PR.

But does is actually work? I mean, the detected file is then run by passing it as a first argument to PHP, which would not work with a binary wrapper (at mentioned in #424.

… php

Nix wrapper binaries need to be executed directly, not with the php command.
The previous version incorrectly tried to run 'php /path/to/wrapper' which
failed because the wrapper is an ELF binary.

Changes:
- Split isPHPScript logic into isPHPScriptDirect and isNixWrapper
- Execute Nix wrappers directly (like SYMFONY_COMPOSER_PATH)
- Execute regular PHP scripts with php command
- Improved error handling and messaging
@spk
Copy link
Author

spk commented Dec 5, 2025

Thank you for this PR.

But does is actually work? I mean, the detected file is then run by passing it as a first argument to PHP, which would not work with a binary wrapper (at mentioned in #424.

Thanks for the comments. After the last fix it works it you use the nix binary directly you will have the warning, even tho its a valid working composer installation. You can reproduce it by using the symphony cli from main and on a project run:

export PATH="/nix/store/vmckm13xcakaiznfzz5mfvlwzs5633ka-composer-2.8.12/bin:/usr/local/bin:/usr/bin:/bin"

/tmp/symfony-cli-old composer install
  WARNING: Detected Composer file (/nix/store/vmckm13xcakaiznfzz5mfvlwzs5633ka-composer-2.8.12/bin/composer) is not a valid PHAR or PHP script.
  Downloading Composer for you, but it is recommended to install Composer yourself, instructions available at https://getcomposer.org/download/
  (running php /home/spk/.config/symfony-cli/composer/composer.phar install)

Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating autoload files
2 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

with this PR we run the binary directly when the wrapper is a valid php script and won't have the warning anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants