@@ -100,4 +100,76 @@ public function getItemSubject()
100100 {
101101 return $ this ->itemSubject ;
102102 }
103+
104+ /**
105+ * Get data using dot notation.
106+ *
107+ * @param string $path Dot notation path (e.g., 'user.profile.name')
108+ * @param mixed $default Default value if path doesn't exist
109+ *
110+ * @return mixed
111+ */
112+ public function getDotData ($ path , $ default = null )
113+ {
114+ $ keys = explode ('. ' , $ path );
115+ $ current = $ this ->data ;
116+
117+ // Navigate through the path
118+ foreach ($ keys as $ key ) {
119+ // Handle numeric keys for arrays
120+ if (is_numeric ($ key )) {
121+ $ key = (int ) $ key ;
122+ }
123+
124+ if (!isset ($ current [$ key ])) {
125+ return $ default ;
126+ }
127+
128+ $ current = $ current [$ key ];
129+ }
130+
131+ return $ current ;
132+ }
133+
134+ /**
135+ * Set data using dot notation.
136+ *
137+ * @param string $path Dot notation path (e.g., 'user.profile.name')
138+ * @param mixed $value Value to set
139+ *
140+ * @return $this
141+ */
142+ public function setDotData ($ path , $ value )
143+ {
144+ $ keys = explode ('. ' , $ path );
145+ $ firstKey = $ keys [0 ];
146+ $ current = &$ this ->data ;
147+
148+ // Navigate to the parent of the target key
149+ for ($ i = 0 ; $ i < count ($ keys ) - 1 ; $ i ++) {
150+ $ key = $ keys [$ i ];
151+
152+ // Handle numeric keys for arrays
153+ if (is_numeric ($ key )) {
154+ $ key = (int ) $ key ;
155+ }
156+
157+ if (!isset ($ current [$ key ]) || !is_array ($ current [$ key ])) {
158+ $ current [$ key ] = [];
159+ }
160+ $ current = &$ current [$ key ];
161+ }
162+
163+ // Set the final value
164+ $ finalKey = $ keys [count ($ keys ) - 1 ];
165+ if (is_numeric ($ finalKey )) {
166+ $ finalKey = (int ) $ finalKey ;
167+ }
168+
169+ $ current [$ finalKey ] = $ value ;
170+ // Keep compatibility with putData method (required by PM Core)
171+ $ this ->putData ($ firstKey , $ this ->data [$ firstKey ]);
172+
173+ return $ this ;
174+ }
103175}
0 commit comments