2

I'm trying to create a composer post-install-cmd that would send a simple post request. I'm using this simple block elsewhere in the application to submit the same request to a development server:

    $ESmapping = file_get_contents('path/to/mapping.json');
    /** @var GuzzleHttp\Message\Response $ESresponse */
    $ESresponse = (new Guzzle())->post($ESmappingUrl, ["body" => $ESmapping]);

This exact code works in a Symfony2 console command, but when I try to send that request in a composer command, it fails with the following:

PHP Fatal error:  Call to undefined function GuzzleHttp\Stream\create() in /srv/www/htdocs/instagram-extractor/vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php on line 179

Fatal error: Call to undefined function GuzzleHttp\Stream\create() in /srv/www/htdocs/instagram-extractor/vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php on line 179

I tried creating the stream beforehand using $stream = Stream::factory('string data');, but it failed with the same error (undefined Stream\create()), just obviously with a different class calling the method.

I haven't found any single clue regarding this issue, any help would be appreciated!

Thanks!

Edit: I suspected it might be an autoloader issue, so I tried changing psr-0 to psr-4 with no success.

4
  • Are you using the Composer autoloader or a custom one? Guzzle uses a 'files' entry in it's composer.json github.com/guzzle/guzzle/blob/master/composer.json#L31 The composer autoloader loads this, but there are reports of others not bothering to implement that feature.
    – Danack
    Sep 22, 2014 at 11:49
  • I'm actually using composer's autoloader. It's working elsewhere in the application, just not when the command is executed by composer. It seems odd to me that it would use different autoloading methods for its own command though.
    – kachnitel
    Sep 23, 2014 at 6:54
  • That's weird then. You should probably debug the composer autoloader....in autoload_real.php there should be something like "$includeFiles = require DIR . '/autoload_files.php';" - it should be getting loaded through there.
    – Danack
    Sep 23, 2014 at 12:42
  • Thanks, looking into these, there is ` $vendorDir . '/guzzlehttp/guzzle/src/functions.php',` in autoload_files.php indeed. I wonder how have I missed it going through these files the first time. However, it appears the file doesn't get included for some reason, I'll try to debug the composerRequire..() function and see if it gets run at all while running the command.
    – kachnitel
    Sep 23, 2014 at 20:30

1 Answer 1

2

Figured out Composer isn't autoloading the stream functions file. This dirty hack works around it:

require 'vendor/guzzlehttp/streams/src/functions.php';

I still wonder if there's a better solution to this?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.