PHP Класс Format

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_data mixed Data to parse
$_from_type string Type to convert from

Открытые методы

Метод Описание
__construct ( null $data = NULL, null $from_type = NULL ) DO NOT CALL THIS DIRECTLY, USE factory()
factory ( mixed $data, string $from_type = NULL ) : object Create an instance of the format class e.g: echo $this->format->factory(['foo' => 'bar'])->to_csv();
to_array ( mixed | null $data = NULL ) : array Format data as an array
to_csv ( mixed | null $data = NULL, string $delimiter = ',', string $enclosure = '"' ) : string
to_html ( mixed | null $data = NULL ) : mixed Format data as HTML
to_json ( mixed | null $data = NULL ) : string Encode data as json
to_php ( mixed | null $data = NULL ) : mixed Format data using a PHP structure
to_serialized ( mixed | null $data = NULL ) : string Encode data as a serialized array
to_xml ( mixed | null $data = NULL, null $structure = NULL, string $basenode = 'xml' ) : mixed Format data as XML

Защищенные методы

Метод Описание
_from_csv ( string $data, string $delimiter = ',', string $enclosure = '"' ) : array
_from_json ( string $data ) : mixed
_from_php ( string $data ) : string
_from_serialize ( string $data ) : mixed
_from_xml ( string $data ) : array

Описание методов

__construct() публичный Метод

DO NOT CALL THIS DIRECTLY, USE factory()
public __construct ( null $data = NULL, null $from_type = NULL )
$data null
$from_type null

_from_csv() защищенный Метод

protected _from_csv ( string $data, string $delimiter = ',', string $enclosure = '"' ) : array
$data string CSV string
$delimiter string The optional delimiter parameter sets the field delimiter (one character only). NULL will use the default value (,)
$enclosure string The optional enclosure parameter sets the field enclosure (one character only). NULL will use the default value (")
Результат array A multi-dimensional array with the outer array being the number of rows and the inner arrays the individual fields

_from_json() защищенный Метод

protected _from_json ( string $data ) : mixed
$data string Encoded json string
Результат mixed Decoded json string with leading and trailing whitespace removed

_from_php() защищенный Метод

protected _from_php ( string $data ) : string
$data string Data to trim leading and trailing whitespace
Результат string Data with leading and trailing whitespace removed

_from_serialize() защищенный Метод

protected _from_serialize ( string $data ) : mixed
$data string Data to unserialize
Результат mixed Unserialized data

_from_xml() защищенный Метод

protected _from_xml ( string $data ) : array
$data string XML string
Результат array XML element object; otherwise, empty array

factory() публичный Метод

Create an instance of the format class e.g: echo $this->format->factory(['foo' => 'bar'])->to_csv();
public factory ( mixed $data, string $from_type = NULL ) : object
$data mixed Data to convert/parse
$from_type string Type to convert from e.g. json, csv, html
Результат object Instance of the format class

to_array() публичный Метод

Format data as an array
public to_array ( mixed | null $data = NULL ) : array
$data mixed | null Optional data to pass, so as to override the data passed to the constructor
Результат array Data parsed as an array; otherwise, an empty array

to_csv() публичный Метод

public to_csv ( mixed | null $data = NULL, string $delimiter = ',', string $enclosure = '"' ) : string
$data mixed | null Optional data to pass, so as to override the data passed to the constructor
$delimiter string The optional delimiter parameter sets the field delimiter (one character only). NULL will use the default value (,)
$enclosure string The optional enclosure parameter sets the field enclosure (one character only). NULL will use the default value (")
Результат string A csv string

to_html() публичный Метод

Format data as HTML
public to_html ( mixed | null $data = NULL ) : mixed
$data mixed | null Optional data to pass, so as to override the data passed to the constructor
Результат mixed

to_json() публичный Метод

Encode data as json
public to_json ( mixed | null $data = NULL ) : string
$data mixed | null Optional data to pass, so as to override the data passed to the constructor
Результат string Json representation of a value

to_php() публичный Метод

Format data using a PHP structure
public to_php ( mixed | null $data = NULL ) : mixed
$data mixed | null Optional data to pass, so as to override the data passed to the constructor
Результат mixed String representation of a variable

to_serialized() публичный Метод

Encode data as a serialized array
public to_serialized ( mixed | null $data = NULL ) : string
$data mixed | null Optional data to pass, so as to override the data passed to the constructor
Результат string Serialized data

to_xml() публичный Метод

Format data as XML
public to_xml ( mixed | null $data = NULL, null $structure = NULL, string $basenode = 'xml' ) : mixed
$data mixed | null Optional data to pass, so as to override the data passed to the constructor
$structure null
$basenode string
Результат mixed

Описание свойств

$_data защищенное свойство

Data to parse
protected mixed $_data
Результат mixed

$_from_type защищенное свойство

Type to convert from
protected string $_from_type
Результат string