1 | <?php |
||
14 | class IdiormString |
||
15 | { |
||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $subject; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $search; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $replace; |
||
30 | |||
31 | /** |
||
32 | * Get an easy to use instance of the class |
||
33 | * |
||
34 | * @param string $subject |
||
35 | * |
||
36 | * @return \static |
||
37 | */ |
||
38 | 4 | public static function value($subject) |
|
42 | |||
43 | /** |
||
44 | * Shortcut method: Replace all occurrences of the search string with the replacement |
||
45 | * string where they appear outside quotes. |
||
46 | * |
||
47 | * @param string $search |
||
48 | * @param string $replace |
||
49 | * @param string $subject |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | 4 | public static function str_replace_outside_quotes($search, $replace, $subject) |
|
57 | |||
58 | /** |
||
59 | * Set the base string object |
||
60 | * |
||
61 | * @param string $subject |
||
62 | */ |
||
63 | 4 | public function __construct($subject) |
|
67 | |||
68 | /** |
||
69 | * Replace all occurrences of the search string with the replacement |
||
70 | * string where they appear outside quotes |
||
71 | * |
||
72 | * @param string $search |
||
73 | * @param string $replace |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | 4 | public function replace_outside_quotes($search, $replace) |
|
84 | |||
85 | /** |
||
86 | * Validate an input string and perform a replace on all occurrences |
||
87 | * of $this->search with $this->replace |
||
88 | * |
||
89 | * @author Jeff Roberson <[email protected]> |
||
90 | * @link http://stackoverflow.com/a/13370709/461813 StackOverflow answer |
||
91 | * |
||
92 | * @return string |
||
93 | * |
||
94 | * @throws IdiormStringException |
||
95 | */ |
||
96 | 4 | protected function _str_replace_outside_quotes() |
|
122 | |||
123 | /** |
||
124 | * Process each matching chunk from preg_replace_callback replacing |
||
125 | * each occurrence of $this->search with $this->replace |
||
126 | * |
||
127 | * @author Jeff Roberson <[email protected]> |
||
128 | * @link http://stackoverflow.com/a/13370709/461813 StackOverflow answer |
||
129 | * |
||
130 | * @param array $matches |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | 4 | protected function _str_replace_outside_quotes_cb($matches) |
|
144 | |||
145 | } |
||
146 |