Changeset 6818
- Timestamp:
- 12/29/07 22:44:41 (6 months ago)
- Files:
-
- plugins/sfAmazonSimpleDBPlugin/trunk/README (modified) (2 diffs)
- plugins/sfAmazonSimpleDBPlugin/trunk/lib/Amazon/SimpleDB/Mock (deleted)
- plugins/sfAmazonSimpleDBPlugin/trunk/lib/Amazon/SimpleDB/Mock.php (deleted)
- plugins/sfAmazonSimpleDBPlugin/trunk/lib/Amazon/SimpleDB/Samples (deleted)
- plugins/sfAmazonSimpleDBPlugin/trunk/lib/sfAmazonSimpleDBClient.class.php (modified) (7 diffs)
- plugins/sfAmazonSimpleDBPlugin/trunk/test/unit/sfAmazonSimpleDBTest.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfAmazonSimpleDBPlugin/trunk/README
r6815 r6818 60 60 === Listing domains === 61 61 62 To list available domains for your t accounts:62 To list available domains for your AWS account : 63 63 64 64 {{{ 65 $domains = $service->listDomains(); 66 echo implode(', ', $domains); 65 $domainsQuery = $service->listDomains(); 66 echo implode(', ', $domainsQuery['results']); 67 }}} 68 69 You can even limit the number of results, eg. for pagination purpose: 70 71 {{{ 72 $domainsQuery = $service->listDomains(5); 73 echo '5 first domains : '.implode(', ', $domainsQuery['results']); 74 75 if (isset($domainsQuery['next_token'])) 76 { 77 $nextDomainsQuery = $service->listDomains(5, $domainsQuery['next_token']); 78 echo 'Next 5 domains : '.implode(', ', $nextDomainsQuery['results']); 79 } 67 80 }}} 68 81 … … 105 118 106 119 {{{ 107 $products = $service->query("['Color' = 'Red'] intersection ['Size' = 'Small']"); 108 echo 'Red small products are '.implode(', ', $results); 120 $resultsQuery = $service->query("['Color' = 'Red'] intersection ['Size' = 'Small']"); 121 echo 'Red small products are '.implode(', ', $resultsQuery['results']); 122 }}} 123 124 [http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_Query.html#SDB_API_Query_QueryExpressionSyntax More on query syntax and available operators]. 125 126 You can even limit the number of results, eg. for pagination purpose: 127 128 {{{ 129 $resultsQuery = $service->query("['Color' = 'Red']", 5) 130 echo '5 first results : '.implode(', ', $resultsQuery['results']); 131 132 if (isset($resultsQuery['next_token'])) 133 { 134 $nextResultsQuery = $service->query("['Color' = 'Red']", 5, $resultsQuery['next_token']); 135 echo 'Next 5 results : '.implode(', ', $nextResultsQuery['results']); 136 } 109 137 }}} 110 138 plugins/sfAmazonSimpleDBPlugin/trunk/lib/sfAmazonSimpleDBClient.class.php
r6815 r6818 147 147 * Lists available domains 148 148 * 149 * @param int $max Max entries to retrieve (optional) 150 * @param int $offset Offset to start with (optional) 149 151 * @return array of strings 150 152 * @throws sfAmazonSimpleDBException 151 153 */ 152 public function listDomains( )154 public function listDomains($max = null, $offset = null) 153 155 { 154 156 try … … 156 158 $results = array(); 157 159 $action = new Amazon_SimpleDB_Model_ListDomains(); 160 if (!is_null($max) && $max > 0) 161 { 162 $action->setMaxNumberOfDomains($max); 163 } 164 if (!is_null($offset)) 165 { 166 $action->setNextToken($offset); 167 } 168 $results = array('results' => array()); 158 169 sfLogger::getInstance()->info('Listing existing domains'); 159 170 $response = self::getClient()->listDomains($action); … … 164 175 foreach ($domainNameList as $domainName) 165 176 { 166 $results[] = $domainName; 167 } 177 $results['results'][] = $domainName; 178 } 179 if ($listDomainsResult->isSetNextToken()) 180 { 181 $results['next_token'] = $listDomainsResult->getNextToken(); 182 } 183 } 184 if ($response->isSetResponseMetadata()) 185 { 186 $responseMetadata = $response->getResponseMetadata(); 187 if ($responseMetadata->isSetRequestId()) 188 { 189 $results['request_id'] = $responseMetadata->getRequestId(); 190 } 191 if ($responseMetadata->isSetBoxUsage()) 192 { 193 $results['box_usage'] = $responseMetadata->getBoxUsage(); 194 } 168 195 } 169 196 return $results; … … 303 330 * Query database with given expression 304 331 * 305 * @param string $expression 306 * @param string $domain 332 * @param string $expression Query expression (optional) 333 * @param int $max Max entries to retrieve (optional) 334 * @param int $offset Offset to start with (optional) 335 * @param string $domain Domain to query (optional) 307 336 * @return array 308 */ 309 public function query($expression = null, $domain = null) 337 * @link http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_Query.html#SDB_API_Query_QueryExpressionSyntax 338 */ 339 public function query($expression = null, $max = null, $offset = null, $domain = null) 310 340 { 311 341 if (is_null($domain)) … … 317 347 throw new sfAmazonSimpleDBException('query(): No domain has been selected nor specified'); 318 348 } 319 $results = array( );349 $results = array('results' => array()); 320 350 $action = new Amazon_SimpleDB_Model_Query(); 321 351 $action->setDomainName($domain); … … 324 354 $action->setQueryExpression($expression); 325 355 } 356 if (!is_null($max) && $max > 0) 357 { 358 $action->setMaxNumberOfItems($max); 359 } 360 if (!is_null($offset)) 361 { 362 $action->setNextToken($offset); 363 } 326 364 sfLogger::getInstance()->info(sprintf('Querying "%s" in domain "%s"', $expression, $domain)); 327 365 $response = self::getClient()->query($action); … … 332 370 foreach ($itemNameList as $itemName) 333 371 { 334 $results[] = $itemName; 372 $results['results'][] = $itemName; 373 } 374 if ($queryResult->isSetNextToken()) 375 { 376 $results['next_token'] = $queryResult->getNextToken(); 377 } 378 } 379 if ($response->isSetResponseMetadata()) 380 { 381 $responseMetadata = $response->getResponseMetadata(); 382 if ($responseMetadata->isSetRequestId()) 383 { 384 $results['request_id'] = $responseMetadata->getRequestId(); 385 } 386 if ($responseMetadata->isSetBoxUsage()) 387 { 388 $results['box_usage'] = $responseMetadata->getBoxUsage(); 335 389 } 336 390 } plugins/sfAmazonSimpleDBPlugin/trunk/test/unit/sfAmazonSimpleDBTest.php
r6815 r6818 6 6 require_once($sf_root.'/lib/symfony/vendor/lime/lime.php'); 7 7 8 $t = new lime_test( 44, new lime_output_color());8 $t = new lime_test(54, new lime_output_color()); 9 9 10 10 $service = sfAmazonSimpleDBClient::getInstance(); … … 14 14 try 15 15 { 16 $domainCreation = $service->createDomain('sfAmazonSimpleDBPluginTestDomain'); 17 $t->ok($domainCreation, 'createDomain() confirms domain has been created'); 16 $domainCreation1 = $service->createDomain('sfAmazonSimpleDBPluginTestDomain'); 17 $domainCreation2 = $service->createDomain('sfAmazonSimpleDBPluginTestDomain2'); 18 $domainCreation3 = $service->createDomain('sfAmazonSimpleDBPluginTestDomain3'); 19 $t->ok($domainCreation1 && $domainCreation2 && $domainCreation3, 'createDomain() confirms domain has been created'); 18 20 $t->pass('createDomain() does not throw an exception'); 19 21 } … … 26 28 try 27 29 { 28 $domainsList = $service->listDomains(); 30 $domainsResults = $service->listDomains(); 31 $domainsList = $domainsResults['results']; 29 32 $t->isa_ok($domainsList, 'array', 'listDomains() returns an array'); 30 33 $t->ok(in_array('sfAmazonSimpleDBPluginTestDomain', $domainsList), 'listDomains() lists new created domain'); 34 $t->ok(in_array('sfAmazonSimpleDBPluginTestDomain2', $domainsList), 'listDomains() lists new created domain'); 35 $t->ok(in_array('sfAmazonSimpleDBPluginTestDomain3', $domainsList), 'listDomains() lists new created domain'); 36 37 $t->diag('Testing limit and offseting for domains list'); 38 $domainsResults = $service->listDomains(2); 39 $domainsList = $domainsResults['results']; 40 $t->is(count($domainsList), 2, 'listDomains() retrieves the correct limited number of results'); 41 $t->ok(isset($domainsResults['next_token']), 'listDomains() returns a next token'); 42 43 $domainsResultsNext = $service->listDomains(2, $domainsResults['next_token']); 44 $domainsResultsListNext = $domainsResultsNext['results']; 45 $t->is(count($domainsResultsListNext), 1, 'listDomains() retrieves the correct limited number of results with an offset'); 46 31 47 $t->pass('listDomains() does not throw an exception'); 32 48 } … … 83 99 { 84 100 $t->diag(' 1. Getting all data'); 85 $query = $service->query(); 86 $t->isa_ok($query, 'array', 'query() retrieves results as an array'); 87 $t->is(count($query), 3, 'query() retrieves the correct number of results'); 101 $queryResults = $service->query(); 102 $queryResultsList = $queryResults['results']; 103 $t->isa_ok($queryResultsList, 'array', 'query() retrieves results as an array'); 104 $t->is(count($queryResultsList), 3, 'query() retrieves the correct number of results'); 88 105 89 106 $t->diag(' 2. Filtering one attribute'); 90 $query = $service->query("['Color' = 'Red']"); 91 $t->isa_ok($query, 'array', 'query() retrieves results as an array'); 92 $t->is(count($query), 1, 'query() retrieves the correct number of results'); 93 $t->is($query[0], 'Entry #2', 'query() retrieves the correct result'); 107 $queryResults = $service->query("['Color' = 'Red']"); 108 $queryResultsList = $queryResults['results']; 109 $t->isa_ok($queryResultsList, 'array', 'query() retrieves results as an array'); 110 $t->is(count($queryResultsList), 1, 'query() retrieves the correct number of results'); 111 $t->is($queryResultsList[0], 'Entry #2', 'query() retrieves the correct result'); 94 112 95 113 $t->diag(' 3. Filtering multiple attributes'); 96 $query = $service->query("['Color' = 'Green'] intersection ['Size' = 'Small']"); 97 $t->is(count($query), 1, 'query() retrieves the correct number of results'); 98 $t->is($query[0], 'Entry #3', 'query() retrieves the correct result'); 114 $queryResults = $service->query("['Color' = 'Green'] intersection ['Size' = 'Small']"); 115 $queryResultsList = $queryResults['results']; 116 $t->is(count($queryResultsList), 1, 'query() retrieves the correct number of results'); 117 $t->is($queryResultsList[0], 'Entry #3', 'query() retrieves the correct result'); 118 119 $t->diag(' 4. Testing limit and offseting for results list'); 120 $queryResults = $service->query(null, 2); 121 $queryResultsList = $queryResults['results']; 122 $t->is(count($queryResultsList), 2, 'query() retrieves the correct limited number of results'); 123 $t->ok(isset($queryResults['next_token']), 'query() retrieves a next token attribute'); 124 125 $queryResultsNext = $service->query(null, 2, $queryResults['next_token']); 126 $queryResultsListNext = $queryResultsNext['results']; 127 $t->is(count($queryResultsListNext), 1, 'query() retrieves the correct limited number of results with an offset'); 128 99 129 $t->pass('query() does not throw an exception'); 100 130 } … … 161 191 try 162 192 { 163 $domainDeletion = $service->deleteDomain('sfAmazonSimpleDBPluginTestDomain'); 164 $t->ok($domainDeletion, 'deleteDomain() confirms domain has been deleted'); 193 $domainDeletion1 = $service->deleteDomain('sfAmazonSimpleDBPluginTestDomain'); 194 $domainDeletion2 = $service->deleteDomain('sfAmazonSimpleDBPluginTestDomain2'); 195 $domainDeletion3 = $service->deleteDomain('sfAmazonSimpleDBPluginTestDomain3'); 196 $t->ok($domainDeletion1 && $domainDeletion2 && $domainDeletion3, 'deleteDomain() confirms domain has been deleted'); 165 197 $t->pass('deleteDomain() does not throw an exception'); 166 198 } … … 170 202 } 171 203 172 $domainsList = $service->listDomains(); 204 $domainsResults = $service->listDomains(); 205 $domainsList = $domainsResults['results']; 173 206 $t->ok(!in_array('sfAmazonSimpleDBPluginTestDomain', $domainsList), 'listDomains() no more lists deleted domain'); 207 $t->ok(!in_array('sfAmazonSimpleDBPluginTestDomain2', $domainsList), 'listDomains() no more lists deleted domain'); 208 $t->ok(!in_array('sfAmazonSimpleDBPluginTestDomain3', $domainsList), 'listDomains() no more lists deleted domain'); 174 209 $t->is($service->getSelectedDomain(), null, 'getSelectedDomain() no more returns a deleted domain as selected');