2017 © Pedro Peláez
 

library php-type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization). PSR-2. Supports nested resources.

image

garyjones/php-type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization). PSR-2. Supports nested resources.

  • Saturday, January 26, 2013
  • by GaryJones
  • Repository
  • 0 Watchers
  • 0 Stars
  • 17 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

PHP Type Converter

A class that handles the detection and conversion of certain resource formats / content types into other formats., (*1)

The current formats are supported: XML, JSON, Array, Object, Serialized, (*2)

Requirements

Documentation

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

$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., (*4)

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., (*5)

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

You can convert an XML document into an array (must have SimpleXML)., (*6)

$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., (*7)

  • 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.

Status

Build Status, (*8)

Changelog

Originally forked from Type Converter v2.0.0 https://github.com/milesj/php-type_converter by Miles Johnson., (*9)

This fork adds support for conversion of nested combinations of arrays / objects and some unit tests., (*10)

The Versions

26/01 2013

dev-master

9999999-dev https://github.com/GaryJones/php-type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization). PSR-2. Supports nested resources.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

converter type

26/01 2013

dev-develop

dev-develop https://github.com/GaryJones/php-type-converter

Converts one resource to another (XML, JSON, Object, Array, Serialization). PSR-2. Supports nested resources.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

converter type