Closed mfarhat437 closed 4 years ago
In your application :)
Are you familiar with composer? Do you use any frameworks?
Yes i use laravel On Feb 28, 2019 6:58 AM, "Tomas Norkūnas" notifications@github.com wrote:
Are you familiar with composer? Do you use any frameworks?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/norkunas/onesignal-php-api/issues/114#issuecomment-468137708, or mute the thread https://github.com/notifications/unsubscribe-auth/Apr80ynhmSrFygYKRBRf1WJVVmk04ns3ks5vR2HagaJpZM4bVLiz .
So bind the OneSignal service to your container:
use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
use Http\Client\Common\HttpMethodsClient as HttpClient;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use OneSignal\Config;
use OneSignal\OneSignal;
$this->app->bind('OneSignal\OneSignal', function ($app) {
$config = new Config();
$config->setApplicationId('your_application_id');
$config->setApplicationAuthKey('your_application_auth_key');
$config->setUserAuthKey('your_auth_key');
$client = new HttpClient(new GuzzleAdapter(new GuzzleClient()), new GuzzleMessageFactory());
return new OneSignal\OneSignal($config, $client);
});
And then inject OneSignal to your controller. For more docs read https://laravel.com/docs/5.8/container
require DIR . '/vendor/autoload.php';
use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; use Http\Client\Common\HttpMethodsClient as HttpClient; use Http\Message\MessageFactory\GuzzleMessageFactory; use OneSignal\Config; use OneSignal\OneSignal;
$config = new Config(); $config->setApplicationId('your_application_id'); $config->setApplicationAuthKey('your_application_auth_key'); $config->setUserAuthKey('your_auth_key');
$guzzle = new GuzzleClient([ // http://docs.guzzlephp.org/en/stable/quickstart.html // ..config ]);
$client = new HttpClient(new GuzzleAdapter($guzzle), new GuzzleMessageFactory()); $api = new OneSignal($config, $client);