You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extendable set of data and datafile encoders and decoders. It allows to transfer PHP arrays into data strings and datafiles and vice versa with chosen format like YAML and JSON. It provides encapsulation of various decoding and encoding mechanisms, unifies interface and exceptions handling.
5
+
Extendable set of data and data file encoders and decoders. It allows to transfer PHP arrays into data strings and datafiles and vice versa with chosen format like YAML and JSON. It provides encapsulation of various decoding and encoding mechanisms, unifies interface and exceptions handling.
6
6
7
7
There are various groups of decoders and encoders
8
8
9
-
* With predefined data format - e.g. *JsonDataDecoder*, *YamlDatafileEncoder*
10
-
* With configurable data format - e.g. *DataDecoder*, *DatafileEncoder*
11
-
* For raw data - e.g. *JsonDataDecoder*, *DataEncoder*
12
-
* For data in the file - e.g. *YamlDatafileEncoder*, *DatafileDecoder*
9
+
* With predefined data format - e.g. *Coder\Json\Data\Decoder*, *Coder\Yaml\Datafile\Encoder*
10
+
* With configurable data format - e.g. *Coder\Data\Decoder*, *Coder\Datafile\Encoder*
11
+
* For raw data - e.g. *Coder\Json\Data\Decoder*, *Coder\Data\Encoder*
12
+
* For data in the file - e.g. *Coder\Yaml\Datafile\Encoder*, *Coder\Datafile\Decoder*
13
13
14
14
## Getting Started
15
15
16
16
### Prerequisities
17
17
18
-
* PHP 8.0+
19
-
*[Composer](https://getcomposer.org/) 2.5.0+
18
+
*[PHP](https://www.php.net/) 8.1 - 8.3
19
+
*[Git](https://git-scm.com/) 2.25.1+
20
+
*[Composer](https://getcomposer.org/) 2.6.0+
20
21
21
-
### Installation
22
+
The instruction assumes using the Linux operating system or compatible tools for other operating systems.
22
23
23
-
The recommended way to install DataCoder into the source code of the project is to handle it as code dependency by [Composer](http://getcomposer.org).
24
+
### Installation
24
25
25
-
#### cURL, php8.0-cliand Git
26
+
#### php8.*-cli, Git and Composer required
26
27
27
-
The command line tool cURL will be used to to download *Composer* installer and *php8.0-cli* for and running it to install Composer. Git is needed by to downloading dependencies by the Composer.
28
+
The recommended way to install DataCoder into the source code of the project is to handle it as code dependency by [Composer](http://getcomposer.org). [Git](https://git-scm.com/) is needed to fetch packages from version control repositories.
28
29
29
-
#### Composer
30
+
The *php8.\*-cli* is needed for installing Composer.
30
31
31
-
The common way to intall Composer is downloading installer via *curl* tool and call the PHP interpreter to run it.
Now composer is available as the command line tool and can be run by typing `composer` with appropriate parameters.
37
-
38
-
#### DataCoder
39
-
40
-
Add to your **composer.json** file following entry in the *require* section
41
-
```
42
-
{
43
-
"require": {
44
-
"exorg/data-coder": "^1.0.0"
45
-
}
46
-
}
47
-
```
48
-
You can do it manually or by running the following command
34
+
Add to your **composer.json** file appropriate entry by running the following command
49
35
```bash
50
36
composer require exorg/data-coder
51
37
```
52
38
If it's project set-up stage and no one dependency have been installed yet, run
53
39
```bash
54
40
composer install
55
41
```
56
-
57
42
If another dependencies have been intalled previously, run
58
43
```bash
59
44
composer update
@@ -65,14 +50,12 @@ The simplest way to autoload all needed files in executable file is attaching *a
65
50
66
51
```php
67
52
require_once (__DIR__ . '/vendor/autoload.php');
68
-
69
53
```
70
54
71
55
### Data Encoders with predefined format
72
56
73
57
```php
74
-
75
-
use ExOrg\DataCoder\JsonDataEncoder;
58
+
use ExOrg\DataCoder\Coder\Json\Data\Encoder;
76
59
77
60
$data = [
78
61
"firstName" => "John",
@@ -85,7 +68,7 @@ $data = [
85
68
],
86
69
];
87
70
88
-
$encoder = new JsonDataEncoder();
71
+
$encoder = new Encoder();
89
72
$result = $encoder->encodeData($data);
90
73
91
74
print($result);
@@ -107,22 +90,19 @@ print($result);
107
90
### Data Decoders with predefined format
108
91
109
92
```php
110
-
111
-
use ExOrg\DataCoder\YamlDataDecoder;
93
+
use ExOrg\DataCoder\Coder\Yaml\Data\Decoder;
112
94
113
95
$data = '
114
-
---
115
96
firstName: John
116
97
lastName: Smith
117
98
address:
118
99
streetAddress: 21 2nd Street
119
100
city: New York
120
101
state: NY
121
102
postalCode: 10021-3100
122
-
...
123
103
';
124
104
125
-
$decoder = new YamlDataDecoder();
105
+
$decoder = new Decoder();
126
106
$result = $decoder->decodeData($data);
127
107
128
108
print_r($result);
@@ -147,7 +127,7 @@ Array
147
127
### Data Encoder with configurable format
148
128
149
129
```php
150
-
use ExOrg\DataCoder\DataEncoder;
130
+
use ExOrg\DataCoder\Coder\Data\Encoder;
151
131
152
132
$data = [
153
133
"firstName" => "John",
@@ -160,30 +140,28 @@ $data = [
160
140
],
161
141
];
162
142
163
-
$encoder = new DataEncoder();
143
+
$encoder = new Encoder();
164
144
$encoder->setDataFormat('yaml');
165
145
$result = $encoder->encodeData($data);
166
146
167
147
print($result);
168
148
```
169
149
---
170
150
```
171
-
---
172
151
firstName: John
173
152
lastName: Smith
174
153
address:
175
-
streetAddress: 21 2nd Street
176
-
city: New York
177
-
state: NY
178
-
postalCode: 10021-3100
179
-
...
154
+
streetAddress: '21 2nd Street'
155
+
city: 'New York'
156
+
state: NY
157
+
postalCode: 10021-3100
180
158
181
159
```
182
160
183
161
### Data Decoder with configurable format
184
162
185
163
```php
186
-
use ExOrg\DataCoder\DataDecoder;
164
+
use ExOrg\DataCoder\Coder\Data\Decoder;
187
165
188
166
$data = '
189
167
{
@@ -199,7 +177,7 @@ $data = '
199
177
}
200
178
';
201
179
202
-
$decoder = new DataDecoder();
180
+
$decoder = new Decoder();
203
181
$decoder->setDataFormat('json');
204
182
$result = $decoder->decodeData($data);
205
183
@@ -225,16 +203,16 @@ Array
225
203
226
204
### Datafile Encoders and Decoders
227
205
228
-
Datafile Encoders and Decoders usage is similar to the Data Encoders and Decoders. There are coders with predefined data format like **JsonDatafileEncoder** or **YamlDatafileDecoder** and those, where data format can be chosen by function *setDataFormat*, just like in examples above - **DatafileEncoder** and **DatafileDecoder**.
206
+
Datafile Encoders and Decoders usage is similar to the Data Encoders and Decoders. There are coders with predefined data format like **Coder\Json\Datafile\Encoder** or **Coder\Yaml\Datafile\Decoder** and those, where data format can be chosen by function *setDataFormat*, just like in examples above - **Code\Datafile\Encoder** and **Code\Datafile\Decoder**.
229
207
230
208
#### Data format recognizing by file extension
231
209
232
-
Datafile coders with configurable data format - **DatafileEncoder** and **DatafileDecoder** - can recognize data format by file extension. In that case, there is no need to set data format manually.
210
+
Datafile coders with configurable data format - **Coder\Datafile\Encoder** and **Coder\Datafile\Decoder** - can recognize data format by file extension. In that case, there is no need to set data format manually.
This project is versioning according to [SemVer](http://semver.org/) versioning standars. All available [releases](https://github.com/ExOrg/php-data-coder/releases) are [tagged](https://github.com/ExOrg/php-data-coder/tags).
340
+
This project is versioning according to [SemVer](http://semver.org/) versioning standars. All available [releases](https://github.com/ExOrg/php-data-coder/releases) are [tagged](https://github.com/ExOrg/php-data-coder/tags).
0 commit comments