Skip to content

Commit

Permalink
Merge 15d8fba into 999c2da
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Zogg committed Sep 20, 2020
2 parents 999c2da + 15d8fba commit 4f28ed3
Show file tree
Hide file tree
Showing 84 changed files with 707 additions and 3,044 deletions.
37 changes: 26 additions & 11 deletions README.md
Expand Up @@ -15,22 +15,22 @@ A simple deserialization.

* php: ^7.2
* psr/http-message: ^1.0.1
* psr/log: ^1.1
* psr/log: ^1.1.3

## Suggest

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

## Installation

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

```sh
composer require chubbyphp/chubbyphp-deserialization "^2.19"
composer require chubbyphp/chubbyphp-deserialization "^3.0"
```

## Usage
Expand Down Expand Up @@ -126,7 +126,7 @@ echo $model->getName();
print_r($deserializer->getContentTypes());
//[
// 'application/json',
// 'application/x-jsonx',
// 'application/jsonx+xml',
// 'application/x-www-form-urlencoded',
// 'application/xml',
// 'application/x-yaml'
Expand Down Expand Up @@ -164,12 +164,20 @@ echo $model->getName();
* [CallableDenormalizationObjectMapping][25]
* [LazyDenormalizationObjectMapping][26]

### Policy

* [AndPolicy][27]
* [CallbackPolicyIncludingPath][28]
* [GroupPolicy][29]
* [NotPolicy][30]
* [NullPolicy][31]
* [OrPolicy][32]

### ServiceFactory

#### chubbyphp-container

* [DeserializationServiceFactory][27]
* [DeserializationServiceFactory][33]

#### chubbyphp-laminas-config-factory

Expand All @@ -180,7 +188,7 @@ echo $model->getName();

### ServiceProvider

* [DeserializationServiceProvider][28]
* [DeserializationServiceProvider][34]

## Copyright

Expand Down Expand Up @@ -226,9 +234,16 @@ Dominik Zogg 2020
[25]: doc/Mapping/CallableDenormalizationObjectMapping.md
[26]: doc/Mapping/LazyDenormalizationObjectMapping.md

[27]: doc/ServiceFactory/DeserializationServiceFactory.md
[27]: doc/Policy/AndPolicy.md
[28]: doc/Policy/CallbackPolicyIncludingPath.md
[29]: doc/Policy/GroupPolicy.md
[30]: doc/Policy/NotPolicy.md
[31]: doc/Policy/NullPolicy.md
[32]: doc/Policy/OrPolicy.md

[33]: doc/ServiceFactory/DeserializationServiceFactory.md

[28]: doc/ServiceProvider/DeserializationServiceProvider.md
[34]: doc/ServiceProvider/DeserializationServiceProvider.md

[40]: doc/ServiceFactory/DecoderFactory.md
[41]: doc/ServiceFactory/DenormalizerFactory.md
Expand Down
30 changes: 15 additions & 15 deletions composer.json
Expand Up @@ -12,26 +12,26 @@
"require": {
"php": "^7.2",
"psr/http-message": "^1.0.1",
"psr/log": "^1.1"
"psr/log": "^1.1.3"
},
"require-dev": {
"chubbyphp/chubbyphp-container": "^1.0",
"chubbyphp/chubbyphp-container": "^1.1",
"chubbyphp/chubbyphp-dev-helper": "dev-master",
"chubbyphp/chubbyphp-laminas-config-factory": "^1.0",
"chubbyphp/chubbyphp-mock": "^1.4.2",
"chubbyphp/chubbyphp-mock": "^1.4.5",
"doctrine/persistence": "^1.3|^2.0",
"infection/infection": "^0.15",
"infection/infection": "^0.15.3|^0.16.4",
"mavimo/phpstan-junit": "^0.3",
"php-coveralls/php-coveralls": "^2.2",
"phploc/phploc": "^5.0",
"phpstan/extension-installer": "^1.0.3",
"phpstan/phpstan": "^0.12.3",
"phpunit/phpunit": "^8.5.1",
"pimple/pimple": "^3.2.3",
"phploc/phploc": "^5.0|^6.0.2",
"phpstan/extension-installer": "^1.0.4",
"phpstan/phpstan": "^0.12.32",
"phpunit/phpunit": "^8.5.8|^9.2.5",
"pimple/pimple": "^3.3",
"psr/container": "^1.0",
"symfony/config": "^2.8.50|^3.4.26|^4.2.7|^5.0",
"symfony/dependency-injection": "^2.8.50|^3.4.26|^4.2.7|^5.0",
"symfony/yaml": "^2.8.50|^3.4.26|^4.2.7|^5.0"
"symfony/config": "^3.4.42|^4.4.10|^5.0.10",
"symfony/dependency-injection": "^3.4.42|^4.4.10|^5.0.10",
"symfony/yaml": "^3.4.42|^4.4.10|^5.0.10"
},
"autoload": {
"psr-4": { "Chubbyphp\\Deserialization\\": "src/" }
Expand All @@ -44,7 +44,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.19-dev"
"dev-master": "3.0-dev"
}
},
"scripts": {
Expand All @@ -60,8 +60,8 @@
"@test:insights"
],
"test:cs": "mkdir -p build && vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=93 --verbose --coverage=build/phpunit",
"test:insights": "mkdir -p build && bash -c 'vendor/bin/phpinsights analyse -v --no-interaction --min-quality=82 --disable-security-check | tee build/phpinsights.log; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=95 --verbose --coverage=build/phpunit",
"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'",
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/result.cache",
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
"test:loc": "mkdir -p build && vendor/bin/phploc src --verbose | tee build/phploc.log",
Expand Down
5 changes: 4 additions & 1 deletion doc/Decoder/Decoder.md
Expand Up @@ -5,12 +5,14 @@

