@@ -47,11 +47,11 @@ class Document
4747 private $ _bucket = null ;
4848
4949 /**
50- * Document metadata
50+ * Document fields
5151 *
5252 * @var array
5353 */
54- private $ _meta = [];
54+ private $ _fields = [];
5555
5656
5757 /**
@@ -61,13 +61,13 @@ class Document
6161 *
6262 * @param string $doc_id document identifier
6363 * @param Bucket $bucket document key/value store
64- * @param array $meta document metadata
64+ * @param array $fields document fields
6565 */
66- public function __construct ( $ doc_id , Bucket $ bucket , array $ meta = [] )
66+ public function __construct ( $ doc_id , Bucket $ bucket , array $ fields = [] )
6767 {
6868 $ this ->_id = (string )$ doc_id ;
6969 $ this ->_bucket = $ bucket ;
70- $ this ->_meta = $ meta ;
70+ $ this ->_fields = $ fields ;
7171 }
7272
7373
@@ -89,7 +89,16 @@ public function getId()
8989 */
9090 public function getProgramId ()
9191 {
92- return $ this ->_getMetaByName ( "programId " );
92+ // This existed before MissingDocumentFieldException and
93+ // was expected to not throw an exception when it does not exist.
94+ try
95+ {
96+ return (string )$ this ->_getFieldByName ( "programId " );
97+ }
98+ catch ( MissingDocumentFieldException $ e )
99+ {
100+ return "" ;
101+ }
93102 }
94103
95104
@@ -100,7 +109,7 @@ public function getProgramId()
100109 */
101110 public function getAgentId ()
102111 {
103- return $ this ->_getMetaByName ( "agentId " );
112+ return $ this ->_getFieldByName ( "agentId " );
104113 }
105114
106115
@@ -111,7 +120,7 @@ public function getAgentId()
111120 */
112121 public function getAgentEntityId ()
113122 {
114- return $ this ->_getMetaByName ( "agentEntityId " );
123+ return $ this ->_getFieldByName ( "agentEntityId " );
115124 }
116125
117126
@@ -122,7 +131,7 @@ public function getAgentEntityId()
122131 */
123132 public function getInitialRatedDate ()
124133 {
125- return $ this ->_getMetaByName ( "initialRatedDate " );
134+ return $ this ->_getFieldByName ( "initialRatedDate " );
126135 }
127136
128137
@@ -133,7 +142,7 @@ public function getInitialRatedDate()
133142 */
134143 public function getStartDate ()
135144 {
136- return $ this ->_getMetaByName ( "startDate " );
145+ return $ this ->_getFieldByName ( "startDate " );
137146 }
138147
139148
@@ -144,7 +153,7 @@ public function getStartDate()
144153 */
145154 public function getAgentName ()
146155 {
147- return $ this ->_getMetaByName ( "agentName " );
156+ return $ this ->_getFieldByName ( "agentName " );
148157 }
149158
150159
@@ -160,15 +169,19 @@ public function getBucket()
160169
161170
162171 /**
163- * Get metadata by key name
172+ * Get fields by key name
164173 *
165- * @param String The name of the key holding the data.
166- *
167- * @return string metadata or empty string if unknown
174+ * @param String The name of the key holding the data
175+ * @return string field or empty string if unknown
176+ * @throws MissingDocumentFieldException when the field does not exist
168177 */
169- private function _getMetaByName ( $ name )
178+ private function _getFieldByName ( $ name )
170179 {
171- $ data = &$ this ->_meta [ $ name ];
172- return (string )$ data ;
180+ if ( array_key_exists ( $ name , $ this ->_fields ) )
181+ {
182+ return $ this ->_fields [ $ name ];
183+ }
184+
185+ throw new MissingDocumentFieldException ( "Missing field data " );
173186 }
174187}
0 commit comments