Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 107 namespaces and autoloading adjustment #108

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
599881a
Exorg vendor name in namespaces changed to ExOrg (ExOrg#107)
katheroine Nov 6, 2023
e95f48a
ExOrg\DataCoder\File fully qualified namespace changed to ExOrg\DataC…
katheroine Nov 7, 2023
8e022b7
ExOrg\DataCoder\CoderBuildingTrait fully qualified namespace changed …
katheroine Nov 8, 2023
6cc4a1c
DatafileDecoder class fixed after changes of File class and CoderBuil…
katheroine Nov 8, 2023
9d1e686
JsonDatafileDecoder class fixed after changes of File class and Coder…
katheroine Nov 8, 2023
ef3d7fd
YamlDatafileDecoder class fixed after changes of File class and Coder…
katheroine Nov 8, 2023
b0c39a7
DatafileEncoder class fixed after changes of File class and CoderBuil…
katheroine Nov 8, 2023
7da85a0
JsonDatafileEncoder class fixed after changes of File class and Coder…
katheroine Nov 8, 2023
083d23e
YamlDatafileEncoder class fixed after changes of File class and Coder…
katheroine Nov 8, 2023
3d8b5ff
DataDecoder class fixed after changes of File class and CoderBuilding…
katheroine Nov 9, 2023
f7782fb
DataEncoder class fixed after changes of File class and CoderBuilding…
katheroine Nov 9, 2023
20d4636
Data Encoders classes namespaces changed, class file paths updated (E…
katheroine Nov 9, 2023
626d15a
Data Decoders classes namespaces changed, class file paths updated (E…
katheroine Nov 9, 2023
16693dd
Datafile Encoders classes namespaces changed, class file paths update…
katheroine Nov 13, 2023
b3a3cf1
Datafile Decoders classes namespaces changed, class file paths update…
katheroine Nov 13, 2023
5e0d5c5
CoderBuildingTrait tests fixed (ExOrg#107)
katheroine Nov 14, 2023
907efbd
Composer autoloading configuration updated (ExOrg#107)
katheroine Nov 15, 2023
151217a
Git ignoring configuration updated (ExOrg#107)
katheroine Nov 15, 2023
67908aa
DataFileFixturesHelper class namespace changed, class file path updat…
katheroine Nov 15, 2023
e37db2c
Composer autoloading configuration updated (ExOrg#107)
katheroine Nov 15, 2023
1b753fa
testing_environment directory renamed to fixtures (ExOrg#107)
katheroine Nov 15, 2023
eb2ac46
README updated (ExOrg#107)
katheroine Nov 20, 2023
a27bdb8
PHPCodeSniffer excluding comment added to DataFormat enum (ExOrg#107)
katheroine Nov 22, 2023
36af963
Class names in PHPDoc updated (ExOrg#107)
katheroine Nov 22, 2023
67291a4
Class descriptions in PHPDoc updated (ExOrg#107)
katheroine Nov 23, 2023
f8c7ed6
.gitignore files in fixtures directories updated (ExOrg#107)
katheroine Nov 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
vendor/
.phpunit.result.cache

110 changes: 43 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,44 @@
# DataCoder

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

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

There are various groups of decoders and encoders

* With predefined data format - e.g. *JsonDataDecoder*, *YamlDatafileEncoder*
* With configurable data format - e.g. *DataDecoder*, *DatafileEncoder*
* For raw data - e.g. *JsonDataDecoder*, *DataEncoder*
* For data in the file - e.g. *YamlDatafileEncoder*, *DatafileDecoder*
* With predefined data format - e.g. *Coder\Json\Data\Decoder*, *Coder\Yaml\Datafile\Encoder*
* With configurable data format - e.g. *Coder\Data\Decoder*, *Coder\Datafile\Encoder*
* For raw data - e.g. *Coder\Json\Data\Decoder*, *Coder\Data\Encoder*
* For data in the file - e.g. *Coder\Yaml\Datafile\Encoder*, *Coder\Datafile\Decoder*

## Getting Started

### Prerequisities

* PHP 8.0+
* [Composer](https://getcomposer.org/) 2.5.0+
* [PHP](https://www.php.net/) 8.1 - 8.3
* [Git](https://git-scm.com/) 2.25.1+
* [Composer](https://getcomposer.org/) 2.6.0+

### Installation
The instruction assumes using the Linux operating system or compatible tools for other operating systems.

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).
### Installation

#### cURL, php8.0-cli and Git
#### php8.*-cli, Git and Composer required

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

#### Composer
The *php8.\*-cli* is needed for installing Composer.

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

```bash
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
```
Now composer is available as the command line tool and can be run by typing `composer` with appropriate parameters.

#### DataCoder

Add to your **composer.json** file following entry in the *require* section
```
{
"require": {
"exorg/data-coder": "^1.0.0"
}
}
```
You can do it manually or by running the following command
Add to your **composer.json** file appropriate entry by running the following command
```bash
composer require exorg/data-coder
```
If it's project set-up stage and no one dependency have been installed yet, run
```bash
composer install
```

If another dependencies have been intalled previously, run
```bash
composer update
Expand All @@ -65,14 +50,12 @@ The simplest way to autoload all needed files in executable file is attaching *a

```php
require_once (__DIR__ . '/vendor/autoload.php');

```

### Data Encoders with predefined format

```php

use Exorg\DataCoder\JsonDataEncoder;
use ExOrg\DataCoder\Coder\Json\Data\Encoder;

$data = [
"firstName" => "John",
Expand All @@ -85,7 +68,7 @@ $data = [
],
];

$encoder = new JsonDataEncoder();
$encoder = new Encoder();
$result = $encoder->encodeData($data);

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

```php

use Exorg\DataCoder\YamlDataDecoder;
use ExOrg\DataCoder\Coder\Yaml\Data\Decoder;

$data = '
---
firstName: John
lastName: Smith
address:
streetAddress: 21 2nd Street
city: New York
state: NY
postalCode: 10021-3100
...
';

$decoder = new YamlDataDecoder();
$decoder = new Decoder();
$result = $decoder->decodeData($data);

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

```php
use Exorg\DataCoder\DataEncoder;
use ExOrg\DataCoder\Coder\Data\Encoder;

$data = [
"firstName" => "John",
Expand All @@ -160,30 +140,28 @@ $data = [
],
];

$encoder = new DataEncoder();
$encoder = new Encoder();
$encoder->setDataFormat('yaml');
$result = $encoder->encodeData($data);

print($result);
```
---
```
---
firstName: John
lastName: Smith
address:
streetAddress: 21 2nd Street
city: New York
state: NY
postalCode: 10021-3100
...
streetAddress: '21 2nd Street'
city: 'New York'
state: NY
postalCode: 10021-3100

```

### Data Decoder with configurable format

```php
use Exorg\DataCoder\DataDecoder;
use ExOrg\DataCoder\Coder\Data\Decoder;

$data = '
{
Expand All @@ -199,7 +177,7 @@ $data = '
}
';

$decoder = new DataDecoder();
$decoder = new Decoder();
$decoder->setDataFormat('json');
$result = $decoder->decodeData($data);

Expand All @@ -225,16 +203,16 @@ Array

### Datafile Encoders and Decoders

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

#### Data format recognizing by file extension

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

##### DatafileEncoder
##### Datafile Encoder

```php
use Exorg\DataCoder\DatafileEncoder;
use ExOrg\DataCoder\Coder\Datafile\Encoder;

$data = [
"firstName" => "John",
Expand All @@ -249,7 +227,7 @@ $data = [

$datafilePath = 'data.json';

$encoder = new DatafileEncoder();
$encoder = new Encoder();
$encoder->encodeFile($data, $datafilePath);

print file_get_contents($datafilePath);
Expand All @@ -268,31 +246,29 @@ print file_get_contents($datafilePath);
}
```

##### DatafileDecoder
##### Datafile Decoder

```php
use Exorg\DataCoder\DatafileDecoder;
use ExOrg\DataCoder\Coder\Datafile\Decoder;

$datafilePath = 'data.yaml';

print file_get_contents($datafilePath);

$decoder = new DatafileDecoder();
$decoder = new Decoder();
$data = $decoder->decodeFile($datafilePath);

print_r($data);
```
---
```
---
firstName: John
lastName: Smith
address:
streetAddress: 21 2nd Street
city: New York
state: NY
postalCode: 10021-3100
...
streetAddress: '21 2nd Street'
city: 'New York'
state: NY
postalCode: 10021-3100
Array
(
[firstName] => John
Expand Down Expand Up @@ -328,7 +304,7 @@ composer test

### Code style tests

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

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

Expand All @@ -355,13 +331,13 @@ composer check
* [Remarkable](https://remarkableapp.github.io/)
* [PHPUnit](https://phpunit.de/)
* [PHPCodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
* [Composer](https://getcomposer.org/)
* [Git](https://git-scm.com/)
* [GitHub](https://github.com/)
* [Travis](https://travis-ci.com/)

## Versioning

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

## Contributing

Expand Down
32 changes: 5 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,16 @@
},
"autoload": {
"psr-4": {
"Exorg\\DataCoder\\": [
"src/",
"src/coders",
"src/coders/data_coders/",
"src/coders/data_coders/data_encoders/",
"src/coders/data_coders/data_decoders/",
"src/coders/datafile_coders/",
"src/coders/datafile_coders/datafile_encoders/",
"src/coders/datafile_coders/datafile_decoders/",
"src/data_format/",
"src/coder_builder/",
"src/file/"
"ExOrg\\DataCoder\\": [
"src/"
]
}
},
"autoload-dev": {
"psr-4": {
"Exorg\\DataCoder\\": [
"tests/",
"tests/testing_environment/",
"tests/testing_environment/helpers/",
"tests/testing_environment/classes/",
"tests/unit_tests/coders/",
"tests/unit_tests/coders/data_coders/",
"tests/unit_tests/coders/data_coders/data_encoders/",
"tests/unit_tests/coders/data_coders/data_decoders/",
"tests/unit_tests/coders/datafile_coders/",
"tests/unit_tests/coders/datafile_coders/datafile_encoders/",
"tests/unit_tests/coders/datafile_coders/datafile_decoders/",
"tests/unit_tests/data_format/",
"tests/unit_tests/coder_builder/",
"tests/unit_tests/file/"
"ExOrg\\DataCoder\\": [
"tests/unit_tests/",
"tests/fixtures/classes/"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<ruleset name="Exorg_PHP_DataCoder">
<ruleset name="ExOrg_PHP_DataCoder">
<description>The coding standard for PHPDataCoder.</description>

<file>./src</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* file that was distributed with this source code.
*/

namespace Exorg\DataCoder;
namespace ExOrg\DataCoder\Coder\Data;

/**
* AbstractDataDecoder.
* Abstract Data Decoder.
* Abstract class for Data Decoder
* for concrete data format.
*
Expand All @@ -22,7 +22,7 @@
* @license http://opensource.org/licenses/MIT MIT License
* @link https://github.com/ExOrg/php-data-coder
*/
abstract class AbstractDataDecoder
abstract class AbstractDecoder
{
/**
* Validate data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Exorg\DataCoder;
namespace ExOrg\DataCoder\Coder\Data;

/**
* AbstractDataEncoder.
Expand All @@ -22,7 +22,7 @@
* @license http://opensource.org/licenses/MIT MIT License
* @link https://github.com/ExOrg/php-data-coder
*/
abstract class AbstractDataEncoder
abstract class AbstractEncoder
{
/**
* Validate data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
* file that was distributed with this source code.
*/

namespace Exorg\DataCoder;
namespace ExOrg\DataCoder\Coder\Data;

use ExOrg\DataCoder\Coder\Data\DecodingStrategyInterface;
use ExOrg\DataCoder\CoderBuilder\CoderBuildingTrait;
use ExOrg\DataCoder\DataFormat\DataFormatConfigurableTrait;

/**
* DataDecoder.
Expand All @@ -22,7 +26,7 @@
* @license http://opensource.org/licenses/MIT MIT License
* @link https://github.com/ExOrg/php-data-coder
*/
class DataDecoder
class Decoder implements DecodingStrategyInterface
{
use DataFormatConfigurableTrait;
use CoderBuildingTrait;
Expand Down
Loading