承接 garyjones/php-type-converter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

garyjones/php-type-converter

Composer 安装命令:

composer require garyjones/php-type-converter

包简介

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

README 文档

README

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

Requirements

Documentation

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

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

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.

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

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

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

  • 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

Changelog

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

This fork adds support for conversion of nested combinations of arrays / objects and some unit tests.

统计信息

  • 总下载量: 24
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-26