@@ -44,6 +44,12 @@ public function encode($value, $depth, array $options, callable $encode)
44
44
return $ this ->getSingleQuotedString ($ value );
45
45
}
46
46
47
+ /**
48
+ * Tests if the given value is a string that could be encoded as a class name constant.
49
+ * @param string $value The string to test
50
+ * @param array $options The string encoding options
51
+ * @return bool True if string can be encoded as class constant, false if not
52
+ */
47
53
private function isClassName ($ value , array $ options )
48
54
{
49
55
if (preg_match ('/^([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)( \\\\(?1))*$/ ' , $ value ) !== 1 ) {
@@ -53,6 +59,12 @@ private function isClassName($value, array $options)
53
59
return array_intersect (iterator_to_array ($ this ->iterateNamespaces ($ value )), $ options ['string.classes ' ]) !== [];
54
60
}
55
61
62
+ /**
63
+ * Encodes the given string as a class name constant based on used imports.
64
+ * @param string $value The string to encode
65
+ * @param array $options The string encoding options
66
+ * @return string The class constant PHP code representation
67
+ */
56
68
private function getClassName ($ value , array $ options )
57
69
{
58
70
foreach ($ this ->iterateNamespaces ($ value ) as $ partial ) {
@@ -65,6 +77,11 @@ private function getClassName($value, array $options)
65
77
return sprintf ('\\%s::class ' , $ value );
66
78
}
67
79
80
+ /**
81
+ * Iterates over the variations of the namespace for the given class name.
82
+ * @param string $value The class name to iterate over
83
+ * @return \Generator|string[] The namespace parts of the string
84
+ */
68
85
private function iterateNamespaces ($ value )
69
86
{
70
87
yield $ value ;
@@ -77,6 +94,12 @@ private function iterateNamespaces($value)
77
94
}
78
95
}
79
96
97
+ /**
98
+ * Returns the PHP code representation for the string that is not just simple ascii characters.
99
+ * @param string $value The string to encode
100
+ * @param array $options The string encoding options
101
+ * @return string The PHP code representation for the complex string
102
+ */
80
103
private function getComplexString ($ value , array $ options )
81
104
{
82
105
if ($ this ->isBinaryString ($ value , $ options )) {
0 commit comments