PHPackages                             juanchosl/datatransfer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. juanchosl/datatransfer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

juanchosl/datatransfer
======================

A small, lightweight utility to read values and properties from distinct sources using the same methodology

1.0.14(3mo ago)1333↓100%2MITPHPPHP ^8.1

Since Jun 16Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/JuanchoSL/DataTransfer)[ Packagist](https://packagist.org/packages/juanchosl/datatransfer)[ Docs](https://github.com/JuanchoSL/DataTransfer)[ RSS](/packages/juanchosl-datatransfer/feed)WikiDiscussions 1.0 Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (18)Used By (2)

DataTransfer
============

[](#datatransfer)

Description
-----------

[](#description)

A small, lightweight utility to read values and properties from distinct sources using the same methodology and convert it to a standard DTO. Include a second tool that can convert any of DTOs to any of the know formats, creating a simple format converter from format A to format B.

Install
-------

[](#install)

```
composer require juanchosl/datatransfer
composer update
```

How use it
----------

[](#how-use-it)

Load composer autoload and use it

Data Transfer Objects
---------------------

[](#data-transfer-objects)

### Using the provided Factory

[](#using-the-provided-factory)

The **$element** parameter can be:

- array indexed or associtive
- object that implements JsonSerializable interface
- string with serialized object or array
- filepath containing a serialized object or array
- json encoded object or array
- json filepath with *json* extension containing a json encoded object or array
- SimpleXMLElement object
- Excel filepath with xlsx extension
- ODS string or filepath with ods extension
- XML string or filepath with xml extension
- CSV string or filepath with csv extension
- INI string or filepath with ini extension
- TAB separated values string or filepath with tsv extension
- YAML string or filepath with yml or yaml extension (require **yaml** php extension)
- primitive value

#### Using a filepath

[](#using-a-filepath)

Open and convert the contents included into file, alternatively you can specify the Format if the extension is not knowed

```
$dto = JuanchoSL\DataTransfer\Factories\DataTransferFactory::byFile($element, Format $original_format = null);
```

#### Using a string

[](#using-a-string)

Try to detect and convert the contents included into string (json encoded, serialized object or array, xml, csv, yaml), alternatively you can specify the Format if the type is INI

```
$dto = JuanchoSL\DataTransfer\Factories\DataTransferFactory::byString($element, Format $original_format = null);
```

#### Using a mime-type

[](#using-a-mime-type)

You can try passing an iterable number of strings as standard mimetypes ir order to process with the first compatible

```
$dto = JuanchoSL\DataTransfer\Factories\DataTransferFactory::byMimeType($element, string|iterable $mime_types);
```

#### Using a trasversable element

[](#using-a-trasversable-element)

Detect and convert the trasversable element (object or array)

```
$dto = JuanchoSL\DataTransfer\Factories\DataTransferFactory::byTrasversable($element);
```

### Using a specific repository

[](#using-a-specific-repository)

Alternative you can use the distincts repositories

```
$dto = new JuanchoSL\DataTransfer\Repositories\{SOURCE_READER}($element)
```

#### Available origins and repositories

[](#available-origins-and-repositories)

TypeCompatibilityReaderArrayfilepath | array | string from array serializedArrayDataTransferstdClassfilepath | object | string from object serializedObjectDataTransferCSVfilepath | array of lines | stringCsvDataTransfer(,) or ExcelCsvDataTransfer(;)INIfilepath | stringIniDataTransferTABfilepath | stringTabsvDataTransferJSONfilepath | stringJsonDataTransferXMLfilepath | string | SimpleXmlElementXmlDataTransferYAMLfilepath | stringYamlDataTransferXLSXfilepath | stringExcelXlsxDataTransferODSfilepath | stringOdsDataTransfer> The **$element** parameter needs to be the required type for the selected repo

> Is more efective use a magic factory in order to avoid know the type of the original data, and you can change it with no need to adapt your existing code.

> The resultant **$dto** variable is a recursive data transfer object, iterable, countable, clonable and json serializable

### Use data

[](#use-data)

```
$dto = DataTransferFactory::create(['key' => 'value']);
echo $dto->has('key'); //true
echo $dto->get('key'); //value
echo $dto['key']; //value
echo $dto->key; //value
echo $dto->has('other_key'); //false
$dto->other_key = 'other_value';// alias for $dto->set('other_key','other_value')
echo $dto->has('other_key'); //true
echo $dto->other_key; //other_value
```

Data Converters
---------------

[](#data-converters)

You can convert any DataTransferObject to a standar format, as:

- array
- stdClass
- SimpleXMLElement
- json
- xml
- ini
- yaml
- csv
- tsv (tab separated)
- excel csv
- xlsx

### Using the provided Factory

[](#using-the-provided-factory-1)

```
$json = JuanchoSL\DataTransfer\Factories\DataConverterFactory::asJson($dto);
```

### Using a mime-type

[](#using-a-mime-type-1)

You can try passing an iterable number of strings as standard mimetypes ir order to convert with the first compatible

```
$json = JuanchoSL\DataTransfer\Factories\DataConverterFactory::asMimeType($dto, 'application/json');
```

### Using a specific converter

[](#using-a-specific-converter)

Alternative you can use the distincts converters

```
$converter = new JuanchoSL\DataTransfer\Converters\{SOURCE_CONVERTER}($dto);
$result = $converter->getData();
```

```
$converter = new JuanchoSL\DataTransfer\Converters\{SOURCE_CONVERTER}();
$converter->setData($dto);
$result = $converter->getData();
```

The available converters are:

- CsvConverter (,)
- ExcelCsvConverter(;)
- ExcelXlsxConverter
- JsonConverter
- XmlConverter
- YamlConverter
- IniConverter
- TabsvConverter
- ArrayConverter
- ObjectConverter
- XmlObjectConverter

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance78

Regular maintenance activity

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~53 days

Total

16

Last Release

116d ago

PHP version history (2 changes)1.0.0PHP ^7.1 || ^8.0

1.0.7PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd6d3dea7eb469817524c42a80683e95793ed4800a6794366503355af046a726?d=identicon)[Juanchosl](/maintainers/Juanchosl)

---

Top Contributors

[![JuanchoSL](https://avatars.githubusercontent.com/u/18701207?v=4)](https://github.com/JuanchoSL "JuanchoSL (128 commits)")

---

Tags

jsonxmlarrayyamlxlsxcsvobjectodsentitytsvvaluesdtoinidata transfer objectstab-separated valuessimplexmlelementdata-converterdata-sheetsfile contents

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juanchosl-datatransfer/health.svg)

```
[![Health](https://phpackages.com/badges/juanchosl-datatransfer/health.svg)](https://phpackages.com/packages/juanchosl-datatransfer)
```

###  Alternatives

[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[jbzoo/data

An extended version of the ArrayObject object for working with system settings or just for working with data arrays

891.6M23](/packages/jbzoo-data)[jasny/dotkey

Dot notation access for objects and arrays

14219.5k6](/packages/jasny-dotkey)[hiraku/xml_builder

Simple DSL for building XML

141.6k1](/packages/hiraku-xml-builder)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
