PHP code example of wearesho-team / wearesho-notifications-repository

1. Go to this page and download the library: Download wearesho-team/wearesho-notifications-repository library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?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\ConfigInterface $config
 * @var GuzzleHttp\ClientInterface $guzzleClient
 */

$repository = new Wearesho\Notifications\Repository($config, $guzzleClient);




/**
 * @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()
}




use Wearesho\Notifications;

/** @var Notifications\Repository $repoFirst */
/** @var Notifications\Repository $repoSecond */

$chain = new Notifications\Push\Chain([
    new Notifications\Push\Filter(
        $repoFirst,
        $types = [
            'primary',
        ]
    ),
    $repoSecond
]);

/** @var Notifications\Notification $notification */

$chain->push($notification);