When using the --composer-settings option in the PackageGenerator, the JSON keys are not correctly written to the composer.json file. They are written with a numeric key (as a string) when it should be the first key from the command line option. We're using the latest .phar file (v 4.1.13) on Windows.
In this example, the first key should be "autoload." However, the key is written to composer.json as a "0" or "1", depending on the number of times the --composer-settings option is used.
To Reproduce
Here is an example Windows batch file that our group uses to generate the package:
Looking at the source code, the GeneratorOptions class has a static method called dotNotationToArray. It appears this method is responsible for exploding the string via the . char, which is how the composer arguments are delimited on the command line.
I did some testing locally using the PHP interpreter. Unfortunately I am not able to fork the repo and install the dependencies due to limitations at my organization. However, when using the PHP interpreter, I called dotNotationToArray and the results are as expected (see below).
But one thing that caught my attention is that the dotNotationToArray method is marked as static in the source code. Yet it accesses the $array value by reference. That is one difference between the source code and the command line sample shown below. I don't know if this is an issue, but it caught my attention to see a static function access a value by reference when the containing class is not static, which is the case for GeneratorOptions. In other words, the GeneratorOptions class is instance, the $array is instance, but the dotNotationToArray function is static.
This is likely unrelated to the --composer-settings issue, but it's worth noting that the package source folder is not correctly written to composer.json, similar to issue #306. The value should have forward slashes but instead it has back slashes.
Describe the bug
When using the
--composer-settings
option in the PackageGenerator, the JSON keys are not correctly written to the composer.json file. They are written with a numeric key (as a string) when it should be the first key from the command line option. We're using the latest .phar file (v 4.1.13) on Windows.Example:
In this example, the first key should be "autoload." However, the key is written to composer.json as a "0" or "1", depending on the number of times the
--composer-settings
option is used.To Reproduce
Here is an example Windows batch file that our group uses to generate the package:
And here is the final output in composer.json:
Expected behavior
The JSON is not formatted correctly.
Instead of this:
It should be this:
Additional context
Looking at the source code, the
GeneratorOptions
class has a static method calleddotNotationToArray
. It appears this method is responsible for exploding the string via the.
char, which is how the composer arguments are delimited on the command line.I did some testing locally using the PHP interpreter. Unfortunately I am not able to fork the repo and install the dependencies due to limitations at my organization. However, when using the PHP interpreter, I called
dotNotationToArray
and the results are as expected (see below).But one thing that caught my attention is that the
dotNotationToArray
method is marked as static in the source code. Yet it accesses the$array
value by reference. That is one difference between the source code and the command line sample shown below. I don't know if this is an issue, but it caught my attention to see a static function access a value by reference when the containing class is not static, which is the case forGeneratorOptions
. In other words, theGeneratorOptions
class is instance, the$array
is instance, but thedotNotationToArray
function is static.Extra Information
This is likely unrelated to the
--composer-settings
issue, but it's worth noting that the package source folder is not correctly written to composer.json, similar to issue #306. The value should have forward slashes but instead it has back slashes.Instead of this:
It should be this: