@@ -77,7 +77,7 @@ class Visualization
7777 *
7878 * @throws Visualization_Error
7979 */
80- public function __construct ($ db = null , $ dialect = 'mysql ' )
80+ public function __construct (PDO $ db = null , $ dialect = 'mysql ' )
8181 {
8282 if (!function_exists ('json_encode ' )) {
8383 throw new Visualization_Error ('You must include the PHP json extension installed to use the MC Google Visualization Server ' );
@@ -90,15 +90,12 @@ public function __construct($db = null, $dialect = 'mysql')
9090 /**
9191 * Set the database connection to use when handling the entire request or getting pivot values.
9292 *
93- * @param null|mixed| PDO $db the database connection to use - or null if you want to handle your own queries
93+ * @param null|PDO $db the database connection to use - or null if you want to handle your own queries
9494 *
9595 * @throws Visualization_Error
9696 */
97- public function setDB ($ db = null )
97+ public function setDB (PDO $ db = null )
9898 {
99- if (null !== $ db && !($ db instanceof PDO )) {
100- throw new Visualization_Error ('You must give a PDO database connection ' );
101- }
10299 if (null !== $ db ) {
103100 $ db ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
104101 }
@@ -142,19 +139,25 @@ public function setDefaultFormat($type, $format)
142139 }
143140
144141 /**
145- * Handle the entire request, pulling the query from the $_GET variables, and printing the results directly.
142+ * Handle the entire request, pulling the query from the $_GET variables and printing the results directly
143+ * if not specified otherwise.
146144 *
147- * @param bool $echo print response and set header
145+ * @param bool $echo print response and set header
146+ * @param array $query_params query parameters
148147 *
149148 * @throws Visualization_Error
150149 *
151150 * @return string the javascript response
152151 */
153- public function handleRequest ($ echo = true )
152+ public function handleRequest ($ echo = true , array $ query_params = null )
154153 {
155- $ query = $ _GET ['tq ' ];
154+ if (null === $ query_params ) {
155+ $ query_params = $ _GET ;
156+ }
157+
158+ $ query = $ query_params ['tq ' ];
156159 $ params = ['version ' => $ this ->version , 'responseHandler ' => 'google.visualization.Query.setResponse ' ];
157- $ paramlist = explode ('; ' , $ _GET ['tqx ' ]);
160+ $ paramlist = explode ('; ' , $ query_params ['tqx ' ]);
158161 foreach ($ paramlist as $ paramstr ) {
159162 list ($ name , $ val ) = explode (': ' , $ paramstr );
160163 $ params [$ name ] = $ val ;
@@ -166,8 +169,8 @@ public function handleRequest($echo = true)
166169 throw new Visualization_Error ('Data Source version ' .$ params ['version ' ].' is unsupported at this time ' );
167170 }
168171
169- if (isset ($ _GET ['responseHandler ' ])) {
170- $ params ['responseHandler ' ] = $ _GET ['responseHandler ' ];
172+ if (isset ($ query_params ['responseHandler ' ])) {
173+ $ params ['responseHandler ' ] = $ query_params ['responseHandler ' ];
171174 }
172175
173176 $ response = $ this ->handleQuery ($ query , $ params );
@@ -188,7 +191,7 @@ public function handleRequest($echo = true)
188191 *
189192 * @return string the javascript response
190193 */
191- public function handleQuery ($ query , $ params )
194+ public function handleQuery ($ query , array $ params )
192195 {
193196 $ reqid = null ;
194197 $ response = '' ;
@@ -261,7 +264,7 @@ public function handleError($reqid, $detail_msg, $handler = 'google.visualizatio
261264 *
262265 * @return string the SQL version of the visualization query
263266 */
264- public function generateSQL (&$ meta )
267+ public function generateSQL (array &$ meta )
265268 {
266269 if (!isset ($ meta ['query_fields ' ])) {
267270 $ meta ['query_fields ' ] = $ meta ['select ' ];
@@ -422,7 +425,7 @@ public function generateSQL(&$meta)
422425 *
423426 * @return array the metadata array from merging the query with the entity table definitions
424427 */
425- public function generateMetadata ($ query )
428+ public function generateMetadata (array $ query )
426429 {
427430 $ meta = [];
428431 if (!isset ($ query ['from ' ]) && null === $ this ->default_entity ) {
@@ -720,7 +723,7 @@ public function parseQuery($str)
720723 *
721724 * @throws Visualization_Error
722725 */
723- public function addEntity ($ name , $ spec = [])
726+ public function addEntity ($ name , array $ spec = [])
724727 {
725728 $ entity = ['table ' => isset ($ spec ['table ' ]) ? $ spec ['table ' ] : $ name , 'fields ' => [], 'joins ' => []];
726729 $ this ->entities [$ name ] = $ entity ;
@@ -751,7 +754,7 @@ public function addEntity($name, $spec = [])
751754 *
752755 * @throws Visualization_Error
753756 */
754- public function addEntityField ($ entity , $ field , $ spec )
757+ public function addEntityField ($ entity , $ field , array $ spec )
755758 {
756759 if (!isset ($ spec ['field ' ]) && !isset ($ spec ['callback ' ])) {
757760 throw new Visualization_Error ('Entity fields must either be mapped to database fields or given callback functions ' );
@@ -828,7 +831,7 @@ public function setDefaultEntity($default = null)
828831 *
829832 * @return string the initial output string for a successful query
830833 */
831- public function getSuccessInit ($ meta )
834+ public function getSuccessInit (array $ meta )
832835 {
833836 $ handler = $ meta ['req_params ' ]['responseHandler ' ] ?: 'google.visualization.Query.setResponse ' ;
834837 $ version = $ meta ['req_params ' ]['version ' ] ?: $ this ->version ;
@@ -845,7 +848,7 @@ public function getSuccessInit($meta)
845848 *
846849 * @return string
847850 */
848- public function getTableInit ($ meta )
851+ public function getTableInit (array $ meta )
849852 {
850853 $ field_init = [];
851854 foreach ($ meta ['select ' ] as $ field ) {
@@ -915,7 +918,7 @@ public function getTableInit($meta)
915918 *
916919 * @return string the string fragment to include in the results back to the javascript client
917920 */
918- public function getRowValues ($ row , $ meta )
921+ public function getRowValues (array $ row , array $ meta )
919922 {
920923 $ vals = [];
921924 foreach ($ meta ['select ' ] as $ field ) {
@@ -1235,7 +1238,7 @@ protected function getFieldQuote()
12351238 *
12361239 * @return string the SQL string for this field, with an op
12371240 */
1238- protected function getFieldSQL ($ name , $ spec , $ alias = false , $ func = null , $ pivot = null , $ pivot_fields = null )
1241+ protected function getFieldSQL ($ name , $ spec , $ alias = false , $ func = null , array $ pivot = null , array $ pivot_fields = null )
12391242 {
12401243 $ sql = $ spec ['field ' ];
12411244 $ q = $ this ->getFieldQuote ();
@@ -1272,7 +1275,7 @@ protected function getFieldSQL($name, $spec, $alias = false, $func = null, $pivo
12721275 *
12731276 * @throws Visualization_Error
12741277 */
1275- protected function addDependantCallbackFields ($ field , $ entity , &$ meta )
1278+ protected function addDependantCallbackFields (array $ field , array $ entity , array &$ meta )
12761279 {
12771280 foreach ($ field ['fields ' ] as $ dependant ) {
12781281 if (!isset ($ entity ['fields ' ][$ dependant ])) {
@@ -1295,10 +1298,10 @@ protected function addDependantCallbackFields($field, $entity, &$meta)
12951298 /**
12961299 * Helper method for the query parser to recursively scan the delimited list of select fields.
12971300 *
1298- * @param Token $token the token or token group to recursively parse
1299- * @param array $fields the collector array reference to receive the flattened select field values
1301+ * @param Token $token the token or token group to recursively parse
1302+ * @param null| array $fields the collector array reference to receive the flattened select field values
13001303 */
1301- protected function parseFieldTokens ($ token , &$ fields )
1304+ protected function parseFieldTokens ($ token , array &$ fields = null )
13021305 {
13031306 if ('* ' === $ token ->value ) {
13041307 return ;
@@ -1326,10 +1329,10 @@ protected function parseFieldTokens($token, &$fields)
13261329 /**
13271330 * Helper method for the query parser to recursively scan and flatten the where clause's conditions.
13281331 *
1329- * @param Token $token the token or token group to parse
1330- * @param array $where the collector array of tokens that make up the where clause
1332+ * @param Token $token the token or token group to parse
1333+ * @param null| array $where the collector array of tokens that make up the where clause
13311334 */
1332- protected function parseWhereTokens ($ token , &$ where )
1335+ protected function parseWhereTokens ($ token , array &$ where = null )
13331336 {
13341337 if (!is_array ($ where )) {
13351338 $ where = [];
0 commit comments