use Chubbyphp\Deserialization\Decoder\Decoder;
use Chubbyphp\Deserialization\Decoder\JsonTypeDecoder;
use Chubbyphp\Deserialization\Decoder\JsonxTypeDecoder;
use Chubbyphp\Deserialization\Decoder\UrlEncodedTypeDecoder;
use Chubbyphp\Deserialization\Decoder\XmlTypeDecoder;
use Chubbyphp\Deserialization\Decoder\YamlTypeDecoder;

$decoder = new Decoder([
new JsonTypeDecoder(),
new JsonxTypeDecoder(),
new UrlEncodedTypeDecoder(),
new XmlTypeDecoder(),
new YamlTypeDecoder()
Expand All @@ -19,6 +21,7 @@ $decoder = new Decoder([
print_r($decoder->getContentTypes());
//[
// 'application/json',
// 'application/jsonx+xml',
// 'application/x-www-form-urlencoded',
// 'application/xml',
// 'application/x-yaml'
Expand All @@ -29,4 +32,4 @@ print_r($decoder->decode(
'application/json'
));
// ['name' => 'php']
```
```
2 changes: 1 addition & 1 deletion doc/Decoder/JsonxTypeDecoder.md
Expand Up @@ -8,7 +8,7 @@ use Chubbyphp\Deserialization\Decoder\JsonxTypeDecoder;
$decoderType = new JsonxTypeDecoder();

echo $decoderType->getContentType();
// 'application/x-jsonx'
// 'application/jsonx+xml'

print_r($decoderType->decode('<json:object><json:string name="name">php</json:string></json:object>'));
// ['name' => 'php']
Expand Down
4 changes: 2 additions & 2 deletions doc/Decoder/XmlTypeDecoder.md
@@ -1,4 +1,4 @@
# XmlTypeDecoder
# XmlTypeDecoder (alias for Jsonx)

```php
<?php
Expand All @@ -10,6 +10,6 @@ $decoderType = new XmlTypeDecoder();
echo $decoderType->getContentType();
// 'application/xml'

print_r($decoderType->decode('<name type="string">php</name>'));
print_r($decoderType->decode('<json:object><json:string name="name">php</json:string></json:object>'));
// ['name' => 'php']
```
2 changes: 1 addition & 1 deletion doc/Denormalizer/CallbackFieldDenormalizer.md
Expand Up @@ -12,7 +12,7 @@ $context = ...;
$fieldDenormalizer = new CallbackFieldDenormalizer(
function (
string $path,
$object,
object $object,
$value,
DenormalizerContextInterface $context,
DenormalizerInterface $denormalizer = null
Expand Down
19 changes: 7 additions & 12 deletions doc/Denormalizer/DenormalizerContext.md
Expand Up @@ -9,23 +9,18 @@ use Psr\Http\Message\ServerRequestInterface;
/** @var ServerRequestInterface $request */
$request = ...;

$context = new DenormalizerContext(['allowed_additional_field'], ['group1'], $request, true, [], true);

echo $context->getAllowedAdditionalFields();
// ['allowed_additional_field']

print_r($context->getGroups());
// ['group1']
$context = new DenormalizerContext($request, ['key' => 'value'], ['allowed_additional_field'], true);

$context->getRequest();
// instanceof ServerRequestInterface

echo $context->isResetMissingFields();
// true

echo $context->isClearMissing();

$context->getAttributes();
$context->getAttribute('name');
$context = $context->withAttribute('name');

echo $context->getAllowedAdditionalFields();
// ['allowed_additional_field']

echo $context->isClearMissing();
// true
```
14 changes: 4 additions & 10 deletions doc/Denormalizer/DenormalizerContextBuilder.md
Expand Up @@ -10,27 +10,21 @@ use Psr\Http\Message\ServerRequestInterface;
$request = ...;

$context = DenormalizerContextBuilder::create()
->setAllowedAdditionalFields(['allowed_additional_field'])
->setGroups(['group1'])
->setRequest($request)
->setResetMissingFields(true) // deprecated
->setAttributes(['key' => 'value'])
->setAllowedAdditionalFields(['allowed_additional_field'])
->setClearMissing(true)
->getContext();

echo $context->getAllowedAdditionalFields();
// ['allowed_additional_field']

print_r($context->getGroups());
// ['group1']

$context->getRequest();
// instanceof ServerRequestInterface

echo $context->isResetMissingFields();
// true

echo $context->isClearMissing();
// true

$context->setAttributes(['key' => 'value']);
echo $context->getAttributes('key');
// value
```
24 changes: 24 additions & 0 deletions doc/Policy/AndPolicy.md
@@ -0,0 +1,24 @@
# AndPolicy

```php
<?php

use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface;
use Chubbyphp\Deserialization\Policy\AndPolicy;
use MyProject\Model\Model;
use MyProject\Policy\AnotherPolicy;
use MyProject\Policy\SomePolicy;

$model = new Model();

/** @var DenormalizerContextInterface $context */
$context = ...;

$policy = new AndPolicy([
new SomePolicy(),
new AnotherPolicy(),
]);

echo $policy->isCompliantIncludingPath('path', $model, $context);
// 1
```
21 changes: 21 additions & 0 deletions doc/Policy/CallbackPolicyIncludingPath.md
@@ -0,0 +1,21 @@
# CallbackPolicyIncludingPath

```php
<?php

use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface;
use Chubbyphp\Deserialization\Policy\CallbackPolicyIncludingPath;
use MyProject\Model\Model;

$model = new Model();

/** @var DenormalizerContextInterface $context */
$context = ...;

$policy = new CallbackPolicyIncludingPath(function (string $path, object $object, DenormalizerContextInterface $context) {
return true;
});

echo $policy->isCompliantIncludingPath('path', $model, $context);
// 1
```
20 changes: 20 additions & 0 deletions doc/Policy/GroupPolicy.md
@@ -0,0 +1,20 @@
# GroupPolicy

```php
<?php

use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface;
use Chubbyphp\Deserialization\Policy\GroupPolicy;
use MyProject\Model\Model;

$model = new Model();

/** @var DenormalizerContextInterface $context */
$context = ...;
$context = $context->withAttribute('groups', ['group1']);

$policy = new GroupPolicy(['group1']);

echo $policy->isCompliantIncludingPath('path', $model, $context);
// 1
```
20 changes: 20 additions & 0 deletions doc/Policy/NotPolicy.md
@@ -0,0 +1,20 @@
# NotPolicy

```php
<?php

use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface;
use Chubbyphp\Deserialization\Policy\NotPolicy;
use MyProject\Model\Model;
use MyProject\Policy\SomePolicy;

$model = new Model();

/** @var DenormalizerContextInterface $context */
$context = ...;

$policy = new NotPolicy(new SomePolicy());

echo $policy->isCompliantIncludingPath('path', $model, $context);
// 1
```
19 changes: 19 additions & 0 deletions doc/Policy/NullPolicy.md
@@ -0,0 +1,19 @@
# NullPolicy

```php
<?php

use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface;
use Chubbyphp\Deserialization\Policy\NullPolicy;
use MyProject\Model\Model;

$model = new Model();

/** @var DenormalizerContextInterface $context */
$context = ...;

$policy = new NullPolicy();

echo $policy->isCompliantIncludingPath('path', $model, $context);
// 1
```

0 comments on commit 4f28ed3

Please sign in to comment.