Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite63a99c

Browse files
committed
1 parenta451444 commite63a99c

File tree

12 files changed

+123
-147
lines changed

12 files changed

+123
-147
lines changed

‎src/Symfony/Component/Serializer/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ CHANGELOG
2828
`AbstractNormalizer::setIgnoredAttributes()` are deprecated, use the default context instead.
2929
*`AbstractObjectNormalizer::$maxDepthHandler` and`AbstractObjectNormalizer::setMaxDepthHandler()`
3030
are deprecated, use the default context instead.
31+
* passing configuration options directly to the constructor of`CsvEncoder`,`JsonDecode` and
32+
`XmlEncoder` is deprecated since Symfony 4.2, use the default context instead.
3133

3234
4.1.0
3335
-----

‎src/Symfony/Component/Serializer/Encoder/CsvEncoder.php‎

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,40 @@
2222
class CsvEncoderimplements EncoderInterface, DecoderInterface
2323
{
2424
constFORMAT ='csv';
25+
26+
constAS_COLLECTION_KEY ='as_collection';
2527
constDELIMITER_KEY ='csv_delimiter';
2628
constENCLOSURE_KEY ='csv_enclosure';
2729
constESCAPE_CHAR_KEY ='csv_escape_char';
28-
constKEY_SEPARATOR_KEY ='csv_key_separator';
29-
constHEADERS_KEY ='csv_headers';
3030
constESCAPE_FORMULAS_KEY ='csv_escape_formulas';
31-
constAS_COLLECTION_KEY ='as_collection';
31+
constHEADERS_KEY ='csv_headers';
32+
constKEY_SEPARATOR_KEY ='csv_key_separator';
3233

3334
private$formulasStartCharacters =array('=','-','+','@');
3435
private$defaultContext =array(
3536
self::DELIMITER_KEY =>',',
3637
self::ENCLOSURE_KEY =>'"',
3738
self::ESCAPE_CHAR_KEY =>'\\',
38-
self::KEY_SEPARATOR_KEY =>'.',
3939
self::ESCAPE_FORMULAS_KEY =>false,
40+
self::HEADERS_KEY =>array(),
41+
self::KEY_SEPARATOR_KEY =>'.',
4042
);
4143

4244
/**
43-
* @param array $defaultContext
44-
* @param string $enclosure
45-
* @param string $escapeChar
46-
* @param string $keySeparator
47-
* @param bool $escapeFormulas
45+
* @param array $defaultContext
4846
*/
4947
publicfunction__construct($defaultContext =array(),string$enclosure ='"',string$escapeChar ='\\',string$keySeparator ='.',bool$escapeFormulas =false)
5048
{
5149
if (!\is_array($defaultContext)) {
52-
@trigger_error(sprintf('The "delimiter" parameter is deprecated since Symfony 4.2, use the "%s" key of the context instead.',static::DELIMITER_KEY),E_USER_DEPRECATED);
53-
54-
$defaultContext =array(static::DELIMITER_KEY =>$defaultContext);
55-
}
56-
57-
$args =array(
58-
array('enclosure',static::ENCLOSURE_KEY,'"'),
59-
array('escapeChar',static::ESCAPE_CHAR_KEY,'\\'),
60-
array('keySeparator',static::KEY_SEPARATOR_KEY,'.'),
61-
array('escapeFormulas',static::ESCAPE_FORMULAS_KEY,false),
62-
);
63-
foreach ($argsas$arg) {
64-
$val =${$arg[0]};
65-
if (${$arg[0]} !==$arg[2]) {
66-
$this->defaultContext[$arg[1]] =$val;
67-
@trigger_error(sprintf('The "%s" parameter is deprecated since Symfony 4.2, use the "%s" key of the context instead.',$arg[0],$arg[1]),E_USER_DEPRECATED);
68-
}
50+
@trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.',E_USER_DEPRECATED);
51+
52+
$defaultContext =array(
53+
self::DELIMITER_KEY =>$defaultContext,
54+
self::ENCLOSURE_KEY =>$enclosure,
55+
self::ESCAPE_CHAR_KEY =>$escapeChar,
56+
self::KEY_SEPARATOR_KEY =>$keySeparator,
57+
self::ESCAPE_FORMULAS_KEY =>$escapeFormulas,
58+
);
6959
}
7060

7161
$this->defaultContext =array_merge($this->defaultContext,$defaultContext);
@@ -227,12 +217,12 @@ private function flatten(array $array, array &$result, string $keySeparator, str
227217

228218
privatefunctiongetCsvOptions(array$context):array
229219
{
230-
$delimiter =$context[static::DELIMITER_KEY] ??$this->defaultContext[static::DELIMITER_KEY];
231-
$enclosure =$context[static::ENCLOSURE_KEY] ??$this->defaultContext[static::ENCLOSURE_KEY];
232-
$escapeChar =$context[static::ESCAPE_CHAR_KEY] ??$this->defaultContext[static::ESCAPE_CHAR_KEY];
233-
$keySeparator =$context[static::KEY_SEPARATOR_KEY] ??$this->defaultContext[static::KEY_SEPARATOR_KEY];
234-
$headers =$context[static::HEADERS_KEY] ??$this->defaultContext[static::HEADERS_KEY] ??array();
235-
$escapeFormulas =$context[static::ESCAPE_FORMULAS_KEY] ??$this->defaultContext[static::ESCAPE_FORMULAS_KEY];
220+
$delimiter =$context[self::DELIMITER_KEY] ??$this->defaultContext[self::DELIMITER_KEY];
221+
$enclosure =$context[self::ENCLOSURE_KEY] ??$this->defaultContext[self::ENCLOSURE_KEY];
222+
$escapeChar =$context[self::ESCAPE_CHAR_KEY] ??$this->defaultContext[self::ESCAPE_CHAR_KEY];
223+
$keySeparator =$context[self::KEY_SEPARATOR_KEY] ??$this->defaultContext[self::KEY_SEPARATOR_KEY];
224+
$headers =$context[self::HEADERS_KEY] ??$this->defaultContext[self::HEADERS_KEY];
225+
$escapeFormulas =$context[self::ESCAPE_FORMULAS_KEY] ??$this->defaultContext[self::ESCAPE_FORMULAS_KEY];
236226

237227
if (!\is_array($headers)) {
238228
thrownewInvalidArgumentException(sprintf('The "%s" context variable must be an array or null, given "%s".',self::HEADERS_KEY,\gettype($headers)));

‎src/Symfony/Component/Serializer/Encoder/JsonDecode.php‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ class JsonDecode implements DecoderInterface
2727
*/
2828
constASSOCIATIVE ='json_decode_associative';
2929

30+
constOPTIONS ='json_decode_options';
31+
3032
/**
3133
* Specifies the recursion depth.
3234
*/
3335
constRECURSION_DEPTH ='json_decode_recursion_depth';
3436

35-
constOPTIONS ='json_decode_options';
36-
3737
private$defaultContext =array(
3838
self::ASSOCIATIVE =>false,
39-
self::RECURSION_DEPTH =>512,
4039
self::OPTIONS =>0,
40+
self::RECURSION_DEPTH =>512,
4141
);
4242

4343
/**
@@ -48,11 +48,11 @@ class JsonDecode implements DecoderInterface
4848
publicfunction__construct($defaultContext =array(),int$depth =512)
4949
{
5050
if (!\is_array($defaultContext) ||512 !==$depth) {
51-
@trigger_error(sprintf('Using constructor parameters that are not a default context is deprecated since Symfony 4.2, use the "%s" and "%s" keys of the context instead.',static::ASSOCIATIVE,static::RECURSION_DEPTH),E_USER_DEPRECATED);
51+
@trigger_error(sprintf('Using constructor parameters that are not a default context is deprecated since Symfony 4.2, use the "%s" and "%s" keys of the context instead.',self::ASSOCIATIVE,self::RECURSION_DEPTH),E_USER_DEPRECATED);
5252

5353
$defaultContext =array(
54-
static::ASSOCIATIVE =>$defaultContext,
55-
static::RECURSION_DEPTH =>$depth,
54+
self::ASSOCIATIVE =>$defaultContext,
55+
self::RECURSION_DEPTH =>$depth,
5656
);
5757
}
5858

@@ -88,9 +88,9 @@ public function __construct($defaultContext = array(), int $depth = 512)
8888
*/
8989
publicfunctiondecode($data,$format,array$context =array())
9090
{
91-
$associative =$context[static::ASSOCIATIVE] ??$this->defaultContext[static::ASSOCIATIVE];
92-
$recursionDepth =$context[static::RECURSION_DEPTH] ??$this->defaultContext[static::RECURSION_DEPTH];
93-
$options =$context[static::OPTIONS] ??$this->defaultContext[static::OPTIONS];
91+
$associative =$context[self::ASSOCIATIVE] ??$this->defaultContext[self::ASSOCIATIVE];
92+
$recursionDepth =$context[self::RECURSION_DEPTH] ??$this->defaultContext[self::RECURSION_DEPTH];
93+
$options =$context[self::OPTIONS] ??$this->defaultContext[self::OPTIONS];
9494

9595
$decodedData =json_decode($data,$associative,$recursionDepth,$options);
9696

‎src/Symfony/Component/Serializer/Encoder/JsonEncode.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct($defaultContext = array())
3434
if (\is_int($defaultContext)) {
3535
@trigger_error(sprintf('Passing an integer as first parameter of the "%s()" method is deprecated since Symfony 4.2, use the "json_encode_options" key of the context instead.',__METHOD__),E_USER_DEPRECATED);
3636

37-
$this->defaultContext[static::JSON_ENCODE_OPTIONS] =$defaultContext;
37+
$this->defaultContext[self::JSON_ENCODE_OPTIONS] =$defaultContext;
3838
}else {
3939
$this->defaultContext =array_merge($this->defaultContext,$defaultContext);
4040
}
@@ -47,7 +47,7 @@ public function __construct($defaultContext = array())
4747
*/
4848
publicfunctionencode($data,$format,array$context =array())
4949
{
50-
$jsonEncodeOptions =$context[static::JSON_ENCODE_OPTIONS] ??$this->defaultContext[static::JSON_ENCODE_OPTIONS];
50+
$jsonEncodeOptions =$context[self::JSON_ENCODE_OPTIONS] ??$this->defaultContext[self::JSON_ENCODE_OPTIONS];
5151
$encodedJson =json_encode($data,$jsonEncodeOptions);
5252

5353
if (JSON_ERROR_NONE !==json_last_error() && (false ===$encodedJson || !($jsonEncodeOptions &JSON_PARTIAL_OUTPUT_ON_ERROR))) {

‎src/Symfony/Component/Serializer/Encoder/XmlEncoder.php‎

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
3030

3131
constFORMAT ='xml';
3232

33-
// context options
3433
constAS_COLLECTION ='as_collection';
3534

3635
/**
@@ -70,32 +69,24 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
7069
publicfunction__construct($defaultContext =array(),int$loadOptions =null,array$decoderIgnoredNodeTypes =array(XML_PI_NODE,XML_COMMENT_NODE),array$encoderIgnoredNodeTypes =array())
7170
{
7271
$this->defaultContext =array(
73-
static::AS_COLLECTION =>false,
74-
static::DECODER_IGNORED_NODE_TYPES =>array(XML_PI_NODE,XML_COMMENT_NODE),
75-
static::ENCODER_IGNORED_NODE_TYPES =>array(),
76-
static::LOAD_OPTIONS =>LIBXML_NONET |LIBXML_NOBLANKS,
77-
static::REMOVE_EMPTY_TAGS =>false,
78-
static::ROOT_NODE_NAME =>'response',
79-
static::TYPE_CASE_ATTRIBUTES =>true,
72+
self::AS_COLLECTION =>false,
73+
self::DECODER_IGNORED_NODE_TYPES =>array(XML_PI_NODE,XML_COMMENT_NODE),
74+
self::ENCODER_IGNORED_NODE_TYPES =>array(),
75+
self::LOAD_OPTIONS =>LIBXML_NONET |LIBXML_NOBLANKS,
76+
self::REMOVE_EMPTY_TAGS =>false,
77+
self::ROOT_NODE_NAME =>'response',
78+
self::TYPE_CASE_ATTRIBUTES =>true,
8079
);
8180

8281
if (!\is_array($defaultContext)) {
83-
@trigger_error(sprintf('The "rootNodeName" parameter is deprecated since Symfony 4.2, use the "%s" key of the context instead.',static::ROOT_NODE_NAME),E_USER_DEPRECATED);
84-
85-
$defaultContext =array(static::ROOT_NODE_NAME =>$defaultContext);
86-
}
87-
88-
$args =array(
89-
array('loadOptions',static::LOAD_OPTIONS,null),
90-
array('decoderIgnoredNodeTypes',static::DECODER_IGNORED_NODE_TYPES,$this->defaultContext[static::DECODER_IGNORED_NODE_TYPES]),
91-
array('encoderIgnoredNodeTypes',static::ENCODER_IGNORED_NODE_TYPES,$this->defaultContext[static::ENCODER_IGNORED_NODE_TYPES]),
92-
);
93-
foreach ($argsas$arg) {
94-
$val =${$arg[0]};
95-
if (${$arg[0]} !==$arg[2]) {
96-
$this->defaultContext[$arg[1]] =$val;
97-
@trigger_error(sprintf('The "%s" parameter is deprecated since Symfony 4.2, use the "%s" key of the context instead.',$arg[0],$arg[1]),E_USER_DEPRECATED);
98-
}
82+
@trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.',E_USER_DEPRECATED);
83+
84+
$defaultContext =array(
85+
self::DECODER_IGNORED_NODE_TYPES =>$decoderIgnoredNodeTypes,
86+
self::ENCODER_IGNORED_NODE_TYPES =>$encoderIgnoredNodeTypes,
87+
self::LOAD_OPTIONS =>$loadOptions ??LIBXML_NONET |LIBXML_NOBLANKS,
88+
self::ROOT_NODE_NAME =>$defaultContext,
89+
);
9990
}
10091

10192
$this->defaultContext =array_merge($this->defaultContext,$defaultContext);
@@ -106,13 +97,13 @@ public function __construct($defaultContext = array(), int $loadOptions = null,
10697
*/
10798
publicfunctionencode($data,$format,array$context =array())
10899
{
109-
$encoderIgnoredNodeTypes =$context[static::ENCODER_IGNORED_NODE_TYPES] ??$this->defaultContext[static::ENCODER_IGNORED_NODE_TYPES];
100+
$encoderIgnoredNodeTypes =$context[self::ENCODER_IGNORED_NODE_TYPES] ??$this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
110101
$ignorePiNode =\in_array(XML_PI_NODE,$encoderIgnoredNodeTypes,true);
111102
if ($datainstanceof \DOMDocument) {
112103
return$data->saveXML($ignorePiNode ?$data->documentElement :null);
113104
}
114105

115-
$xmlRootNodeName =$context[static::ROOT_NODE_NAME] ??$this->defaultContext[static::ROOT_NODE_NAME];
106+
$xmlRootNodeName =$context[self::ROOT_NODE_NAME] ??$this->defaultContext[self::ROOT_NODE_NAME];
116107

117108
$this->dom =$this->createDomDocument($context);
118109
$this->format =$format;
@@ -143,7 +134,7 @@ public function decode($data, $format, array $context = array())
143134
libxml_clear_errors();
144135

145136
$dom =new \DOMDocument();
146-
$dom->loadXML($data,$context[static::LOAD_OPTIONS] ??$this->defaultContext[static::LOAD_OPTIONS]);
137+
$dom->loadXML($data,$context[self::LOAD_OPTIONS] ??$this->defaultContext[self::LOAD_OPTIONS]);
147138

148139
libxml_use_internal_errors($internalErrors);
149140
libxml_disable_entity_loader($disableEntities);
@@ -155,7 +146,7 @@ public function decode($data, $format, array $context = array())
155146
}
156147

157148
$rootNode =null;
158-
$decoderIgnoredNodeTypes =$context[static::DECODER_IGNORED_NODE_TYPES] ??$this->defaultContext[static::DECODER_IGNORED_NODE_TYPES];
149+
$decoderIgnoredNodeTypes =$context[self::DECODER_IGNORED_NODE_TYPES] ??$this->defaultContext[self::DECODER_IGNORED_NODE_TYPES];
159150
foreach ($dom->childNodesas$child) {
160151
if (XML_DOCUMENT_TYPE_NODE ===$child->nodeType) {
161152
thrownewNotEncodableValueException('Document types are not allowed.');
@@ -221,7 +212,7 @@ public function supportsDecoding($format)
221212
*/
222213
publicfunctionsetRootNodeName($name)
223214
{
224-
$this->defaultContext[static::ROOT_NODE_NAME] =$name;
215+
$this->defaultContext[self::ROOT_NODE_NAME] =$name;
225216
}
226217

227218
/**
@@ -231,7 +222,7 @@ public function setRootNodeName($name)
231222
*/
232223
publicfunctiongetRootNodeName()
233224
{
234-
return$this->defaultContext[static::ROOT_NODE_NAME];
225+
return$this->defaultContext[self::ROOT_NODE_NAME];
235226
}
236227

237228
finalprotectedfunctionappendXMLString(\DOMNode$node,string$val):bool
@@ -339,7 +330,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = array()): a
339330
}
340331

341332
$data =array();
342-
$typeCastAttributes = (bool) ($context[static::TYPE_CASE_ATTRIBUTES] ??$this->defaultContext[static::TYPE_CASE_ATTRIBUTES]);
333+
$typeCastAttributes = (bool) ($context[self::TYPE_CASE_ATTRIBUTES] ??$this->defaultContext[self::TYPE_CASE_ATTRIBUTES]);
343334

344335
foreach ($node->attributesas$attr) {
345336
if (!is_numeric($attr->nodeValue) || !$typeCastAttributes) {
@@ -376,7 +367,7 @@ private function parseXmlValue(\DOMNode $node, array $context = array())
376367
}
377368

378369
$value =array();
379-
$decoderIgnoredNodeTypes =$context[static::DECODER_IGNORED_NODE_TYPES] ??$this->defaultContext[static::DECODER_IGNORED_NODE_TYPES];
370+
$decoderIgnoredNodeTypes =$context[self::DECODER_IGNORED_NODE_TYPES] ??$this->defaultContext[self::DECODER_IGNORED_NODE_TYPES];
380371
foreach ($node->childNodesas$subnode) {
381372
if (\in_array($subnode->nodeType,$decoderIgnoredNodeTypes,true)) {
382373
continue;
@@ -395,7 +386,7 @@ private function parseXmlValue(\DOMNode $node, array $context = array())
395386
}
396387
}
397388

398-
$asCollection =$context[static::AS_COLLECTION] ??$this->defaultContext[static::AS_COLLECTION];
389+
$asCollection =$context[self::AS_COLLECTION] ??$this->defaultContext[self::AS_COLLECTION];
399390
foreach ($valueas$key =>$val) {
400391
if (!$asCollection &&\is_array($val) &&1 ===\count($val)) {
401392
$value[$key] =current($val);
@@ -415,8 +406,8 @@ private function parseXmlValue(\DOMNode $node, array $context = array())
415406
privatefunctionbuildXml(\DOMNode$parentNode,$data,string$xmlRootNodeName =null):bool
416407
{
417408
$append =true;
418-
$removeEmptyTags =$this->context[static::REMOVE_EMPTY_TAGS] ??$this->defaultContext[static::REMOVE_EMPTY_TAGS] ??false;
419-
$encoderIgnoredNodeTypes =$this->context[static::ENCODER_IGNORED_NODE_TYPES] ??$this->defaultContext[static::ENCODER_IGNORED_NODE_TYPES];
409+
$removeEmptyTags =$this->context[self::REMOVE_EMPTY_TAGS] ??$this->defaultContext[self::REMOVE_EMPTY_TAGS] ??false;
410+
$encoderIgnoredNodeTypes =$this->context[self::ENCODER_IGNORED_NODE_TYPES] ??$this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
420411

421412
if (\is_array($data) || ($datainstanceof \Traversable && !$this->serializer->supportsNormalization($data,$this->format))) {
422413
foreach ($dataas$key =>$data) {
@@ -548,16 +539,16 @@ private function createDomDocument(array $context): \DOMDocument
548539
// Set an attribute on the DOM document specifying, as part of the XML declaration,
549540
$xmlOptions =array(
550541
// nicely formats output with indentation and extra space
551-
static::FORMAT_OUTPUT =>'formatOutput',
542+
self::FORMAT_OUTPUT =>'formatOutput',
552543
// the version number of the document
553-
static::VERSION =>'xmlVersion',
544+
self::VERSION =>'xmlVersion',
554545
// the encoding of the document
555-
static::ENCODING =>'encoding',
546+
self::ENCODING =>'encoding',
556547
// whether the document is standalone
557-
static::STANDALONE =>'xmlStandalone',
548+
self::STANDALONE =>'xmlStandalone',
558549
);
559550
foreach ($xmlOptionsas$xmlOption =>$documentProperty) {
560-
if ($contextOption =($context[$xmlOption] ??$this->defaultContext[$xmlOption] ??false)) {
551+
if ($contextOption =$context[$xmlOption] ??$this->defaultContext[$xmlOption] ??false) {
561552
$document->$documentProperty =$contextOption;
562553
}
563554
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp