I've just installed Symfony 4 project and found this section in composer.json
:
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
],
...
I've found that section auto-scripts
is handled somehow differently by the Composer: key is a command to bin/console
and value is a command "type" (In this case it's Symfony's). As it is not documented on Composer website, I assume it's not legal definition, but it works, and my question is how the Composer knows how to execute such commands? How Composer knows what is symfony-cmd
?
A script, in Composer's terms, can either be a PHP callback (defined as a static method) or any command-line executable command. Scripts are useful for executing a package's custom code or package-specific commands during the Composer execution process.
To configure Composer for your PHP app json file specifies required packages. Verify that a composer. json file is present in the root of your git repository. Run composer install (on your local machine) to install the required packages and generate a composer.
symfony-cmd is a part of Symfony Flex. Your composer. json does not contain any requirement for Flex, so running composer require symfony/flex might resolve that problem. Follow this answer to receive notifications.
You can check your installed composer version using a command composer -v at the current path. Such as: composer -v.
It's as Cerad says. auto-script
is parsed by Symfony/Flex and the "right side" of a command:executable pair is processed by this switch-case.
switch ($type) {
case 'symfony-cmd':
return $this->expandSymfonyCmd($cmd);
case 'php-script':
return $this->expandPhpScript($cmd);
case 'script':
return $cmd;
Therefore Composer documentation can not say a word about that as it is Symfony-specific.
Personally don't like the mixing of standard Composer sections with custom ones on the composer.json root level. It simply confuses me and draws me into silent Composer documentation.
Also the naming itself, auto-script
, should be better. Something less magic and more self-explanatory, like flex-script
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With