@@ -543,6 +543,7 @@ public function runQuery(QueryInterface $query, array $options = [])
543543 if (isset ($ remainingLimit )) {
544544 $ requestQueryArr ['limit ' ] = $ remainingLimit ;
545545 }
546+
546547 $ request = [
547548 'projectId ' => $ this ->projectId ,
548549 'partitionId ' => $ this ->partitionId (
@@ -924,6 +925,10 @@ private function readOptions(array $options = [])
924925 'readTime ' => $ options ['readTime ' ]
925926 ]);
926927
928+ if (count ($ readOptions ) > 1 ) {
929+ throw new InvalidArgumentException ('ReadOptions can only be one of `readConsistency`, `transaction` or `readTime`. ' );
930+ }
931+
927932 return array_filter ([
928933 'readOptions ' => $ readOptions ,
929934 ]);
@@ -961,29 +966,33 @@ private function sortEntities(array $entities, array $keys)
961966 */
962967 private function createReadOptions (array $ options )
963968 {
964- $ empty = true ;
969+ $ totalSet = 0 ;
965970
966971 $ readOptions = new ReadOptions ();
967972 if (isset ($ options ['transaction ' ])) {
968- $ empty = false ;
973+ $ totalSet ++ ;
969974 $ readOptions ->setTransaction (base64_decode ($ options ['transaction ' ]));
970975 }
971976 if (isset ($ options ['readConsistency ' ])) {
972- $ empty = false ;
977+ $ totalSet ++ ;
973978 $ readOptions ->setReadConsistency ($ options ['readConsistency ' ]);
974979 }
975980 if (isset ($ options ['readTime ' ])) {
976- $ empty = false ;
981+ $ totalSet ++ ;
977982 $ protoTime = new ProtobufTimestamp ();
978983 // Timestamps can be passed as an array or a Timestamp object.
979984 $ protoTime ->mergeFromJsonString (json_encode ($ options ['readTime ' ]));
980985 $ readOptions ->setReadTime ($ protoTime );
981986 }
982987
983- if ($ empty ) {
988+ if ($ totalSet === 0 ) {
984989 return null ;
985990 }
986991
992+ if ($ totalSet > 1 ) {
993+ throw new InvalidArgumentException ('Only one of `readConsistency`, `transaction` or `readTime` may be set. ' );
994+ }
995+
987996 return $ readOptions ;
988997 }
989998
0 commit comments