Skip to content
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

Composer::getComposerFilePath() must be of the type string, bool returned #246

Closed
tbl0605 opened this issue Apr 5, 2021 · 4 comments
Closed
Assignees
Labels
bug to be released Issue that is ready to be released

Comments

@tbl0605
Copy link

tbl0605 commented Apr 5, 2021

Hi,
after updating the package generator from version 3.3.4 to version 4.1.0, I've get following error when starting the generator in standalone mode:

Return value of WsdlToPhp\PackageGenerator\File\Composer::getComposerFilePath() must be of the type string, bool returned
at ...\wsdltophp\packagegenerator\src\File\Composer.php(146)
#0 ...\wsdltophp\packagegenerator\src\File\Composer.php(121): WsdlToPhp\PackageGenerator\File\Composer->getComposerFilePath()
#1 ...\wsdltophp\packagegenerator\src\File\Composer.php(72): WsdlToPhp\PackageGenerator\File\Composer->getComposerFileContent()
#2 ...\wsdltophp\packagegenerator\src\File\Composer.php(57): WsdlToPhp\PackageGenerator\File\Composer->completeComposerJson()
#3 ...\wsdltophp\packagegenerator\src\File\AbstractFile.php(40): WsdlToPhp\PackageGenerator\File\Composer->writeFile()
#4 ...\wsdltophp\packagegenerator\src\Generator\GeneratorFiles.php(106): WsdlToPhp\PackageGenerator\File\AbstractFile->write()
#5 ...\wsdltophp\packagegenerator\src\Generator\GeneratorFiles.php(41): WsdlToPhp\PackageGenerator\Generator\GeneratorFiles->generateComposerFile()
#6 ...\wsdltophp\packagegenerator\src\Generator\Generator.php(1092): WsdlToPhp\PackageGenerator\Generator\GeneratorFiles->doGenerate()
#7 ...\wsdltophp\packagegenerator\src\Generator\Generator.php(58): WsdlToPhp\PackageGenerator\Generator\Generator->doGenerate()
#8 ...\main.php: WsdlToPhp\PackageGenerator\Generator\Generator->generatePackage()

My code is very similar to the README example:

        $options = GeneratorOptions::instance();
        $options->setOrigin(TEMP_DIR . '/roc.wsdl')
            ->setDestination(OUTPUT_DIR)
            ->setComposerName('mycompany/roc');
        // Generator instanciation
        $generator = new Generator($options);
        // Package generation
        $generator->generatePackage();

Workaround:
When I manually create a composer.json file directly in the output dir, the generator works again (and the PHP files are correctly generated) but the composer.json file isn't updated, the composer.lock file isn't created and the vendor directory isn't created.

Expected:
The composer.json file, the composer.lock file and the vendor directory should automatically be created.

The culprit is following code in WsdlToPhp\PackageGenerator\File\Composer, that expects composer.json to exist, even in standalone mode:

    protected function getComposerFilePath(): string
    {
        return realpath(sprintf('%s/composer.json', $this->getGenerator()->getOptionDestination()));
    }
@mikaelcom
Copy link
Member

Probably the cause of the issue #206

@mikaelcom
Copy link
Member

Actually, the composer.json file is first created by Composer itself at https://github.com/WsdlToPhp/PackageGenerator/blob/develop/src/File/Composer.php#L39-L55.

Could you try adding a exit(); call after these lines and check if Composer succeeds to initiate the composer.json file?

@tbl0605
Copy link
Author

tbl0605 commented Apr 5, 2021

Oh well, you are right!
I've previously launched my script using Apache, but when I launch same script as PHP CLI everything works as expected:

Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug
Writing composer.json
Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug
Loading composer repositories with package information
Updating dependencies
Dependency resolution completed in 0.002 seconds
Analyzed 87 packages to resolve dependencies
Analyzed 95 rules to resolve dependencies
Lock file operations: 1 install, 0 updates, 0 removals
Installs: wsdltophp/packagebase:5.0.1
  - Locking wsdltophp/packagebase (5.0.1)
Writing lock file
Installing dependencies from lock file
Package operations: 1 install, 0 updates, 0 removals
Installs: wsdltophp/packagebase:5.0.1
  - Installing wsdltophp/packagebase (5.0.1): Extracting archive
Generating optimized autoload files

Feel free to close my bug report, since it works as expected in CLI mode.

And thank you for your great work :)

@mikaelcom
Copy link
Member

I'll improve the method anyway, thanks for your feedback.

@mikaelcom mikaelcom added the to be released Issue that is ready to be released label Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug to be released Issue that is ready to be released
Projects
None yet
Development

No branches or pull requests

2 participants