1 | <?php |
||
5 | class Parser |
||
6 | { |
||
7 | private $iptclabels = [ |
||
8 | '1#000' => 'Model Version', |
||
9 | '1#005' => 'Destination', |
||
10 | '1#020' => 'File Format', |
||
11 | '1#022' => 'File Format Version', |
||
12 | '1#030' => 'Service Identifier', |
||
13 | '1#040' => 'Envelope Number', |
||
14 | '1#050' => 'Product I.D.', |
||
15 | '1#060' => 'Envelope Priority', |
||
16 | '1#070' => 'Date Sent', |
||
17 | '1#080' => 'Time Sent', |
||
18 | '1#090' => 'Coded Character Set', |
||
19 | '1#100' => 'UNO', |
||
20 | '1#120' => 'ARM Identifier', |
||
21 | '1#122' => 'ARM Version', |
||
22 | '2#000' => 'Record Version', |
||
23 | '2#003' => 'Object Type Reference', |
||
24 | '2#004' => 'Object Attribute Reference', |
||
25 | '2#005' => 'Object Name', |
||
26 | '2#007' => 'Edit Status', |
||
27 | '2#008' => 'EditorialUpdate', |
||
28 | '2#010' => 'Urgency', |
||
29 | '2#012' => 'Subject Reference', |
||
30 | '2#015' => 'Category', |
||
31 | '2#020' => 'Supplemental Category', |
||
32 | '2#022' => 'Fixture Identifier', |
||
33 | '2#025' => 'Keywords', |
||
34 | '2#026' => 'Content Location Code', |
||
35 | '2#027' => 'Content Location Name', |
||
36 | '2#030' => 'Release Date', |
||
37 | '2#035' => 'Release Time', |
||
38 | '2#037' => 'ExpirationDate', |
||
39 | '2#038' => 'Expiration Time', |
||
40 | '2#040' => 'Special Instructions', |
||
41 | '2#042' => 'Action Advised', |
||
42 | '2#045' => 'Reference Service', |
||
43 | '2#047' => 'Reference Date', |
||
44 | '2#050' => 'Reference Number', |
||
45 | '2#055' => 'Date Created', |
||
46 | '2#060' => 'Time Created', |
||
47 | '2#062' => 'Digital Creation Date', |
||
48 | '2#063' => 'Digital Creation Time', |
||
49 | '2#065' => 'Originating Program', |
||
50 | '2#070' => 'Program Version', |
||
51 | '2#075' => 'Object Cycle', |
||
52 | '2#080' => 'By-line', |
||
53 | '2#085' => 'By-line Title', |
||
54 | '2#090' => 'City', |
||
55 | '2#092' => 'Sublocation', |
||
56 | '2#095' => 'Province/State', |
||
57 | '2#100' => 'Country/Primary Location Code', |
||
58 | '2#101' => 'Country/Primary Location Name', |
||
59 | '2#103' => 'Original Transmission Reference', |
||
60 | '2#105' => 'Headline', |
||
61 | '2#110' => 'Credit', |
||
62 | '2#115' => 'Source', |
||
63 | '2#116' => 'Copyright Notice', |
||
64 | '2#118' => 'Contact', |
||
65 | '2#120' => 'Caption/Abstract', |
||
66 | '2#122' => 'Writer/Editor', |
||
67 | '2#125' => 'Rasterized Caption', |
||
68 | '2#130' => 'Image Type', |
||
69 | '2#131' => 'Image Orientation', |
||
70 | '2#135' => 'Language Identifier', |
||
71 | '2#150' => 'Audio Type', |
||
72 | '2#151' => 'Audio SamplingRate', |
||
73 | '2#152' => 'Audio Sampling Resolution', |
||
74 | '2#153' => 'Audio Duration', |
||
75 | '2#154' => 'Audio Outcue', |
||
76 | '2#200' => 'ObjectData Preview File Format', |
||
77 | '2#201' => 'ObjectData Preview File Format Version', |
||
78 | '2#202' => 'ObjectData Preview Data' |
||
79 | ]; |
||
80 | |||
81 | private $metadata = array( |
||
82 | 'exif' => null, |
||
83 | 'iptc' => null, |
||
84 | 'xmp' => null |
||
85 | ); |
||
86 | |||
87 | private $resource; |
||
88 | |||
89 | 3 | public function __construct($resource) |
|
93 | |||
94 | 1 | public function readExif() |
|
98 | |||
99 | 1 | public function readIptc() |
|
114 | |||
115 | 1 | public function readXmp() |
|
123 | |||
124 | 1 | private function readXmpData($chunk_size = 10000) |
|
148 | |||
149 | 3 | public function getMetaData() |
|
153 | } |
||
154 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.