PHP code example of obsidiane / notifuse-symfony-bundle

1. Go to this page and download the library: Download obsidiane/notifuse-symfony-bundle 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/ */

    

obsidiane / notifuse-symfony-bundle example snippets


return [
    // ...
    Obsidiane\Notifuse\NotifuseBundle::class => ['all' => true],
];

use Obsidiane\Notifuse\ApiClient;

final class MyService
{
    public function __construct(private ApiClient $apiClient) {}

    public function ping(): array
    {
        // Performs GET https://…/api/workspace.status with auth headers
        return $this->apiClient->request('GET', '/api/workspace.status');
    }

    public function createSomething(array $payload): array
    {
        return $this->apiClient->request('POST', '/api/something', [
            'json' => $payload,
            // Optional per‑request overrides
            'headers' => [ 'X-Client-Name' => 'my-app' ],
            'timeout' => 8.0,
        ]);
    }
}

try {
    $data = $this->apiClient->request('GET', '/api/workspace.status');
} catch (\Obsidiane\Notifuse\Exception\NotifuseClientException $e) {
    // Log and render a user‑friendly message
}

// 1) Send transactional notification
$client->sendTransactional([
    'id' => 'welcome_email',
    'contact' => ['email' => '[email protected]'],
    'channels' => ['email'],
    'data' => ['user_name' => 'John'],
]);

// 2) Upsert a contact
$client->upsertContact([
    'email' => '[email protected]',
    'first_name' => 'John',
]);

// 3) Get a contact
$client->getContactByEmail('[email protected]');
$client->getContactByExternalId('user_123');

// 4) Import contacts in batch
$client->importContacts([
    ['email' => '[email protected]'],
    ['email' => '[email protected]'],
], ['newsletter']);

// 5) Delete a contact
$client->deleteContact('[email protected]');

// 6) Update list subscription status
$client->updateContactListStatus('[email protected]', 'newsletter', 'active');

// 7) Public subscription (no Authorization header)
$client->publicSubscribeToLists([
    'email' => '[email protected]',
], ['newsletter']);

$this->apiClient->request('GET', '/api/endpoint', [
    'headers' => ['Accept-Language' => 'fr'],
    'timeout' => 5.0,
]);