1. Go to this page and download the library: Download golded-dev/laravel-ftn 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/ */
golded-dev / laravel-ftn example snippets
declare(strict_types=1);
use Golded\Ftn\Contracts\MessageBaseReader;
use Golded\Ftn\ParsedMessage;
use Golded\Ftn\ReaderOptions;
final class ExampleReader implements MessageBaseReader
{
/**
* @return iterable<ParsedMessage>
*/
public function read(string $path, ?ReaderOptions $options = null): iterable
{
$options ??= new ReaderOptions();
yield new ParsedMessage(
msgno: 1,
fromName: 'Sysop',
toName: 'All',
subject: 'Hello',
bodyText: 'Message body',
attributesRaw: 0,
externalId: 'example:1',
areaCode: 'GENERAL',
areaName: 'General',
);
}
}
declare(strict_types=1);
use Golded\Ftn\Contracts\MessageSourceCatalog;
use Golded\Ftn\MessageSource;
use Golded\Ftn\ReaderOptions;
final class ExampleCatalog implements MessageSourceCatalog
{
/**
* @return iterable<MessageSource>
*/
public function sources(string $path, ?ReaderOptions $options = null): iterable
{
yield new MessageSource(
sourceType: 'example',
path: $path.'/general',
code: 'GENERAL',
name: 'General',
sortOrder: 10,
metaKey: 'example:general',
);
}
}
use Golded\Ftn\ReaderOptions;
$options = new ReaderOptions(
fallbackCharset: 'CP850',
);
declare(strict_types=1);
use Golded\Ftn\Contracts\MessageWriter;
use Golded\Ftn\OutgoingMessage;
use Golded\Ftn\WriterOptions;
final class ExampleWriter implements MessageWriter
{
/**
* @param iterable<OutgoingMessage> $messages
*/
public function write(string $path, iterable $messages, ?WriterOptions $options = null): int
{
$written = 0;
foreach ($messages as $message) {
$written++;
}
return $written;
}
}
use Golded\Ftn\Support\CharsetDetector;
$charset = CharsetDetector::detect("\x01CHRS: LATIN-1 2\nBody");
// ISO-8859-1