| 
5 | 5 |  *  | 
6 | 6 |  * @author  Riku Särkinen <riku@adbar.io>  | 
7 | 7 |  * @link    https://github.com/adbario/php-dot-notation  | 
8 |  | - * @license https://github.com/adbario/php-dot-notation/blob/2.x/LICENSE.md (MIT License)  | 
 | 8 | + * @license https://github.com/adbario/php-dot-notation/blob/3.x/LICENSE.md (MIT License)  | 
9 | 9 |  */  | 
10 | 10 | 
 
  | 
11 | 11 | namespace Adbar;  | 
@@ -36,19 +36,29 @@ class Dot implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable  | 
36 | 36 |      *  | 
37 | 37 |      * @var array<TKey, TValue>  | 
38 | 38 |      */  | 
39 |  | -    protected $items = [];  | 
 | 39 | +    protected $items;  | 
 | 40 | + | 
 | 41 | +    /**  | 
 | 42 | +     * The character to use as a delimiter, defaults to dot (.)  | 
 | 43 | +     *  | 
 | 44 | +     * @var non-empty-string  | 
 | 45 | +     */  | 
 | 46 | +    protected $delimiter = ".";  | 
40 | 47 | 
 
  | 
41 | 48 |     /**  | 
42 | 49 |      * Create a new Dot instance  | 
43 | 50 |      *  | 
44 | 51 |      * @param  mixed  $items  | 
45 | 52 |      * @param  bool  $parse  | 
 | 53 | +     * @param  non-empty-string  $delimiter  | 
46 | 54 |      * @return void  | 
47 | 55 |      */  | 
48 |  | -    public function __construct($items = [], $parse = false)  | 
 | 56 | +    public function __construct($items = [], $parse = false, $delimiter = ".")  | 
49 | 57 |     {  | 
50 | 58 |         $items = $this->getArrayItems($items);  | 
51 | 59 | 
 
  | 
 | 60 | +        $this->delimiter = $delimiter ?: ".";  | 
 | 61 | + | 
52 | 62 |         if ($parse) {  | 
53 | 63 |             $this->set($items);  | 
54 | 64 |         } else {  | 
@@ -128,7 +138,7 @@ public function delete($keys)  | 
128 | 138 |             }  | 
129 | 139 | 
 
  | 
130 | 140 |             $items = &$this->items;  | 
131 |  | -            $segments = explode('.', $key);  | 
 | 141 | +            $segments = explode($this->delimiter, $key);  | 
132 | 142 |             $lastSegment = array_pop($segments);  | 
133 | 143 | 
 
  | 
134 | 144 |             foreach ($segments as $segment) {  | 
@@ -201,13 +211,13 @@ public function get($key = null, $default = null)  | 
201 | 211 |             return $this->items[$key];  | 
202 | 212 |         }  | 
203 | 213 | 
 
  | 
204 |  | -        if (!is_string($key) || strpos($key, '.') === false) {  | 
 | 214 | +        if (!is_string($key) || strpos($key, $this->delimiter) === false) {  | 
205 | 215 |             return $default;  | 
206 | 216 |         }  | 
207 | 217 | 
 
  | 
208 | 218 |         $items = $this->items;  | 
209 | 219 | 
 
  | 
210 |  | -        foreach (explode('.', $key) as $segment) {  | 
 | 220 | +        foreach (explode($this->delimiter, $key) as $segment) {  | 
211 | 221 |             if (!is_array($items) || !$this->exists($items, $segment)) {  | 
212 | 222 |                 return $default;  | 
213 | 223 |             }  | 
@@ -258,7 +268,7 @@ public function has($keys)  | 
258 | 268 |                 continue;  | 
259 | 269 |             }  | 
260 | 270 | 
 
  | 
261 |  | -            foreach (explode('.', $key) as $segment) {  | 
 | 271 | +            foreach (explode($this->delimiter, $key) as $segment) {  | 
262 | 272 |                 if (!is_array($items) || !$this->exists($items, $segment)) {  | 
263 | 273 |                     return false;  | 
264 | 274 |                 }  | 
@@ -487,7 +497,7 @@ public function set($keys, $value = null)  | 
487 | 497 |         $items = &$this->items;  | 
488 | 498 | 
 
  | 
489 | 499 |         if (is_string($keys)) {  | 
490 |  | -            foreach (explode('.', $keys) as $key) {  | 
 | 500 | +            foreach (explode($this->delimiter, $keys) as $key) {  | 
491 | 501 |                 if (!isset($items[$key]) || !is_array($items[$key])) {  | 
492 | 502 |                     $items[$key] = [];  | 
493 | 503 |                 }  | 
 | 
0 commit comments