Skip to content

Commit eb2ac46

Browse files
committedNov 22, 2023
README updated (#107)
1 parent 1b753fa commit eb2ac46

File tree

1 file changed

+43
-67
lines changed

1 file changed

+43
-67
lines changed
 

‎README.md

+43-67
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,44 @@
11
# DataCoder
22

3-
[![Build Status](https://travis-ci.org/ExOrg/php-data-coder.svg?branch=master)](https://travis-ci.org/ExOrg/php-data-coder)
3+
![example workflow](https://github.com/ExOrg/php-data-coder/actions/workflows/php.yml/badge.svg)
44

5-
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.
66

77
There are various groups of decoders and encoders
88

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*
1313

1414
## Getting Started
1515

1616
### Prerequisities
1717

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+
2021

21-
### Installation
22+
The instruction assumes using the Linux operating system or compatible tools for other operating systems.
2223

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
2425

25-
#### cURL, php8.0-cli and Git
26+
#### php8.*-cli, Git and Composer required
2627

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

29-
#### Composer
30+
The *php8.\*-cli* is needed for installing Composer.
3031

31-
The common way to intall Composer is downloading installer via *curl* tool and call the PHP interpreter to run it.
32+
#### DataCoder installation
3233

33-
```bash
34-
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
35-
```
36-
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
4935
```bash
5036
composer require exorg/data-coder
5137
```
5238
If it's project set-up stage and no one dependency have been installed yet, run
5339
```bash
5440
composer install
5541
```
56-
5742
If another dependencies have been intalled previously, run
5843
```bash
5944
composer update
@@ -65,14 +50,12 @@ The simplest way to autoload all needed files in executable file is attaching *a
6550

6651
```php
6752
require_once (__DIR__ . '/vendor/autoload.php');
68-
6953
```
7054

7155
### Data Encoders with predefined format
7256

7357
```php
74-
75-
use ExOrg\DataCoder\JsonDataEncoder;
58+
use ExOrg\DataCoder\Coder\Json\Data\Encoder;
7659

7760
$data = [
7861
"firstName" => "John",
@@ -85,7 +68,7 @@ $data = [
8568
],
8669
];
8770

88-
$encoder = new JsonDataEncoder();
71+
$encoder = new Encoder();
8972
$result = $encoder->encodeData($data);
9073

9174
print($result);
@@ -107,22 +90,19 @@ print($result);
10790
### Data Decoders with predefined format
10891

10992
```php
110-
111-
use ExOrg\DataCoder\YamlDataDecoder;
93+
use ExOrg\DataCoder\Coder\Yaml\Data\Decoder;
11294

11395
$data = '
114-
---
11596
firstName: John
11697
lastName: Smith
11798
address:
11899
streetAddress: 21 2nd Street
119100
city: New York
120101
state: NY
121102
postalCode: 10021-3100
122-
...
123103
';
124104

125-
$decoder = new YamlDataDecoder();
105+
$decoder = new Decoder();
126106
$result = $decoder->decodeData($data);
127107

128108
print_r($result);
@@ -147,7 +127,7 @@ Array
147127
### Data Encoder with configurable format
148128

149129
```php
150-
use ExOrg\DataCoder\DataEncoder;
130+
use ExOrg\DataCoder\Coder\Data\Encoder;
151131

152132
$data = [
153133
"firstName" => "John",
@@ -160,30 +140,28 @@ $data = [
160140
],
161141
];
162142

163-
$encoder = new DataEncoder();
143+
$encoder = new Encoder();
164144
$encoder->setDataFormat('yaml');
165145
$result = $encoder->encodeData($data);
166146

167147
print($result);
168148
```
169149
---
170150
```
171-
---
172151
firstName: John
173152
lastName: Smith
174153
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
180158
181159
```
182160

183161
### Data Decoder with configurable format
184162

185163
```php
186-
use ExOrg\DataCoder\DataDecoder;
164+
use ExOrg\DataCoder\Coder\Data\Decoder;
187165

188166
$data = '
189167
{
@@ -199,7 +177,7 @@ $data = '
199177
}
200178
';
201179

202-
$decoder = new DataDecoder();
180+
$decoder = new Decoder();
203181
$decoder->setDataFormat('json');
204182
$result = $decoder->decodeData($data);
205183

@@ -225,16 +203,16 @@ Array
225203

226204
### Datafile Encoders and Decoders
227205

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**.
229207

230208
#### Data format recognizing by file extension
231209

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

234-
##### DatafileEncoder
212+
##### Datafile Encoder
235213

236214
```php
237-
use ExOrg\DataCoder\DatafileEncoder;
215+
use ExOrg\DataCoder\Coder\Datafile\Encoder;
238216

239217
$data = [
240218
"firstName" => "John",
@@ -249,7 +227,7 @@ $data = [
249227

250228
$datafilePath = 'data.json';
251229

252-
$encoder = new DatafileEncoder();
230+
$encoder = new Encoder();
253231
$encoder->encodeFile($data, $datafilePath);
254232

255233
print file_get_contents($datafilePath);
@@ -268,31 +246,29 @@ print file_get_contents($datafilePath);
268246
}
269247
```
270248

271-
##### DatafileDecoder
249+
##### Datafile Decoder
272250

273251
```php
274-
use ExOrg\DataCoder\DatafileDecoder;
252+
use ExOrg\DataCoder\Coder\Datafile\Decoder;
275253

276254
$datafilePath = 'data.yaml';
277255

278256
print file_get_contents($datafilePath);
279257

280-
$decoder = new DatafileDecoder();
258+
$decoder = new Decoder();
281259
$data = $decoder->decodeFile($datafilePath);
282260

283261
print_r($data);
284262
```
285263
---
286264
```
287-
---
288265
firstName: John
289266
lastName: Smith
290267
address:
291-
streetAddress: 21 2nd Street
292-
city: New York
293-
state: NY
294-
postalCode: 10021-3100
295-
...
268+
streetAddress: '21 2nd Street'
269+
city: 'New York'
270+
state: NY
271+
postalCode: 10021-3100
296272
Array
297273
(
298274
[firstName] => John
@@ -328,7 +304,7 @@ composer test
328304

329305
### Code style tests
330306

331-
This code follows [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-2](http://www.php-fig.org/psr/psr-2/) standards.
307+
This code follows [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-12](http://www.php-fig.org/psr/psr-12/) standards.
332308

333309
To run tests for code style write the following command in your command line inside the main DataCoder project directory
334310

@@ -355,13 +331,13 @@ composer check
355331
* [Remarkable](https://remarkableapp.github.io/)
356332
* [PHPUnit](https://phpunit.de/)
357333
* [PHPCodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
334+
* [Composer](https://getcomposer.org/)
358335
* [Git](https://git-scm.com/)
359336
* [GitHub](https://github.com/)
360-
* [Travis](https://travis-ci.com/)
361337

362338
## Versioning
363339

364-
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).
365341

366342
## Contributing
367343

0 commit comments

Comments
 (0)
Please sign in to comment.