File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ public function mapRawData(array $data)
133133 continue ;
134134 }
135135
136- if (!array_key_exists ( $ field , $ this ->map )) {
136+ if (!$ this ->isFieldKnown ( $ field )) {
137137 // silently ignore unknown fields
138138 continue ;
139139 }
@@ -214,6 +214,33 @@ protected function isSection($field)
214214 return (in_array ($ field , $ this ->sections ));
215215 }
216216
217+ /**
218+ * Determines if the given field is known,
219+ * in a case insensitive way for its first letter.
220+ * Also update $field to keep it valid against the known fields.
221+ *
222+ * @param string &$field
223+ * @return bool
224+ */
225+ protected function isFieldKnown (&$ field )
226+ {
227+ $ lcfField = lcfirst ($ field );
228+ if (array_key_exists ($ lcfField , $ this ->map )) {
229+ $ field = $ lcfField ;
230+
231+ return true ;
232+ }
233+
234+ $ ucfField = ucfirst ($ field );
235+ if (array_key_exists ($ ucfField , $ this ->map )) {
236+ $ field = $ ucfField ;
237+
238+ return true ;
239+ }
240+
241+ return false ;
242+ }
243+
217244 /**
218245 * Extract GPS coordinates from components array
219246 *
Original file line number Diff line number Diff line change @@ -191,6 +191,27 @@ public function testMapRawDataFlattensRawDataWithSections()
191191 $ this ->assertEquals ($ expected , $ keys );
192192 }
193193
194+ /**
195+ * @group mapper
196+ * @covers \PHPExif\Mapper\Native::mapRawData
197+ */
198+ public function testMapRawDataMacthesFieldsWithoutCaseSensibilityOnFirstLetter ()
199+ {
200+ $ rawData = array (
201+ \PHPExif \Mapper \Native::ORIENTATION => 'Portrait ' ,
202+ 'Copyright ' => 'Acme ' ,
203+ );
204+ $ mapped = $ this ->mapper ->mapRawData ($ rawData );
205+ $ this ->assertCount (2 , $ mapped );
206+ $ keys = array_keys ($ mapped );
207+
208+ $ expected = array (
209+ \PHPExif \Mapper \Native::ORIENTATION ,
210+ \PHPExif \Mapper \Native::COPYRIGHT
211+ );
212+ $ this ->assertEquals ($ expected , $ keys );
213+ }
214+
194215 /**
195216 * @group mapper
196217 * @covers \PHPExif\Mapper\Native::mapRawData
You can’t perform that action at this time.
0 commit comments