PHP code example of memran / marwa-envelop
1. Go to this page and download the library: Download memran/marwa-envelop 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/ */
memran / marwa-envelop example snippets
use Marwa\Envelop\Codec;
use Marwa\Envelop\Envelop;
use Marwa\Envelop\EnvelopBuilder;
$message = EnvelopBuilder::start()
->type('chat.message')
->sender('user:123')
->receiver('user:456')
->header('x-room', 'support')
->body(['text' => 'Hello world'])
->ttl(60)
->sign('shared-secret')
->build();
$wire = Codec::encode($message, ['compression' => Codec::COMPRESSION_GZIP]);
$decoded = Codec::decode($wire, [
'compression' => Codec::COMPRESSION_GZIP,
'verifyWithSecret' => 'shared-secret',
'signatureRequired' => true,
]);
assert($decoded instanceof Envelop);
$decoded = Codec::decode($wire, [
'compression' => Codec::COMPRESSION_GZIP,
'maxWireBytes' => 512 * 1024,
'maxDecodedBytes' => 2 * 1024 * 1024,
]);
$message = EnvelopBuilder::start()
->type('chat.message')
->body('Hello')
->build();
$message = EnvelopBuilder::start()
->type('job.created')
->body(['id' => 42, 'priority' => 'high'])
->build();
$message = EnvelopBuilder::start()
->type('chat.file')
->attach('/absolute/path/to/invoice.pdf')
->build();
$message = EnvelopBuilder::start()
->type('file.link')
->link('https://example.com/report.pdf', [
'name' => 'Quarterly Report',
'size' => '2MB',
])
->build();
text
src/
Codec.php
Envelop.php
EnvelopBuilder.php
Util.php
tests/
.github/workflows/ci.yml