web-push-php
web-push-php copied to clipboard
Uncaught Error: Class 'minishlink\WebPush\WebPush' not found
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
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
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 :
- delete composer.lock file
- delete vendor folder
- remove all the packages from composer.json except minishlink/web-push-php
- run composer install
- add the other package in composer.json
- 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 😊