<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wearesho-team / wearesho-notifications-repository example snippets
/**
* @var string $requestsUrl URL to your notification server.
* @var string|null $serviceKey Access key to notification server. Optional (depends on server
$config = new Wearesho\Notifications\EnvironmentConfig($dotenvPrefix = 'WEARESHO_NOTIFICATIONS_');
/**
* @var Wearesho\Notifications\Repository $repository
* @var int $userId
*/
try {
$authorizationToken = $repository->authorize($userId);
} catch (Wearesho\Notifications\Exceptions\Credentials\Missed $exception) {
// Your server se instance using $exception->getResponse()
}
/**
* @var int $userId Notification's owner
* @var string $message Notification's content
* @var array|null $context Special params for message.
* F.e. if message is like 'Hello, {person}', you can pass params like [ 'person' => 'Jonh', ]
* This params can be applied in front-end
*
* @var string|null $type Notification type.
* Can be any string. but we recommend to use Wearesho\Notifications\Notification\Type constants
* to avoid unexpected situations.
*
* @var \DateTime|null $time Notification's creation date
* @var bool|null $isRead Mark if the notification is read.
*/
$notification = new Wearesho\Notifications\Notification(
$userId,
$message,
$context,
$type,
$time,
$isRead
);
/**
* @var Wearesho\Notifications\Notification $notification
* @var Wearesho\Notifications\Repository $repository
*/
try {
$repository->push($notification);
} catch (Wearesho\Notifications\Exceptions\Credentials\Missed $exception) {
// Your server ing $exception->getNotification()
}