File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 99 */
1010class MissingConfigException extends ConfigException
1111{
12- /** @var string */
12+ /** @var string|null */
1313 protected $ needKey ;
1414
1515 /**
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