2017 © Pedro Peláez
 

library type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization).

image

mjohnson/type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization).

  • Thursday, March 12, 2015
  • by milesj
  • Repository
  • 0 Watchers
  • 0 Stars
  • 29,346 Installations
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 6 % Grown

The README.md

Type Converter v2.0.0

A class that handles the detection and conversion of certain resource formats / content types into other formats. The current formats are supported: XML, JSON, Array, Object, Serialized, (*1)

Requirements

  • PHP 5.3+ - v2.x
  • PHP 5.2+ - v1.x
  • SimpleXML - http://php.net/manual/book.simplexml.php

Documentation

The class is pretty straight forward. If you want to convert something to another format, use the "to" methods., (*2)

$object = TypeConverter::toObject($resource);
$array = TypeConverter::toArray($resource);
$json = TypeConverter::toJson($resource);
$xml = TypeConverter::toXml($resource);
$ser = TypeConverter::toSerialize($resource);

If you want to detect what resource type it is, use the "is" methods. If you use the "to" methods above, it does automatic "is" detection., (*3)

TypeConverter::isObject($resource);
TypeConverter::isArray($resource);
TypeConverter::isJson($resource);
TypeConverter::isXml($resource);
TypeConverter::isSerialized($resource);

If you want a string representation of what a resource is, use the default is() method., (*4)

$resource = array();
TypeConverter::is($resource); // array

Finally, you can convert an XML document into an array (must have SimpleXML)., (*5)

$array = TypeConverter::xmlToArray($xml, TypeConverter::XML_MERGE);

When using xmlToArray(), you can define the format in which the node attributes and values are presented. The following constants are available., (*6)

XML_NONE  - Disregard XML attributes and only return the value.
XML_MERGE - Merge attributes and the value into a single dimension; the values key will be "value".
XML_GROUP - Group the attributes into a key of "attributes" and the value into a key of "value".
XML_OVERWRITE - Attributes will only be returned.

Be sure to set the content type when supporting UTF-8., (*7)

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

The Versions

12/03 2015

dev-master

9999999-dev http://milesj.me/code/php/type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization).

  Sources   Download

MIT

The Requires

  • php >=5.2

 

converter type

21/11 2012

2.0.0

2.0.0.0 http://milesj.me/code/php/type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization).

  Sources   Download

MIT

The Requires

  • php >=5.2

 

converter type

25/10 2012

1.4.1

1.4.1.0 http://milesj.me/code/php/type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization).

  Sources   Download

MIT

The Requires

  • php >=5.2

 

converter type

09/07 2012

1.4

1.4.0.0 http://milesj.me/code/php/type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization).

  Sources   Download

MIT

The Requires

  • php >=5.2

 

converter type