File tree 12 files changed +29
-44
lines changed
12 files changed +29
-44
lines changed Original file line number Diff line number Diff line change 28
28
* @license http://opensource.org/licenses/MIT MIT License
29
29
* @link https://github.com/ExOrg/php-data-coder
30
30
*/
31
- class Decoder extends AbstractCoder
31
+ class Decoder extends AbstractCoder implements DecodingStrategyInterface
32
32
{
33
33
use CoderBuildingTrait;
34
34
Original file line number Diff line number Diff line change 11
11
* file that was distributed with this source code.
12
12
*/
13
13
14
- namespace ExOrg \DataCoder \Coder \Data ;
14
+ namespace ExOrg \DataCoder \Coder \Datafile ;
15
15
16
16
/**
17
- * Abstract Data Decoder.
18
- * Abstract class for Data Decoder
19
- * for concrete data format.
17
+ * Datafile Decoding Strategy Interface.
18
+ * Defines interface of particular data file decoding strategy.
20
19
*
21
20
* @package DataCoder
22
21
* @author Katarzyna Krasińska <[email protected] >
23
22
* @copyright Copyright (c) 2015-2023 Katarzyna Krasińska
24
23
* @license http://opensource.org/licenses/MIT MIT License
25
24
* @link https://github.com/ExOrg/php-data-coder
26
25
*/
27
- abstract class AbstractDecoder
26
+ interface DecodingStrategyInterface
28
27
{
29
28
/**
30
- * Validate data .
29
+ * Decode file content .
31
30
*
32
- * @param string $data
31
+ * @param string $filePath
33
32
*
34
- * @return void
33
+ * @return array
35
34
*/
36
- protected function validateData (string $ data ): void
37
- {
38
- }
35
+ public function decodeFile (string $ filePath ): array ;
39
36
}
Original file line number Diff line number Diff line change 28
28
* @license http://opensource.org/licenses/MIT MIT License
29
29
* @link https://github.com/ExOrg/php-data-coder
30
30
*/
31
- class Encoder extends AbstractCoder
31
+ class Encoder extends AbstractCoder implements EncodingStrategyInterface
32
32
{
33
33
use CoderBuildingTrait;
34
34
Original file line number Diff line number Diff line change 11
11
* file that was distributed with this source code.
12
12
*/
13
13
14
- namespace ExOrg \DataCoder \Coder \Data ;
14
+ namespace ExOrg \DataCoder \Coder \Datafile ;
15
15
16
16
/**
17
- * Abstract Data Encoder.
18
- * Abstract class for Data Encoder
19
- * for concrete data format.
17
+ * Datafile Encoding Strategy Interface.
18
+ * Defines interface of particular data file encoding strategy.
20
19
*
21
20
* @package DataCoder
22
21
* @author Katarzyna Krasińska <[email protected] >
23
22
* @copyright Copyright (c) 2015-2023 Katarzyna Krasińska
24
23
* @license http://opensource.org/licenses/MIT MIT License
25
24
* @link https://github.com/ExOrg/php-data-coder
26
25
*/
27
- abstract class AbstractEncoder
26
+ interface EncodingStrategyInterface
28
27
{
29
28
/**
30
- * Validate data.
29
+ * Encode data and write to the file .
31
30
*
32
31
* @param array $data
32
+ * @param string $filePath
33
33
*
34
34
* @return void
35
35
*/
36
- protected function validateData (array $ data ): void
37
- {
38
- }
36
+ public function encodeFile (array $ data , string $ filePath ): void ;
39
37
}
Original file line number Diff line number Diff line change 13
13
14
14
namespace ExOrg \DataCoder \Coder \Json \Data ;
15
15
16
- use ExOrg \DataCoder \Coder \Data \AbstractDecoder ;
17
16
use ExOrg \DataCoder \Coder \Data \DecodingStrategyInterface ;
18
17
use ExOrg \DataCoder \DataFormat \DataFormatInvalidException ;
19
18
27
26
* @license http://opensource.org/licenses/MIT MIT License
28
27
* @link https://github.com/ExOrg/php-data-coder
29
28
*/
30
- class Decoder extends AbstractDecoder implements DecodingStrategyInterface
29
+ class Decoder implements DecodingStrategyInterface
31
30
{
32
31
/**
33
32
* Decode given JSON data to PHP array.
@@ -40,8 +39,6 @@ class Decoder extends AbstractDecoder implements DecodingStrategyInterface
40
39
*/
41
40
public function decodeData (string $ data ): array
42
41
{
43
- $ this ->validateData ($ data );
44
-
45
42
$ decodedData = json_decode ($ data , true );
46
43
47
44
$ parsingSuccessful = !(is_null ($ decodedData ));
Original file line number Diff line number Diff line change 13
13
14
14
namespace ExOrg \DataCoder \Coder \Json \Data ;
15
15
16
- use ExOrg \DataCoder \Coder \Data \AbstractEncoder ;
17
16
use ExOrg \DataCoder \Coder \Data \EncodingStrategyInterface ;
18
17
19
18
/**
26
25
* @license http://opensource.org/licenses/MIT MIT License
27
26
* @link https://github.com/ExOrg/php-data-coder
28
27
*/
29
- class Encoder extends AbstractEncoder implements EncodingStrategyInterface
28
+ class Encoder implements EncodingStrategyInterface
30
29
{
31
30
/**
32
31
* Encode given PHP array to JSON data.
@@ -39,10 +38,6 @@ class Encoder extends AbstractEncoder implements EncodingStrategyInterface
39
38
*/
40
39
public function encodeData (array $ data ): string
41
40
{
42
- $ dataTypeIsCorrect = is_array ($ data );
43
-
44
- $ this ->validateData ($ data );
45
-
46
41
$ encodedData = json_encode ($ data , JSON_PRETTY_PRINT );
47
42
48
43
return $ encodedData ;
Original file line number Diff line number Diff line change 13
13
14
14
namespace ExOrg \DataCoder \Coder \Json \Datafile ;
15
15
16
+ use ExOrg \DataCoder \Coder \Datafile \DecodingStrategyInterface ;
16
17
use ExOrg \DataCoder \File \File ;
17
18
use ExOrg \DataCoder \Coder \Json \Data \Decoder as DataDecoder ;
18
19
26
27
* @license http://opensource.org/licenses/MIT MIT License
27
28
* @link https://github.com/ExOrg/php-data-coder
28
29
*/
29
- class Decoder
30
+ class Decoder implements DecodingStrategyInterface
30
31
{
31
32
/**
32
33
* Decode file content.
Original file line number Diff line number Diff line change 13
13
14
14
namespace ExOrg \DataCoder \Coder \Json \Datafile ;
15
15
16
+ use ExOrg \DataCoder \Coder \Datafile \EncodingStrategyInterface ;
16
17
use ExOrg \DataCoder \File \File ;
17
18
use ExOrg \DataCoder \Coder \Json \Data \Encoder as DataEncoder ;
18
19
26
27
* @license http://opensource.org/licenses/MIT MIT License
27
28
* @link https://github.com/ExOrg/php-data-coder
28
29
*/
29
- class Encoder
30
+ class Encoder implements EncodingStrategyInterface
30
31
{
31
32
/**
32
33
* Encode JSON data and write to the file.
Original file line number Diff line number Diff line change 13
13
14
14
namespace ExOrg \DataCoder \Coder \Yaml \Data ;
15
15
16
- use ExOrg \DataCoder \Coder \Data \AbstractDecoder ;
17
16
use ExOrg \DataCoder \Coder \Data \DecodingStrategyInterface ;
18
17
use ExOrg \DataCoder \DataFormat \DataFormatInvalidException ;
19
18
use Symfony \Component \Yaml \Yaml ;
28
27
* @license http://opensource.org/licenses/MIT MIT License
29
28
* @link https://github.com/ExOrg/php-data-coder
30
29
*/
31
- class Decoder extends AbstractDecoder implements DecodingStrategyInterface
30
+ class Decoder implements DecodingStrategyInterface
32
31
{
33
32
/**
34
33
* Decode given YAML data to PHP array.
@@ -43,8 +42,6 @@ public function decodeData(string $data): array
43
42
{
44
43
$ this ->turnOffErrors ();
45
44
46
- $ this ->validateData ($ data );
47
-
48
45
$ parsedData = Yaml::parse ($ data );
49
46
50
47
$ parsingSuccessful = ($ parsedData !== null );
Original file line number Diff line number Diff line change 13
13
14
14
namespace ExOrg \DataCoder \Coder \Yaml \Data ;
15
15
16
- use ExOrg \DataCoder \Coder \Data \AbstractEncoder ;
17
16
use ExOrg \DataCoder \Coder \Data \EncodingStrategyInterface ;
18
17
use Symfony \Component \Yaml \Yaml ;
19
18
27
26
* @license http://opensource.org/licenses/MIT MIT License
28
27
* @link https://github.com/ExOrg/php-data-coder
29
28
*/
30
- class Encoder extends AbstractEncoder implements EncodingStrategyInterface
29
+ class Encoder implements EncodingStrategyInterface
31
30
{
32
31
/**
33
32
* Encode given PHP array to YAML data.
@@ -40,8 +39,6 @@ class Encoder extends AbstractEncoder implements EncodingStrategyInterface
40
39
*/
41
40
public function encodeData (array $ data ): string
42
41
{
43
- $ this ->validateData ($ data );
44
-
45
42
$ encodedData = Yaml::dump ($ data );
46
43
47
44
return $ encodedData ;
Original file line number Diff line number Diff line change 13
13
14
14
namespace ExOrg \DataCoder \Coder \Yaml \Datafile ;
15
15
16
+ use ExOrg \DataCoder \Coder \Datafile \DecodingStrategyInterface ;
16
17
use ExOrg \DataCoder \File \File ;
17
18
use ExOrg \DataCoder \Coder \Yaml \Data \Decoder as DataDecoder ;
18
19
26
27
* @license http://opensource.org/licenses/MIT MIT License
27
28
* @link https://github.com/ExOrg/php-data-coder
28
29
*/
29
- class Decoder
30
+ class Decoder implements DecodingStrategyInterface
30
31
{
31
32
/**
32
33
* Decode file content.
Original file line number Diff line number Diff line change 13
13
14
14
namespace ExOrg \DataCoder \Coder \Yaml \Datafile ;
15
15
16
+ use ExOrg \DataCoder \Coder \Datafile \EncodingStrategyInterface ;
16
17
use ExOrg \DataCoder \File \File ;
17
18
use ExOrg \DataCoder \Coder \Yaml \Data \Encoder as DataEncoder ;
18
19
26
27
* @license http://opensource.org/licenses/MIT MIT License
27
28
* @link https://github.com/ExOrg/php-data-coder
28
29
*/
29
- class Encoder
30
+ class Encoder implements EncodingStrategyInterface
30
31
{
31
32
/**
32
33
* Encode YAML data and write to the file.
You can’t perform that action at this time.
0 commit comments