pusher / pusher-http-php

PHP library for interacting with the Pusher Channels HTTP API
https://pusher.com/docs/server_api_guide
1.4k stars 306 forks source link

Pusher being run at Laravel package:discover resulting in Argument Error #373

Open williwlwilliwll opened 1 year ago

williwlwilliwll commented 1 year ago

In my Dockerfile I have a step that installs Composer packages. After the installs are complete an artisan package:discover automatically executes and this errors out because Pusher can't find environment variables that it needs.

Why does Pusher actually get run by the package:discover command? Could I prefix the step in my Dockerfile with some 'temporary' env variables to get the build to succeed e.g. PUSHER_APP_KEY=foo PUSHER_APP_SECRET=bar composer install? Would this present any problems when I later to come set the actual values that I want when running the image as a container?

Cheers!

composer.json

 "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],

Terminal Output

#21 28.30 
#21 28.30    TypeError 
#21 28.30 
#21 28.30   Pusher\Pusher::__construct(): Argument #1 ($auth_key) must be of type string, null given, called in /var/www/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php on line 295
#21 28.30 
#21 28.30   at vendor/pusher/pusher-php-server/src/Pusher.php:63
#21 28.31      59▕      * @param ClientInterface|null $client [optional] - a Guzzle client to use for all HTTP requests
#21 28.31      60▕      *
#21 28.31      61▕      * @throws PusherException Throws exception if any required dependencies are missing
#21 28.31      62▕      */
#21 28.31   ➜  63▕     public function __construct(string $auth_key, string $secret, string $app_id, array $options = [], ClientInterface $client = null)
#21 28.31      64▕     {
#21 28.31      65▕         $this->check_compatibility();
#21 28.31      66▕ 
#21 28.31      67▕         if (!is_null($client)) {
stale[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you.

williwlwilliwll commented 10 months ago

Please keep this issue open, I think it is a valid question

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you.

watkit commented 8 months ago

I've just encountered the same problem. Seems a straightforward question, strange not to get an answer.

williwlwilliwll commented 8 months ago

@watkit

I have added the following code to my Dockerfile:

RUN export PUSHER_APP_ID="123abc" \
    && export PUSHER_APP_KEY="abc123" \
    && export PUSHER_APP_SECRET="1a2b3c" \
    && curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && composer install \
    && composer clear-cache

This circumvents the problem but it would still be nice to have a response from the project owners about why this is necessary at all.

watkit commented 8 months ago

Ah, good workaround, thanks for sharing! I ended up figuring out a way to maintain a .env file in prod and setting environment variables from there, in a similar vein to your Dockerfile idea, but would be handy for pusher (or laravel for my case) to have a supported way to manage this.

Guilhemfuel commented 7 months ago

I got same problem here, can't install project because of it

benw-pusher commented 4 months ago

I believe this is a result of the integration of Pusher (specifically this library) into the Laravel framework. package:discover registers service providers, and this process may be looking for the values identified in https://github.com/pusher/pusher-http-php/issues/373#issuecomment-1818581459.

You can prevent a library from being discovered with the below:

"extra": {
    "laravel": {
        "dont-discover": [
            "pusher/pusher-php-server"
        ]
    }
}