PHP code example of decent-newsroom / nostr-client-bundle

1. Go to this page and download the library: Download decent-newsroom/nostr-client-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/ */

    

decent-newsroom / nostr-client-bundle example snippets


// config/bundles.php
return [
    DecentNewsroom\NostrClientBundle\NostrClientBundle::class => ['all' => true],
];

use Innis\Nostr\Client\Application\Port\NostrClientInterface;
use Innis\Nostr\Core\Domain\ValueObject\Protocol\RelayUrl;

final class ExampleService
{
    public function __construct(private readonly NostrClientInterface $client) {}

    public function fetchRecent(string $relayUrl): void
    {
        $relay = RelayUrl::fromString($relayUrl);
        $this->client->connect($relay);
        // ...subscribe/publish as needed; see innis/nostr-client for its API.
        $this->client->close();
    }
}

$client->connect(
    RelayUrl::fromString('wss://relay.example.com'),
    new ConnectionConfig(connectionTimeoutSeconds: 5),
);
yaml
# config/packages/nostr_client.yaml
nostr_client:
    connection_timeout_seconds: 10
    auto_reconnect: true
    reconnect_initial_delay_ms: 500
    reconnect_max_delay_ms: 60000
    reconnect_max_attempts: 0
    user_agent: null