PHP Class Format

Afficher le fichier Open project: chriskacerguis/codeigniter-restserver Class Usage Examples

Protected Properties

Свойство Type Description
$_data mixed Data to parse
$_from_type string Type to convert from

Méthodes publiques

Méthode Description
__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

Méthodes protégées

Méthode Description
_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

Method Details

__construct() public méthode

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

_from_csv() protected méthode

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 (")
Résultat array A multi-dimensional array with the outer array being the number of rows and the inner arrays the individual fields

_from_json() protected méthode

protected _from_json ( string $data ) : mixed
$data string Encoded json string
Résultat mixed Decoded json string with leading and trailing whitespace removed

_from_php() protected méthode

protected _from_php ( string $data ) : string
$data string Data to trim leading and trailing whitespace
Résultat string Data with leading and trailing whitespace removed

_from_serialize() protected méthode

protected _from_serialize ( string $data ) : mixed
$data string Data to unserialize
Résultat mixed Unserialized data

_from_xml() protected méthode

protected _from_xml ( string $data ) : array
$data string XML string
Résultat array XML element object; otherwise, empty array

factory() public méthode

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
Résultat object Instance of the format class

to_array() public méthode

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
Résultat array Data parsed as an array; otherwise, an empty array

to_csv() public méthode

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 (")
Résultat string A csv string

to_html() public méthode

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
Résultat mixed

to_json() public méthode

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
Résultat string Json representation of a value

to_php() public méthode

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
Résultat mixed String representation of a variable

to_serialized() public méthode

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
Résultat string Serialized data

to_xml() public méthode

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
Résultat mixed

Property Details

$_data protected_oe property

Data to parse
protected mixed $_data
Résultat mixed

$_from_type protected_oe property

Type to convert from
protected string $_from_type
Résultat string