Documentation

JsonConverter
in package

FinalYes

Converts and store tabular data into a JSON string.

Tags
template

Table of Contents

Properties

$chunkSize  : int<1, max>
$depth  : int<1, max>
$flags  : int
$format  : JsonFormat
$formatter  : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(T, Array): mixed|null
$indentSize  : int<1, max>
$emptyIterable  : string
$end  : string
$indentation  : non-empty-string
$indentationLevels  : array<string|int, string>
$jsonEncodeChunk  : callable(array<int, T>): string
$separator  : string
$start  : string

Methods

__call()  : self|bool
__construct()  : mixed
addFlags()  : self
Adds a list of JSON flags.
chunkSize()  : self
Set the indentation size.
convert()  : Iterator<string|int, string>
Returns an Iterator that you can iterate to generate the actual JSON string representation.
create()  : self
DEPRECATION WARNING! This method will be removed in the next major point release.
depth()  : self
Set the depth of Json encoding.
download()  : int
Sends and makes the JSON structure downloadable via HTTP.
encode()  : string
Returns the JSON representation of a tabular data collection.
format()  : self
formatter()  : self
Set a callback to format each item before json encode.
indentSize()  : self
DEPRECATION WARNING! This method will be removed in the next major point release.
removeFlags()  : self
Removes a list of JSON flags.
save()  : int
Store the generated JSON in the destination filepath.
useFlags()  : bool
Tells whether the flag is being used by the current JsonConverter.
useForceObject()  : bool
useHexAmp()  : bool
useHexApos()  : bool
useHexQuot()  : bool
useHexTag()  : bool
useInvalidUtf8Ignore()  : bool
useInvalidUtf8Substitute()  : bool
useNumericCheck()  : bool
usePartialOutputOnError()  : bool
usePreserveZeroFraction()  : bool
usePrettyPrint()  : bool
useThrowOnError()  : bool
useUnescapedLineTerminators()  : bool
useUnescapedSlashes()  : bool
useUnescapedUnicode()  : bool
when()  : self
Apply the callback if the given "condition" is (or resolves to) true.
withForceObject()  : JsonConverter
withHexAmp()  : JsonConverter
withHexApos()  : JsonConverter
withHexQuot()  : JsonConverter
withHexTag()  : JsonConverter
withInvalidUtf8Ignore()  : JsonConverter
withInvalidUtf8Substitute()  : JsonConverter
withNumericCheck()  : JsonConverter
withoutForceObject()  : JsonConverter
withoutHexAmp()  : JsonConverter
withoutHexApos()  : JsonConverter
withoutHexQuot()  : JsonConverter
withoutHexTag()  : JsonConverter
withoutInvalidUtf8Ignore()  : JsonConverter
withoutInvalidUtf8Substitute()  : JsonConverter
withoutNumericCheck()  : JsonConverter
withoutPartialOutputOnError()  : JsonConverter
withoutPreserveZeroFraction()  : JsonConverter
withoutPrettyPrint()  : JsonConverter
withoutThrowOnError()  : JsonConverter
withoutUnescapedLineTerminators()  : JsonConverter
withoutUnescapedSlashes()  : JsonConverter
withoutUnescapedUnicode()  : JsonConverter
withPartialOutputOnError()  : JsonConverter
withPreserveZeroFraction()  : JsonConverter
withPrettyPrint()  : self
withThrowOnError()  : JsonConverter
withUnescapedLineTerminators()  : JsonConverter
withUnescapedSlashes()  : JsonConverter
withUnescapedUnicode()  : JsonConverter
getList()  : callable(): Generator
methodToFlag()  : int
Returns the PHP json flag associated to its method suffix to ease method lookup.
prettyPrint()  : string
Pretty Print the JSON string without using JSON_PRETTY_PRINT The method also allow using an arbitrary length for the indentation.
setFlags()  : self
Sets the encoding flags.

Properties

$formatter read-only

public Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(T, Array): mixed|null $formatter

$indentation read-only

private non-empty-string $indentation

$indentationLevels

private array<string|int, string> $indentationLevels = []

$jsonEncodeChunk read-only

private callable(array<int, T>): string $jsonEncodeChunk

Methods

__call()

public __call(string $name, array<string|int, mixed> $arguments) : self|bool
Parameters
$name : string
$arguments : array<string|int, mixed>
Tags
throws
BadMethodCallException
Return values
self|bool

__construct()

public __construct([int $flags = 0 ][, int<1, max> $depth = 512 ][, int<1, max> $indentSize = 4 ][, Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(T, Array): mixed|null $formatter = null ][, int<1, max> $chunkSize = 500 ][, JsonFormat $jsonFormat = JsonFormat::Standard ]) : mixed
Parameters
$flags : int = 0
$depth : int<1, max> = 512
$indentSize : int<1, max> = 4
$formatter : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(T, Array): mixed|null = null
$chunkSize : int<1, max> = 500
$jsonFormat : JsonFormat = JsonFormat::Standard
Tags
throws
InvalidArgumentException

addFlags()

Adds a list of JSON flags.

public addFlags(int ...$flags) : self
Parameters
$flags : int
Return values
self

chunkSize()

Set the indentation size.

public chunkSize(int<1, max> $chunkSize) : self
Parameters
$chunkSize : int<1, max>
Return values
self

convert()

Returns an Iterator that you can iterate to generate the actual JSON string representation.

