Skip to content

Commit 2b21d84

Browse files
authored
Json converter removal (#159)
* JsonConverter and concrete class marked as deprecated * New internal JSON converter
1 parent d4ebc03 commit 2b21d84

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

src/Bundle/JoseFramework/DependencyInjection/Configuration.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public function getConfigTreeBuilder()
5151

5252
return $treeBuilder;
5353
}
54-
55-
private function getRootNode(TreeBuilder $treeBuilder, $name)
56-
{
57-
// BC layer for symfony/config 4.1 and older
58-
if (! \method_exists($treeBuilder, 'getRootNode')) {
59-
return $treeBuilder->root($name);
60-
}
6154

62-
return $treeBuilder->getRootNode();
63-
}
55+
private function getRootNode(TreeBuilder $treeBuilder, $name)
56+
{
57+
// BC layer for symfony/config 4.1 and older
58+
if (!\method_exists($treeBuilder, 'getRootNode')) {
59+
return $treeBuilder->root($name);
60+
}
61+
62+
return $treeBuilder->getRootNode();
63+
}
6464
}

src/Bundle/JoseFramework/Serializer/JWEEncoder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public function encode($data, $format, array $context = [])
5454
return $this->serializerManager->serialize(mb_strtolower($format), $data, $this->getRecipientIndex($context));
5555
} catch (\Exception $ex) {
5656
$message = sprintf('Cannot encode JWE to %s format.', $format);
57-
57+
5858
if (\class_exists('Symfony\Component\Serializer\Exception\NotEncodableValueException')) {
5959
throw new NotEncodableValueException($message, 0, $ex);
6060
}
61-
61+
6262
throw new UnexpectedValueException($message, 0, $ex);
6363
}
6464
}
@@ -67,13 +67,13 @@ public function decode($data, $format, array $context = [])
6767
{
6868
try {
6969
return $this->serializerManager->unserialize($data);
70-
} catch (\Exception $ex) {
70+
} catch (\Exception $ex) {
7171
$message = sprintf('Cannot decode JWE from %s format.', $format);
72-
72+
7373
if (\class_exists('Symfony\Component\Serializer\Exception\NotEncodableValueException')) {
7474
throw new NotEncodableValueException($message, 0, $ex);
7575
}
76-
76+
7777
throw new UnexpectedValueException($message, 0, $ex);
7878
}
7979
}

src/Component/Core/Converter/JsonConverter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Jose\Component\Core\Converter;
1515

16+
/**
17+
* @deprecated This interface is deprecated in v1.3 and will be removed in v2.0
18+
*/
1619
interface JsonConverter
1720
{
1821
/**

src/Component/Core/Converter/StandardConverter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Jose\Component\Core\Converter;
1515

16+
/**
17+
* @deprecated This class is deprecated in v1.3 and will be removed in v2.0
18+
*/
1619
final class StandardConverter implements JsonConverter
1720
{
1821
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2018 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Jose\Component\Core\Util;
15+
16+
final class JsonConverter
17+
{
18+
public static function encode($payload): string
19+
{
20+
return \json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
21+
}
22+
23+
public static function decode(string $payload)
24+
{
25+
return \json_decode($payload, true, 512, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
26+
}
27+
}

0 commit comments

Comments
 (0)