49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
|
<?php
|
||
|
// BencodeSerialiserSettings.php
|
||
|
// Created: 2022-01-13
|
||
|
// Updated: 2022-02-02
|
||
|
|
||
|
namespace Index\Serialisation;
|
||
|
|
||
|
/**
|
||
|
* Provides settings for Bencode serialisation.
|
||
|
*/
|
||
|
class BencodeSerialiserSettings {
|
||
|
public const DEFAULT_DEPTH = 512;
|
||
|
|
||
|
private int $maxDepth;
|
||
|
private bool $dictAsObject;
|
||
|
|
||
|
/**
|
||
|
* Creates a new BencodeSerialiserSettings instance.
|
||
|
*
|
||
|
* @param int $maxDepth Maximum parsing depth before the serialisation/deserialisation should stop.
|
||
|
* @param bool $dictAsObject Whether Dictionaries should be decoded as stdClass instances rather than associative arrays.
|
||
|
*/
|
||
|
public function __construct(
|
||
|
int $maxDepth = self::DEFAULT_DEPTH,
|
||
|
bool $dictAsObject = false
|
||
|
) {
|
||
|
$this->maxDepth = $maxDepth;
|
||
|
$this->dictAsObject = $dictAsObject;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets the maximum recursion depth.
|
||
|
*
|
||
|
* @return int Maximum recursion depth.
|
||
|
*/
|
||
|
public function getMaxDepth(): int {
|
||
|
return $this->maxDepth;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets whether dictionaries should be decoded as objects (instances of stdClass).
|
||
|
*
|
||
|
* @return bool True if dictionaries should be objects, false if they should be associative arrays.
|
||
|
*/
|
||
|
public function shouldDecodeDictAsObject(): bool {
|
||
|
return $this->dictAsObject;
|
||
|
}
|
||
|
}
|