PHP code example of rrp / t3-toon
1. Go to this page and download the library: Download rrp/t3-toon 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/ */
rrp / t3-toon example snippets
use RRP\T3Toon\Service\Toon;
$data = ['user' => 'ABC', 'tasks' => [['id' => 1, 'done' => false], ['id' => 2, 'done' => true]]];
echo Toon::encodeStatic($data);
// or: Toon::convertStatic($data);
$decoded = Toon::decodeStatic($toonString);
$estimate = Toon::estimateTokensStatic($toonString);
use RRP\T3Toon\Service\Toon;
use TYPO3\CMS\Core\Utility\GeneralUtility;
$toon = GeneralUtility::makeInstance(Toon::class);
echo $toon->convert($data);
$decoded = $toon->decode($toonString);
use RRP\T3Toon\Domain\Model\EncodeOptions;
use RRP\T3Toon\Domain\Model\DecodeOptions;
use RRP\T3Toon\Service\Toon;
// Encoding: indent, delimiter (comma/tab/pipe), key folding
$compact = Toon::encodeStatic($data, EncodeOptions::compact()); // indent 2, comma
$readable = Toon::encodeStatic($data, EncodeOptions::readable()); // indent 4
$tabular = Toon::encodeStatic($data, EncodeOptions::tabular()); // tab delimiter
$folded = Toon::encodeStatic($data, EncodeOptions::folded()); // safe key folding
$custom = Toon::encodeStatic($data, new EncodeOptions(indent: 2, delimiter: "|", keyFolding: "safe"));
// Decoding: strict (default) vs lenient; optional dotted-key path expansion
$data = Toon::decodeStatic($toon);
$lenient = Toon::decodeStatic($toon, DecodeOptions::lenient()); // relax strict-mode checks
$expanded = Toon::decodeStatic($toon, DecodeOptions::expanded()); // expand a.b.c into nested objects
toon($value); // encode (alias for Toon::encodeStatic)
toon_decode($toon); // decode
toon_compact($value); // encode with EncodeOptions::compact()
toon_readable($value); // encode with EncodeOptions::readable()
toon_decode_lenient($toon); // decode in non-strict mode (relaxed validation)
toon_estimate_tokens($toon); // return ['words' => …, 'chars' => …, 'tokens_estimate' => …]
use RRP\T3Toon\Exception\ToonDecodeException;
use RRP\T3Toon\Service\Toon;
try {
$data = Toon::decodeStatic($input);
} catch (ToonDecodeException $e) {
// $e->getLineNumber(), $e->getSnippet()
}