Changeset 5600
- Timestamp:
- 10/19/07 18:22:47 (6 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfMDB2RestPlugin/trunk/lib/MDB2RestClient.class.php
r5587 r5600 10 10 class MDB2RestClient 11 11 { 12 protected $serverUrl = null, 13 $username = null, 14 $password = null; 12 protected $serverUrl = null, 13 $username = null, 14 $password = null, 15 $batch = false, 16 $batchRequests = array(); 15 17 16 18 /** … … 23 25 { 24 26 $this->serverUrl = $serverUrl; 27 } 28 29 /** 30 * startBatch 31 * 32 * @return void 33 */ 34 public function startBatch() 35 { 36 $this->batch = true; 37 } 38 39 /** 40 * endBatch 41 * 42 * @return void 43 */ 44 public function endBatch() 45 { 46 $this->batch = false; 47 48 return $this->retrieveBatchResults(); 49 } 50 51 /** 52 * retrieveBatchResults 53 * 54 * @return void 55 */ 56 protected function retrieveBatchResults() 57 { 58 $request = array('method' => 'batch', 'arguments' => $this->batchRequests); 59 60 $results = $this->request($request); 61 62 return $this->processRequestResults($results); 25 63 } 26 64 … … 67 105 $results = ob_get_contents(); 68 106 ob_end_clean(); 69 107 70 108 return unserialize($results); 71 109 } … … 162 200 $request = array('method' => $method, 'arguments' => $arguments); 163 201 164 $results = $this->request($request); 165 166 if (isset($results['error'])) { 167 throw new Exception($results['error']); 202 if ($this->batch) { 203 $this->batchRequests[] = $request; 168 204 } else { 169 return $results; 205 $results = $this->request($request); 206 207 return $this->processRequestResults($results); 170 208 } 171 209 } 210 211 /** 212 * processRequestResults 213 * 214 * @param array $results 215 */ 216 protected function processRequestResults($results) 217 { 218 if (isset($results['error'])) { 219 throw new Exception($results['error']); 220 } else { 221 return $results; 222 } 223 } 172 224 } plugins/sfMDB2RestPlugin/trunk/lib/MDB2RestServer.class.php
r5586 r5600 93 93 $request = unserialize($this->request['data']); 94 94 95 $results = $this->executeRequest($request); 96 97 echo serialize($results); 98 } 99 100 /** 101 * executeRequest 102 * 103 * @param array $request 104 */ 105 protected function executeRequest($request) 106 { 95 107 $method = $request['method']; 96 108 $arguments = $request['arguments']; 97 109 98 $results = $this->$method($arguments); 99 100 if ($results instanceof MDB2_error) { 101 $results = array('error' => $results->getMessage()); 102 } 103 104 echo serialize($results); 110 try { 111 $results = $this->$method($arguments); 112 113 if ($results instanceof MDB2_error) { 114 $results = array('error' => $results->getMessage()); 115 } 116 } catch (Exception $e) { 117 $results = array('error' => $e->getMessage()); 118 } 119 120 return $results; 121 } 122 123 /** 124 * batch 125 * 126 * @param array $arguments 127 */ 128 public function batch($arguments) 129 { 130 $results = array(); 131 foreach ($arguments as $request) { 132 $results[] = $this->executeRequest($request); 133 } 134 135 return $results; 105 136 } 106 137