File tree 3 files changed +57
-1
lines changed
3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 9
9
*/
10
10
class MissingConfigException extends ConfigException
11
11
{
12
- /** @var string */
12
+ /** @var string|null */
13
13
protected $ needKey ;
14
14
15
15
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Php \Support \Helpers ;
4
+
5
+ /**
6
+ * Class Arr
7
+ *
8
+ * @package Php\Support\Helpers
9
+ */
10
+ class Arr
11
+ {
12
+ /**
13
+ * Replace templates into array
14
+ * Key = search value
15
+ * Value = replace value
16
+ *
17
+ * @param array $array
18
+ * @param array $replace
19
+ */
20
+ public static function arrayReplaceByTemplate (array &$ array , array $ replace )
21
+ {
22
+ foreach ($ array as &$ item ) {
23
+ if (is_array ($ item )) {
24
+ self ::arrayReplaceByTemplate ($ item , $ replace );
25
+ } else if (is_string ($ item )) {
26
+ $ item = Str::stringReplaceByTemplate ($ item , $ replace );
27
+ }
28
+ }
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Php \Support \Helpers ;
4
+
5
+ /**
6
+ * Class Str
7
+ *
8
+ * @package Php\Support\Helpers
9
+ */
10
+ class Str
11
+ {
12
+ /**
13
+ * Replace templates into string
14
+ * Key = search value
15
+ * Value = replace value
16
+ *
17
+ * @param string $str
18
+ * @param array $replace
19
+ *
20
+ * @return mixed
21
+ */
22
+ public static function stringReplaceByTemplate (string $ str , array $ replace )
23
+ {
24
+ return str_replace (array_keys ($ replace ), array_values ($ replace ), $ str );
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments