Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 070b284

Browse files
authored
v3 (#21)
* v3 * handle t & v feedback
1 parent 3408978 commit 070b284

File tree

108 files changed

+720
-3514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+720
-3514
lines changed

README.md

+28-12
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ A simple serialization.
1414
## Requirements
1515

1616
* php: ^7.2
17-
* doctrine/inflector: ^1.0
17+
* doctrine/inflector: ^1.0|^2.0
1818
* psr/http-message: ^1.0.1
1919
* psr/link: ^1.0
20-
* psr/log: ^1.1
20+
* psr/log: ^1.1.3
2121

2222
## Suggest
2323

24-
* chubbyphp/chubbyphp-container: ^1.0
25-
* pimple/pimple: ^3.2.3
24+
* chubbyphp/chubbyphp-container: ^1.1
25+
* pimple/pimple: ^3.3
2626
* psr/container: ^1.0
27-
* symfony/dependency-injection: ^2.8.50|^3.4.26|^4.2.7|^5.0 (symfony integration)
28-
* symfony/yaml: ^2.8.50|^3.4.26|^4.2.7|^5.0 (application/x-yaml support)
27+
* symfony/dependency-injection: ^3.4.42|^4.4.10|^5.0.10 (symfony integration)
28+
* symfony/yaml: ^3.4.42|^4.4.10|^5.0.10 (application/x-yaml support)
2929

3030
## Installation
3131

3232
Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-serialization][1].
3333

3434
```sh
35-
composer require chubbyphp/chubbyphp-serialization "^2.15"
35+
composer require chubbyphp/chubbyphp-serialization "^3.0"
3636
```
3737

3838
## Usage
@@ -111,11 +111,20 @@ composer require chubbyphp/chubbyphp-serialization "^2.15"
111111
* [CallableNormalizationObjectMapping][30]
112112
* [LazyNormalizationObjectMapping][31]
113113

114+
### Policy
115+
116+
* [AndPolicy][32]
117+
* [CallbackPolicy][33]
118+
* [GroupPolicy][34]
119+
* [NotPolicy][35]
120+
* [NullPolicy][36]
121+
* [OrPolicy][37]
122+
114123
### ServiceFactory
115124

116125
#### chubbyphp-container
117126

118-
* [SerializationServiceFactory][32]
127+
* [SerializationServiceFactory][38]
119128

120129
#### chubbyphp-laminas-config-factory
121130

@@ -126,7 +135,7 @@ composer require chubbyphp/chubbyphp-serialization "^2.15"
126135

127136
### ServiceProvider
128137

129-
* [SerializationServiceProvider][33]
138+
* [SerializationServiceProvider][39]
130139

131140
### Serializer
132141

@@ -188,7 +197,7 @@ print_r($data);
188197
print_r($serializer->getContentTypes());
189198
//[
190199
// 'application/json',
191-
// 'application/x-jsonx',
200+
// 'application/jsonx+xml',
192201
// 'application/x-www-form-urlencoded',
193202
// 'application/xml',
194203
// 'application/x-yaml'
@@ -252,9 +261,16 @@ Dominik Zogg 2020
252261
[30]: doc/Mapping/CallableNormalizationObjectMapping.md
253262
[31]: doc/Mapping/LazyNormalizationObjectMapping.md
254263

255-
[32]: doc/ServiceFactory/SerializationServiceFactory.md
264+
[32]: doc/Policy/AndPolicy.md
265+
[33]: doc/Policy/CallbackPolicy.md
266+
[34]: doc/Policy/GroupPolicy.md
267+
[35]: doc/Policy/NotPolicy.md
268+
[36]: doc/Policy/NullPolicy.md
269+
[37]: doc/Policy/OrPolicy.md
270+
271+
[38]: doc/ServiceFactory/SerializationServiceFactory.md
256272

257-
[33]: doc/ServiceProvider/SerializationServiceProvider.md
273+
[39]: doc/ServiceProvider/SerializationServiceProvider.md
258274

259275
[40]: doc/ServiceFactory/EncoderFactory.md
260276
[41]: doc/ServiceFactory/NormalizerFactory.md

