Format class

Help convert between various formats such as XML, JSON, CSV, etc.

 Methods

Do not use this directly, call forge()

__construct(mixed $data, string $from_type, mixed $param) 

Parameters

$data

mixed

general date to be converted

$from_type

string

data format the file was provided in

$param

mixed

additional parameter that can be passed on to a 'from' method

Exceptions

\FuelException

Loads Format config.

_init() 

Returns an instance of the Format object.

forge(mixed $data, string $from_type, mixed $param) : \Fuel\Core\Format

echo Format::forge(array('foo' => 'bar'))->to_xml();

Parameters

$data

mixed

general date to be converted

$from_type

string

data format the file was provided in

$param

mixed

additional parameter that can be passed on to a 'from' method

Returns

To array conversion

to_array(mixed $data) : array

Goes through the input and makes sure everything is either a scalar value or array

Parameters

$data

mixed

Returns

array

To CSV conversion

to_csv(mixed $data, mixed $delimiter, mixed $enclose_numbers, array $headings) : string

Parameters

$data

mixed

$delimiter

mixed

$enclose_numbers

mixed

$headings

array

Custom headings to use

Returns

string

To JSON conversion

to_json(mixed $data, bool $pretty) : string

Parameters

$data

mixed

$pretty

bool

whether to make the json pretty

Returns

string

To JSONP conversion

to_jsonp(mixed $data, bool $pretty, string $callback) : string

Parameters

$data

mixed

$pretty

bool

whether to make the json pretty

$callback

string

JSONP callback

Returns

stringformatted JSONP

Return as a string representing the PHP structure

to_php(mixed $data) : string

Parameters

$data

mixed

Returns

string

Serialize

to_serialized(mixed $data) : string

Parameters

$data

mixed

Returns

string

To XML conversion

to_xml(mixed $data, null $structure, null | string $basenode, null | bool $use_cdata, mixed $bool_representation) : string

Parameters

$data

mixed

$structure

null

$basenode

nullstring

$use_cdata

nullbool

whether to use CDATA in nodes

$bool_representation

mixed

if true, element values are true/false. if 1, 1/0.

Returns

string

Convert to YAML

to_yaml(mixed $data) : string

Parameters

$data

mixed

Returns

string

Import CSV data

_from_csv(string $string, bool $no_headings) : array

Parameters

$string

string

$no_headings

bool

Returns

array

Import XML data

_from_xml(string $string, bool $recursive) : array

Parameters

$string

string

$recursive

bool

Returns

array

Import YAML data

_from_yaml(string $string) : array

Parameters

$string

string

Returns

array

Makes json pretty the json output.

pretty_json(string $data) : string | false

Borrowed from http://www.php.net/manual/en/function.json-encode.php#80339

Parameters

$data

string

json encoded array

Returns

stringfalsepretty json output or false when the input was not valid

Import JSON data

_from_json(string $string) : mixed

Parameters

$string

string

Returns

mixed

Import Serialized data

_from_serialize(string $string) : mixed

Parameters

$string

string

Returns

mixed

 Properties

 

<p>input to convert</p>

$_data : array | mixed

 

<p>whether to ignore namespaces when parsing xml</p>

$ignore_namespaces : bool