@@ -505,16 +505,7 @@ private function addIndex(ClassMetadata $class, SimpleXMLElement $xmlIndex): voi
505505
506506 if (isset ($ xmlIndex ->{'option ' })) {
507507 foreach ($ xmlIndex ->{'option ' } as $ option ) {
508- $ value = (string ) $ option ['value ' ];
509- if ($ value === 'true ' ) {
510- $ value = true ;
511- } elseif ($ value === 'false ' ) {
512- $ value = false ;
513- } elseif (is_numeric ($ value )) {
514- $ value = preg_match ('/^[-]?\d+$/ ' , $ value ) ? (int ) $ value : (float ) $ value ;
515- }
516-
517- $ options [(string ) $ option ['name ' ]] = $ value ;
508+ $ options [(string ) $ option ['name ' ]] = $ this ->convertXMLElementValue ((string ) $ option ['value ' ]);
518509 }
519510 }
520511
@@ -564,15 +555,7 @@ private function getPartialFilterExpression(SimpleXMLElement $fields): array
564555
565556 $ value = $ nestedExpression ;
566557 } else {
567- $ value = trim ((string ) $ field ['value ' ]);
568- }
569-
570- if ($ value === 'true ' ) {
571- $ value = true ;
572- } elseif ($ value === 'false ' ) {
573- $ value = false ;
574- } elseif (is_numeric ($ value )) {
575- $ value = preg_match ('/^[-]?\d+$/ ' , $ value ) ? (int ) $ value : (float ) $ value ;
558+ $ value = $ this ->convertXMLElementValue ((string ) $ field ['value ' ]);
576559 }
577560
578561 $ partialFilterExpression [(string ) $ field ['name ' ]] = $ operator ? ['$ ' . $ operator => $ value ] : $ value ;
@@ -581,6 +564,37 @@ private function getPartialFilterExpression(SimpleXMLElement $fields): array
581564 return $ partialFilterExpression ;
582565 }
583566
567+ /**
568+ * Converts XML strings to scalar values.
569+ *
570+ * Special strings "false", "true", and "null" are converted to their
571+ * respective values. Numeric strings are cast to int or float depending on
572+ * whether they contain decimal separators or not.
573+ *
574+ * @return scalar|null
575+ */
576+ private function convertXMLElementValue (string $ value )
577+ {
578+ $ value = trim ($ value );
579+
580+ switch ($ value ) {
581+ case 'true ' :
582+ return true ;
583+
584+ case 'false ' :
585+ return false ;
586+
587+ case 'null ' :
588+ return null ;
589+ }
590+
591+ if (! is_numeric ($ value )) {
592+ return $ value ;
593+ }
594+
595+ return preg_match ('/^[-]?\d+$/ ' , $ value ) ? (int ) $ value : (float ) $ value ;
596+ }
597+
584598 private function setShardKey (ClassMetadata $ class , SimpleXMLElement $ xmlShardkey ): void
585599 {
586600 $ attributes = $ xmlShardkey ->attributes ();
@@ -601,16 +615,7 @@ private function setShardKey(ClassMetadata $class, SimpleXMLElement $xmlShardkey
601615
602616 if (isset ($ xmlShardkey ->{'option ' })) {
603617 foreach ($ xmlShardkey ->{'option ' } as $ option ) {
604- $ value = (string ) $ option ['value ' ];
605- if ($ value === 'true ' ) {
606- $ value = true ;
607- } elseif ($ value === 'false ' ) {
608- $ value = false ;
609- } elseif (is_numeric ($ value )) {
610- $ value = preg_match ('/^[-]?\d+$/ ' , $ value ) ? (int ) $ value : (float ) $ value ;
611- }
612-
613- $ options [(string ) $ option ['name ' ]] = $ value ;
618+ $ options [(string ) $ option ['name ' ]] = $ this ->convertXMLElementValue ((string ) $ option ['value ' ]);
614619 }
615620 }
616621
0 commit comments