composer.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@
1111
],
1212
"require": {
1313
"php": "^7.2",
14-
"doctrine/inflector": "^1.0",
14+
"doctrine/inflector": "^1.0|^2.0",
1515
"psr/http-message": "^1.0.1",
1616
"psr/link": "^1.0",
17-
"psr/log": "^1.1"
17+
"psr/log": "^1.1.3"
1818
},
1919
"require-dev": {
20-
"chubbyphp/chubbyphp-container": "^1.0",
20+
"chubbyphp/chubbyphp-container": "^1.1",
2121
"chubbyphp/chubbyphp-dev-helper": "dev-master",
2222
"chubbyphp/chubbyphp-laminas-config-factory": "^1.0",
23-
"chubbyphp/chubbyphp-mock": "^1.4.2",
23+
"chubbyphp/chubbyphp-mock": "^1.4.5",
2424
"doctrine/persistence": "^1.3|^2.0",
25-
"infection/infection": "^0.15",
25+
"infection/infection": "^0.15.3|^0.16.4",
2626
"mavimo/phpstan-junit": "^0.3",
2727
"php-coveralls/php-coveralls": "^2.2",
28-
"phploc/phploc": "^5.0",
29-
"phpstan/extension-installer": "^1.0.3",
30-
"phpstan/phpstan": "^0.12.3",
31-
"phpunit/phpunit": "^8.5.1",
32-
"pimple/pimple": "^3.2.3",
28+
"phploc/phploc": "^5.0|^6.0.2",
29+
"phpstan/extension-installer": "^1.0.4",
30+
"phpstan/phpstan": "^0.12.32",
31+
"phpunit/phpunit": "^8.5.8|^9.2.5",
32+
"pimple/pimple": "^3.3",
3333
"psr/container": "^1.0",
34-
"symfony/config": "^2.8.50|^3.4.26|^4.2.7|^5.0",
35-
"symfony/dependency-injection": "^2.8.50|^3.4.26|^4.2.7|^5.0",
36-
"symfony/yaml": "^2.8.50|^3.4.26|^4.2.7|^5.0"
34+
"symfony/config": "^3.4.42|^4.4.10|^5.0.10",
35+
"symfony/dependency-injection": "^3.4.42|^4.4.10|^5.0.10",
36+
"symfony/yaml": "^3.4.42|^4.4.10|^5.0.10"
3737
},
3838
"autoload": {
3939
"psr-4": { "Chubbyphp\\Serialization\\": "src/" }
@@ -46,7 +46,7 @@
4646
},
4747
"extra": {
4848
"branch-alias": {
49-
"dev-master": "2.15-dev"
49+
"dev-master": "3.0-dev"
5050
}
5151
},
5252
"scripts": {
@@ -63,7 +63,7 @@
6363
],
6464
"test:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
6565
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=87 --verbose --coverage=build/phpunit",
66-
"test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=88 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
66+
"test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=94 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
6767
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/result.cache",
6868
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
6969
"test:loc": "mkdir -p build && vendor/bin/phploc src --verbose | tee build/phploc.log",

