PHP Class VersionPress\Storages\Serialization\SerializedDataToIniConverter

Serialized data are prefixed with the $serializedMarker.
Show file Open project: versionpress/versionpress Class Usage Examples

Public Methods

Method Description
convertParsingResultToIni ( $key, $parsingResult )
createFirstLine ( string $key, string | null $type = null, string | null $value = null ) : string[] Returns array with first line of INI.
fromIniLines ( string $key, string[] $lines ) : string Restores the PHP-serialized value from INI.
toIniLines ( string $key, string $serializedData ) : string[] Converts PHP-serialized string to mutiple INI lines.

Private Methods

Method Description
convertArrayToSerializedString ( $relatedLines ) : string Converts array items saved in INI to PHP-like serialized string.
convertObjectToSerializedString ( $type, $relatedKeys ) : string Converts object saved in INI to PHP-like serialized string.
convertValueToSerializedString ( mixed $value, array $relatedLines = [] ) : string Converts single value (string, number, array, object, .
findRelatedKeys ( $maybeRelatedKeys, $commonKey ) : array Finds array items with prefix $commonKey and cuts the prefix off.
getSubItems ( $relatedLines, callable | null $subkeyTransformFn = null ) : array Takes lines of INI representing array items or class fields and returns them as PHP-like serialized string.
parseSerializedString ( ) : array Transforms PHP primitives, arrays, objects etc. to INI. Complex structures like arrays and objects can take multiple lines (every scalar value is on new line).
primitiveToEscapedString ( $value )

Method Details

convertParsingResultToIni() public static method

public static convertParsingResultToIni ( $key, $parsingResult )

createFirstLine() public static method

Returns array with first line of INI.
public static createFirstLine ( string $key, string | null $type = null, string | null $value = null ) : string[]
$key string
$type string | null
$value string | null
return string[]

fromIniLines() public static method

For examples see the tests.
public static fromIniLines ( string $key, string[] $lines ) : string
$key string The original top-level key.
$lines string[] Lines related to the $key. Hierarchical structures are saved as multiple lines.
return string Original result of PHP serialization.

toIniLines() public static method

For example string 'a:1:{i:0;s:3:"foo";}' with key 'data' is converted to [ 'data = <<>> ', 'data[0] = "foo"' ] See IniSerializerTest for more examples.
public static toIniLines ( string $key, string $serializedData ) : string[]
$key string
$serializedData string
return string[]