I installed a dependency (Minishlink Web-Push) via composer2 on my server. The installation returned a success and in my homepages file manager I find the files composer.json and composer.lock now.
The files show the dependency I want to use.
However, sending an Ajax POST request to my php file returns an internal server error as soon as I enter a piece of code that is trying to access the dependency. I tried several ways to access the dependency, but it does not work.
Internal server Error:
POST <MY_URL> 500 (Internal Server Error)
My php file, accessed with an Ajax POST request:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// probably needed to initialize an instance of my dependency
$auth = [
'VAPID' => [
'subject' => 'https://<MY_DOMAIN>',
'publicKey' => '<SERVER_PUBLIC_KEY>',
'privateKey' => '<SERVER_PRIVATE_KEY>'
]
];
// I tried all eight options below:
$webPush = new MinishlinkWebPushWebPush($auth);
//ERROR: PHP Fatal error: Uncaught Error: Class "MinishlinkWebPushWebPush" not found in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php
$webPush = new MinishlinkWebPushWebPush($auth);
//ERROR: PHP Fatal error: Uncaught Error: Class "MinishlinkWebPushWebPush" not found in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php
$webPush = new /Minishlink/WebPush/WebPush($auth);
$webPush = new Minishlink/WebPush/WebPush($auth);
use MinishlinkWebPushWebPush;
$webPush = new WebPush($auth);
//ERROR: PHP Parse error: syntax error, unexpected token "use" in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php
use MinishlinkWebPushWebPush;
$webPush = new WebPush($auth);
//ERROR: PHP Parse error: syntax error, unexpected token "use" in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php
use /Minishlink/WebPush/WebPush;
$webPush = new WebPush($auth);
//ERROR: PHP Parse error: syntax error, unexpected token "use" in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php
use Minishlink/WebPush/WebPush;
$webPush = new WebPush($auth);
//ERROR: PHP Parse error: syntax error, unexpected token "use" in /home/<USER>/domains/<MY_DOMAIN>/public_html/push/subscription.php
// general success variable
$success = true;
// build response object
$response = (object) ['success' => $success, 'data' => (object) []];
// return response
echo json_encode($response);
//--> without dependency it returns {success: true, data: {}}
}