I want to send push notifications to iPhone devices by writing PHP code for it.
gomoob:php-pushwoosh is a PHP Library that easily work with the pushwoosh REST Web Services.
This is the URL for gomoob:php-pushwoosh
As per the instructions I've installed gomoob:php-pushwoosh on my local machine using Composer at location '/var/www/gomoob-php-pushwoosh'
I wrote following code in a file titled sample_1.php
which is present at location '/var/www/gomoob-php-pushwoosh/sample_1.php'
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
require __DIR__.'/vendor/autoload.php';
// Create a Pushwoosh client
$pushwoosh = Pushwoosh::create()
->setApplication('XXXX-XXX')
->setAuth('xxxxxxxx');
// Create a request for the '/createMessage' Web Service
$request = CreateMessageRequest::create()
->addNotification(Notification::create()->setContent('Hello Jean !'));
// Call the REST Web Service
$response = $pushwoosh->createMessage($request);
// Check if its ok
if($response->isOk()) {
print 'Great, my message has been sent !';
} else {
print 'Oups, the sent failed :-(';
print 'Status code : ' . $response->getStatusCode();
print 'Status message : ' . $response->getStatusMessage();
}
?>
But I'm getting following error for it :
Fatal error: Class 'Pushwoosh' not found in /var/www/gomoob-php-pushwoosh/sample_1.php on line 9
At the Link they have not mentioned that any file needs to be included into the code. They have only written sample code program. I've used that program as it is but getting error for it.
So can someone please help me in running this program?
The class you want resides in a namespace, so you need to instruct PHP to "import" it (and other classes) from there; add this to the beginning of your script:
use Gomoob\Pushwoosh\Client\Pushwoosh;
use Gomoob\Pushwoosh\Model\Request\CreateMessageRequest;
use Gomoob\Pushwoosh\Model\Notification\Notification;
require __DIR__.'/vendor/autoload.php';