doc/Encoder/Encoder.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
```php
44
<?php
55

6-
use Chubbyphp\Deserialization\Encoder\Encoder;
7-
use Chubbyphp\Deserialization\Encoder\JsonTypeEncoder;
8-
use Chubbyphp\Deserialization\Encoder\UrlEncodedTypeEncoder;
9-
use Chubbyphp\Deserialization\Encoder\XmlTypeEncoder;
10-
use Chubbyphp\Deserialization\Encoder\YamlTypeEncoder;
6+
use Chubbyphp\Serialization\Encoder\Encoder;
7+
use Chubbyphp\Serialization\Encoder\JsonTypeEncoder;
8+
use Chubbyphp\Serialization\Encoder\JsonxTypeEncoder;
9+
use Chubbyphp\Serialization\Encoder\UrlEncodedTypeEncoder;
10+
use Chubbyphp\Serialization\Encoder\XmlTypeEncoder;
11+
use Chubbyphp\Serialization\Encoder\YamlTypeEncoder;
1112

1213
$encoder = new Encoder([
1314
new JsonTypeEncoder(),
15+
new JsonxTypeEncoder(),
1416
new UrlEncodedTypeEncoder(),
1517
new XmlTypeEncoder(),
1618
new YamlTypeEncoder()
@@ -19,6 +21,7 @@ $encoder = new Encoder([
1921
print_r($encoder->getContentTypes());
2022
//[
2123
// 'application/json',
24+
// 'application/jsonx+xml',
2225
// 'application/x-www-form-urlencoded',
2326
// 'application/xml',
2427
// 'application/x-yaml'
@@ -29,4 +32,4 @@ echo $encoder->encode(
2932
'application/json'
3033
);
3134
// '{"name": "php"}'
32-
```
35+
```

doc/Encoder/JsonxTypeEncoder.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Chubbyphp\Serialization\Encoder\JsonxTypeEncoder;
88
$encoderType = new JsonxTypeEncoder();
99

1010
echo $encoderType->getContentType();
11-
// 'application/x-jsonx'
11+
// 'application/jsonx+xml'
1212

1313
echo $encoderType->encode(['name' => 'php']);
1414
// '<json:object><json:string name="name">php</json:string></json:object>'

doc/Encoder/XmlTypeEncoder.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# XmlTypeEncoder
1+
# XmlTypeEncoder (alias for Jsonx)
22

33
```php
44
<?php
@@ -11,5 +11,5 @@ echo $encoderType->getContentType();
1111
// 'application/xml'
1212

1313
echo $encoderType->encode(['name' => 'php']);
14-
// '<name type="string">php</name>'
14+
// '<json:object><json:string name="name">php</json:string></json:object>'
1515
```

doc/Mapping/AdvancedNormalizationObjectMapping.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ namespace MyProject\Serialization;
1111

1212
use Chubbyphp\Serialization\Accessor\PropertyAccessor;
1313
use Chubbyphp\Serialization\Link\LinkBuilder;
14+
use Chubbyphp\Serialization\Mapping\NormalizationFieldMappingBuilder;
15+
use Chubbyphp\Serialization\Mapping\NormalizationFieldMappingInterface;
1416
use Chubbyphp\Serialization\Mapping\NormalizationLinkMapping;
1517
use Chubbyphp\Serialization\Mapping\NormalizationLinkMappingInterface;
18+
use Chubbyphp\Serialization\Mapping\NormalizationObjectMappingInterface;
1619
use Chubbyphp\Serialization\Normalizer\CallbackLinkNormalizer;
1720
use Chubbyphp\Serialization\Normalizer\Relation\EmbedManyFieldNormalizer;
18-
use Chubbyphp\Serialization\Mapping\NormalizationFieldMappingBuilder;
19-
use Chubbyphp\Serialization\Mapping\NormalizationFieldMappingInterface;
20-
use Chubbyphp\Serialization\Mapping\NormalizationObjectMappingInterface;
2121
use Chubbyphp\Serialization\Normalizer\Relation\EmbedOneFieldNormalizer;
22+
use Chubbyphp\Serialization\Policy\GroupPolicy;
2223
use MyProject\Model\Model;
2324

2425
final class ModelMapping implements NormalizationObjectMappingInterface
@@ -48,8 +49,12 @@ final class ModelMapping implements NormalizationObjectMappingInterface
4849
public function getNormalizationFieldMappings(string $path, string $type = null): array
4950
{
5051
return [
51-
NormalizationFieldMappingBuilder::create('id')->setGroups(['baseInformation'])->getMapping(),
52-
NormalizationFieldMappingBuilder::create('name')->setGroups(['baseInformation'])->getMapping(),
52+
NormalizationFieldMappingBuilder::create('id')
53+
->setPolicy(new GroupPolicy(['baseInformation']))
54+
->getMapping(),
55+
NormalizationFieldMappingBuilder::create('name')
56+
->setPolicy(new GroupPolicy(['baseInformation']))
57+
->getMapping(),
5358
NormalizationFieldMappingBuilder::createEmbedOne('one')->getMapping(),
5459
NormalizationFieldMappingBuilder::createEmbedMany('manies')->getMapping(),
5560
];

doc/Mapping/NormalizationFieldMappingBuilder.md

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use Chubbyphp\Serialization\Normalizer\FieldNormalizer;
88
use Chubbyphp\Serialization\Mapping\NormalizationFieldMappingBuilder;
99

1010
$fieldMapping = NormalizationFieldMappingBuilder::create('name')
11-
->setGroups(['group1'])
1211
->setFieldNormalizer(
1312
new FieldNormalizer(
1413
new PropertyAccessor('name')

doc/Mapping/NormalizationLinkMappingBuilder.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ use Chubbyphp\Serialization\Normalizer\CallbackLinkNormalizer;
99
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
1010

1111
$fieldMapping = NormalizationLinkMappingBuilder::create(
12-
'name',
13-
new CallbackLinkNormalizer(
14-
function (
15-
string $path,
16-
$object,
17-
NormalizerContextInterface $context
18-
) {
19-
return new Link('/api/model');
20-
}
21-
)
12+
'name',
13+
new CallbackLinkNormalizer(
14+
function (
15+
string $path,
16+
$object,
17+
NormalizerContextInterface $context
18+
) {
19+
return new Link('/api/model');
20+
}
2221
)
23-
->setGroups(['group1'])
24-
->getMapping();
22+
)
23+
->getMapping();
2524

2625
echo $fieldMapping->getName();
2726
// 'name'

doc/Normalizer/CallbackFieldNormalizer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $context = ...;
1414
$fieldNormalizer = new CallbackFieldNormalizer(
1515
function (
1616
string $path,
17-
$object,
17+
object $object,
1818
NormalizerContextInterface $context,
1919
NormalizerInterface $normalizer = null
2020
) {

doc/Normalizer/CallbackLinkNormalizer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $context = ...;
1414
$fieldNormalizer = new CallbackLinkNormalizer(
1515
function (
1616
string $path,
17-
$object,
17+
object $object,
1818
NormalizerContextInterface $context
1919
) {
2020
return new Link('/api/model');

doc/Normalizer/NormalizerContext.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use Psr\Http\Message\ServerRequestInterface;
88

99
$request = ...;
1010

11-
$context = new NormalizerContext(['group1'], $request);
12-
13-
print_r($context->getGroups());
14-
// ['group1']
11+
$context = new NormalizerContext($request, ['key' => 'value']);
1512

1613
$request = $context->getRequest();
14+
15+
print_r($context->getAttributes());
16+
// ['key' => 'value']
1717
```