public convert(TabularDataProvider|TabularData|iterable<string|int, T$records[, array<string|int, string> $header = [] ]) : Iterator<string|int, string>
Parameters
$records : TabularDataProvider|TabularData|iterable<string|int, T>
$header : array<string|int, string> = []
Tags
throws
JsonException
throws
Exception
Return values
Iterator<string|int, string>

create()

DEPRECATION WARNING! This method will be removed in the next major point release.

public static create() : self

Since version 9.22.0

use League\Csv\JsonConverter::__construct() instead

Tags
see
JsonConverter::__construct()
codeCoverageIgnore
Return values
self

depth()

Set the depth of Json encoding.

public depth(int<1, max> $depth) : self
Parameters
$depth : int<1, max>
Return values
self

download()

Sends and makes the JSON structure downloadable via HTTP.

public download(TabularDataProvider|TabularData|iterable<string|int, T$records[, string|null $filename = null ][, array<string|int, string> $header = [] ]) : int

. Returns the number of characters read from the handle and passed through to the output.

Parameters
$records : TabularDataProvider|TabularData|iterable<string|int, T>
$filename : string|null = null
$header : array<string|int, string> = []
Tags
throws
Exception
throws
JsonException
Return values
int

encode()

Returns the JSON representation of a tabular data collection.

public encode(TabularDataProvider|TabularData|iterable<string|int, T$records[, array<string|int, string> $header = [] ]) : string
Parameters
$records : TabularDataProvider|TabularData|iterable<string|int, T>
$header : array<string|int, string> = []
Tags
throws
Exception
throws
JsonException
Return values
string

formatter()

Set a callback to format each item before json encode.

public formatter(callable|null $formatter) : self
Parameters
$formatter : callable|null
Return values
self

indentSize()

DEPRECATION WARNING! This method will be removed in the next major point release.

public indentSize(int<1, max> $indentSize) : self

Since version 9.19.0

use League\Csv\JsonConverter::withPrettyPrint() instead

Parameters
$indentSize : int<1, max>
Tags
see
JsonConverter::withPrettyPrint()
codeCoverageIgnore

Set the indentation size.

Return values
self

removeFlags()

Removes a list of JSON flags.

public removeFlags(int ...$flags) : self
Parameters
$flags : int
Return values
self

save()

Store the generated JSON in the destination filepath.

public save(TabularDataProvider|TabularData|iterable<string|int, T$records, SplFileInfo|SplFileObject|Stream|resource|string $destination[, resource|null $context = null ][, array<string|int, string> $header = [] ]) : int

if a Path or a SplFileInfo object is given, the file will be emptying before adding the JSON content to it. For all the other types you are required to provide a file with the correct open mode.

Parameters
$records : TabularDataProvider|TabularData|iterable<string|int, T>
$destination : SplFileInfo|SplFileObject|Stream|resource|string
$context : resource|null = null
$header : array<string|int, string> = []
Tags
throws
JsonException
throws
RuntimeException
throws
TypeError
throws
UnavailableStream
Return values
int

useFlags()

Tells whether the flag is being used by the current JsonConverter.

public useFlags(int ...$flags) : bool
Parameters
$flags : int
Return values
bool

useForceObject()

public useForceObject() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useHexAmp()

public useHexAmp() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useHexApos()

public useHexApos() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useHexQuot()

public useHexQuot() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useHexTag()

public useHexTag() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useInvalidUtf8Ignore()

public useInvalidUtf8Ignore() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useInvalidUtf8Substitute()

public useInvalidUtf8Substitute() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useNumericCheck()

public useNumericCheck() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

usePartialOutputOnError()

public usePartialOutputOnError() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

usePreserveZeroFraction()

public usePreserveZeroFraction() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

usePrettyPrint()

public usePrettyPrint() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useThrowOnError()

public useThrowOnError() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useUnescapedLineTerminators()

public useUnescapedLineTerminators() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useUnescapedSlashes()

public useUnescapedSlashes() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

useUnescapedUnicode()

public useUnescapedUnicode() : bool

tells whether the JSON_HEX_TAG flag is used

Return values
bool

when()

Apply the callback if the given "condition" is (or resolves to) true.

public when(callable($this): bool|bool $condition, Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable($this): Array $onSuccess[, Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable($this): Array|null $onFail = null ]) : self
Parameters
$condition : callable($this): bool|bool
$onSuccess : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable($this): Array
$onFail : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable($this): Array|null = null
Return values
self

withPrettyPrint()

public withPrettyPrint([int<1, max>|null $indentSize = null ]) : self
Parameters
$indentSize : int<1, max>|null = null
Return values
self

getList()

private static getList(Iterator $data, array<string|int, string> $header, JsonFormat $format) : callable(): Generator
Parameters
$data : Iterator
$header : array<string|int, string>
$format : JsonFormat
Tags
throws
InvalidArgument
Return values
callable(): Generator

methodToFlag()

Returns the PHP json flag associated to its method suffix to ease method lookup.

private static methodToFlag(string $method, int $prefixSize) : int
Parameters
$method : string
$prefixSize : int
Return values
int

prettyPrint()

Pretty Print the JSON string without using JSON_PRETTY_PRINT The method also allow using an arbitrary length for the indentation.

private prettyPrint(string $json) : string
Parameters
$json : string
Return values
string

setFlags()

Sets the encoding flags.

private setFlags(int $flags) : self
Parameters
$flags : int
Return values
self

        
On this page

Search results