web-push-php icon indicating copy to clipboard operation
web-push-php copied to clipboard

Uncaught Error: Class 'minishlink\WebPush\WebPush' not found

Open LaurentWi opened this issue 4 years ago • 2 comments

Setup

PHP 7.2 Last version of webpush

Please check that you have installed and enabled these PHP extensions :

gmp, mbstring, curl, openssl are all enabled

Please select any browsers that you are experiencing problems with:

All browsers

Please specify the versions (i.e. Chrome Beta, Firefox Beta etc).

All versions

I get the following error message: Fatal error: Uncaught Error: Class 'Minishlink\WebPush\Subscription' not found in ... when using this code: use Minishlink\WebPush\WebPush; use Minishlink\WebPush\Subscription;

// array of notifications $notifications = [ [ 'subscription' => Subscription::create([ 'endpoint' => $endpoint, // Firefox 43+, 'publicKey' => $publicKey, // base 64 encoded, should be 88 chars 'authToken' => $authToken, // base 64 encoded, should be 24 chars ]), 'payload' => 'hello !', ] ];

I have installed the package with composer and i see all files in the directory: Encryption.php MessageSentReport.php Notification.php Subscription.php SubscriptionInterface.php Utils.php VAPID.php WebPush.php

I have seen someone with the same error message in the list of issues here but in his case there was a file missing which is not my case.

Any idea?

Thanks

LaurentWi avatar Apr 06 '21 15:04 LaurentWi

Hi

Same problem for me with 6.0 version

You have to make an array of the $notifications an use this method to send :

foreach ($notifications as $notification) { $webPush->queueNotification( $notification['subscription'], $notification['payload'] ); }

foreach ($webPush->flush() as $report) { $endpoint = $report->getRequest()->getUri()->__toString(); if ($report->isSuccess()) {
// do something } else {
//$report->getReason() } }

And don't forget to autoload

a-polounovsky avatar Sep 30 '21 02:09 a-polounovsky

Hi,

I spent over 12 hours looking for solutions ☹ This is how i solve this issue, maybe it is not the best way but it worked for me :

  1. delete composer.lock file
  2. delete vendor folder
  3. remove all the packages from composer.json except minishlink/web-push-php
  4. run composer install
  5. add the other package in composer.json
  6. run composer update

This idea came to me after testing web-push-php in a new project composer and seeing that it worked fine. Hope it will help someone 😊

yoan-theophile avatar Sep 22 '22 11:09 yoan-theophile