doc/Normalizer/NormalizerContextBuilder.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use Psr\Http\Message\ServerRequestInterface;
99
$request = ...;
1010

1111
$context = NormalizerContextBuilder::create()
12-
->setGroups(['group1'])
1312
->setRequest($request)
13+
->setAttributes(['key' => 'value'])
1414
->getContext();
1515

16-
print_r($context->getGroups());
17-
// ['group1']
16+
print_r($context->getAttributes());
17+
// ['key' => 'value']
1818

1919
$request = $context->getRequest();
2020
```

doc/Policy/AndPolicy.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# AndPolicy
2+
3+
```php
4+
<?php
5+
6+
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
7+
use Chubbyphp\Serialization\Policy\AndPolicy;
8+
use MyProject\Model\Model;
9+
use MyProject\Policy\AnotherPolicy;
10+
use MyProject\Policy\SomePolicy;
11+
12+
$model = new Model();
13+
14+
/** @var NormalizerContextInterface $context */
15+
$context = ...;
16+
17+
$policy = new AndPolicy([
18+
new SomePolicy(),
19+
new AnotherPolicy(),
20+
]);
21+
22+
echo $policy->isCompliant('path', $model, $context);
23+
// 1
24+
```

doc/Policy/CallbackPolicy.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# CallbackPolicy
2+
3+
```php
4+
<?php
5+
6+
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
7+
use Chubbyphp\Serialization\Policy\CallbackPolicy;
8+
use MyProject\Model\Model;
9+
10+
$model = new Model();
11+
12+
/** @var NormalizerContextInterface $context */
13+
$context = ...;
14+
15+
$policy = new CallbackPolicy(function (string $path, object $object, NormalizerContextInterface $context) {
16+
return true;
17+
});
18+
19+
echo $policy->isCompliant('path', $model, $context);
20+
// 1
21+
```

0 commit comments

Comments
 (0)