Skip to content

Commit

Permalink
Source code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
JackieDo committed Mar 17, 2022
1 parent e1396f1 commit fac2f6e
Show file tree
Hide file tree
Showing 10 changed files with 345 additions and 316 deletions.
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.{md,htm,html,blade.php}]
insert_final_newline = false
trim_trailing_whitespace = false

[*.{min.css,min.js}]
insert_final_newline = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Auto detect text files and perform LF normalization
* text=auto

/.github export-ignore
/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php-cs-fixer.dist.php export-ignore
.travis.yml export-ignore
phpunit.xml export-ignore
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/vendor
composer.phar
composer.lock
.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
.DS_Store
composer.phar
composer.lock
49 changes: 28 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[![Build Status](https://api.travis-ci.org/JackieDo/Xml-Array.svg?branch=master)](https://travis-ci.org/JackieDo/Xml-Array)
[![Total Downloads](https://poser.pugx.org/jackiedo/xml-array/downloads)](https://packagist.org/packages/jackiedo/xml-array)
[![Latest Stable Version](https://poser.pugx.org/jackiedo/xml-array/v/stable)](https://packagist.org/packages/jackiedo/xml-array)
[![Latest Unstable Version](https://poser.pugx.org/jackiedo/xml-array/v/unstable)](https://packagist.org/packages/jackiedo/xml-array)
[![License](https://poser.pugx.org/jackiedo/xml-array/license)](https://packagist.org/packages/jackiedo/xml-array)

The conversion between xml and array becomes easier than ever. This package provides some very simple classes to convert XML to array and back.
Expand All @@ -15,38 +14,46 @@ The conversion between xml and array becomes easier than ever. This package prov
# Overview
Look at one of the following sessions to learn more about this package.

* [Installation](#installation)
* [Basic usage](#basic-usage)
- [Xml-Array](#xml-array)
- [Features of this package](#features-of-this-package)
- [Overview](#overview)
- [Installation](#installation)
- [Basic usage](#basic-usage)
- [Convert XML to array](#convert-xml-to-array)
- [Convert XML to Json](#convert-xml-to-json)
- [Convert array to XML](#convert-array-to-xml)
- [Convert array to DOM](#convert-array-to-dom)
* [Advanced usage](#advanced-usage)
- [Advanced usage](#advanced-usage)
- [Set configuration](#set-configuration)
- [Method 1](#method-1)
- [Method 2](#method-2)
- [Method 3](#method-3)
- [Get configuration](#get-configuration)
- [Default configuration](#default-configuration)
* [License](#license)
- [For Xml2Array](#for-xml2array)
- [For Array2Xml](#for-array2xml)
- [License](#license)

## Installation
You can install this package through [Composer](https://getcomposer.org).

```shell
composer require jackiedo/xml-array
$ composer require jackiedo/xml-array
```

## Basic usage

### Convert XML to array

###### Syntax:
**Syntax**:

```
array Xml2Array::convert(DOMDocument|SimpleXMLElement|string $inputXML)->toArray();
```

> **Note:** The input XML can be one of types DOMDocument object, SimpleXMLElement object or well-formed XML string.
###### Example 1 (Convert from XML string):
**Example 1** - _(Convert from XML string)_:

```php
use Jackiedo\XmlArray\Xml2Array;
Expand Down Expand Up @@ -135,7 +142,7 @@ $array = [
]
```

###### Example 2 (Convert form XML object, such as SimpleXMLElement):
**Example 2** - _(Convert form XML object, such as SimpleXMLElement)_:

```php
use Jackiedo\XmlArray\Xml2Array;
Expand Down Expand Up @@ -331,27 +338,27 @@ $array = [

### Convert XML to Json

###### Syntax:
**Syntax**:

```
string Xml2Array::convert(DOMDocument|SimpleXMLElement|string $inputXML)->toJson([int $options = 0]);
```

###### Example 3:
**Example 3**:

```php
$jsonString = Xml2Array::convert($xmlString)->toJson(JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
```

### Convert array to XML

###### Syntax:
**Syntax**:

```
string Array2Xml::convert(array $array)->toXml([bool $prettyOutput = false]);
```

###### Example 4:
**Example 4**:

```php
use Jackiedo\XmlArray\Array2Xml;
Expand All @@ -363,13 +370,13 @@ $xmlString = Array2Xml::convert($array)->toXml(true);

### Convert array to DOM

###### Syntax:
**Syntax**:

```
DOMDocument Array2Xml::convert(array $array)->toDom();
```

###### Example 5:
**Example 5**:

```php
$domObject = Array2Xml::convert($array)->toDom();
Expand All @@ -380,7 +387,7 @@ $domObject = Array2Xml::convert($array)->toDom();
### Set configuration
You can set configuration for conversion process with one of following methods:

###### Method 1:
#### Method 1

```php
...
Expand All @@ -398,14 +405,14 @@ $xml = Array2Xml::convert($inputArray, $config)->toXml();

> **Note**: Configuration is an array of parameters. For more details, see section [Default configuration](#default-configuration).
###### Method 2:
#### Method 2

```php
$converter = new Xml2Array($config);
$array = $converter->convertFrom($inputXml)->toArray();
```

###### Method 3:
#### Method 3

```php
$converter = new Xml2Array;
Expand All @@ -421,7 +428,7 @@ $config = $converter->getConfig();

### Default configuration

###### For Xml2Array
#### For Xml2Array

```php
$defaultConfig = [
Expand All @@ -434,7 +441,7 @@ $defaultConfig = [
];
```

###### For Array2Xml
#### For Array2Xml

```php
$defaultConfig = [
Expand All @@ -447,5 +454,5 @@ $defaultConfig = [
];
```

## License
# License
[MIT](LICENSE) © Jackie Do
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"autoload": {
"psr-4": {
"Jackiedo\\XmlArray\\": "src"
"Jackiedo\\XmlArray\\": "src/"
}
},
"minimum-stability": "stable"
Expand Down
Loading

0 comments on commit fac2f6e

Please sign in to comment.