Changeset 10237
- Timestamp:
- 07/12/08 09:22:27 (4 months ago)
- Files:
-
- plugins/sfSearchPlugin/trunk/lib/result/xfDocumentHit.class.php (modified) (1 diff)
- plugins/sfSearchPlugin/trunk/lib/result/xfRetort.interface.php (modified) (2 diffs)
- plugins/sfSearchPlugin/trunk/lib/result/xfRetortField.class.php (modified) (3 diffs)
- plugins/sfSearchPlugin/trunk/lib/result/xfRetortFilter.class.php (modified) (3 diffs)
- plugins/sfSearchPlugin/trunk/lib/result/xfRetortFilterCallback.interface.php (modified) (1 diff)
- plugins/sfSearchPlugin/trunk/lib/result/xfRetortRoute.class.php (modified) (3 diffs)
- plugins/sfSearchPlugin/trunk/test/functional/xfResultsTest.php (modified) (2 diffs)
- plugins/sfSearchPlugin/trunk/test/mock/result/xfMockRetort.class.php (modified) (1 diff)
- plugins/sfSearchPlugin/trunk/test/mock/result/xfMockRetortFilterCallback.class.php (modified) (1 diff)
- plugins/sfSearchPlugin/trunk/test/unit/result/xfRetortFieldTest.php (modified) (2 diffs)
- plugins/sfSearchPlugin/trunk/test/unit/result/xfRetortFilterTest.php (modified) (3 diffs)
- plugins/sfSearchPlugin/trunk/test/unit/result/xfRetortRouteTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfSearchPlugin/trunk/lib/result/xfDocumentHit.class.php
r9420 r10237 71 71 foreach ($this->retorts as $retort) 72 72 { 73 if ($retort->can($this , $method, $args))73 if ($retort->can($this->document, $method, $args)) 74 74 { 75 return $retort->respond($this , $method, $args);75 return $retort->respond($this->document, $method, $args); 76 76 } 77 77 } plugins/sfSearchPlugin/trunk/lib/result/xfRetort.interface.php
r8175 r10237 9 9 10 10 /** 11 * A retort extends xfDocument Hitto provide advanced functionality.11 * A retort extends xfDocument to provide advanced functionality. 12 12 * 13 13 * @package sfSearch … … 20 20 * Determines if this retort can in fact respond. 21 21 * 22 * @param xfDocument Hit $resultThe result22 * @param xfDocument $doc The result 23 23 * @param string $method The method called 24 24 * @param array $args The args passed (optional) 25 25 * @returns mixed The retort response 26 26 */ 27 public function can(xfDocument Hit $result, $method, array $args = array());27 public function can(xfDocument $doc, $method, array $args = array()); 28 28 29 29 /** 30 30 * Generates a response for this retort 31 31 * 32 * @param xfDocument Hit $resultThe result32 * @param xfDocument $doc The result 33 33 * @param string $method The method called 34 34 * @param array $args The args passed (optional) 35 35 * @returns mixed The retort response 36 36 */ 37 public function respond(xfDocument Hit $result, $method, array $args = array());37 public function respond(xfDocument $doc, $method, array $args = array()); 38 38 } plugins/sfSearchPlugin/trunk/lib/result/xfRetortField.class.php
r8175 r10237 31 31 * @see xfRetort 32 32 */ 33 public function can(xfDocument Hit $result, $method, array $args = array())33 public function can(xfDocument $doc, $method, array $args = array()) 34 34 { 35 35 if (substr($method, 0, 3) == 'get') … … 37 37 $field = $this->normalize($method); 38 38 39 return $ result->getDocument()->hasField($field);39 return $doc->hasField($field); 40 40 } 41 41 … … 46 46 * @see xfRetort 47 47 */ 48 public function respond(xfDocument Hit $result, $method, array $args = array())48 public function respond(xfDocument $doc, $method, array $args = array()) 49 49 { 50 50 $field = $this->normalize($method); 51 51 52 return $ result->getDocument()->getField($field)->getValue();52 return $doc->getField($field)->getValue(); 53 53 } 54 54 plugins/sfSearchPlugin/trunk/lib/result/xfRetortFilter.class.php
r8175 r10237 65 65 * @see xfRetort 66 66 */ 67 public function can(xfDocument Hit $hit, $method, array $args = array())67 public function can(xfDocument $doc, $method, array $args = array()) 68 68 { 69 return $this->retort->can($ hit, $method, $args);69 return $this->retort->can($doc, $method, $args); 70 70 } 71 71 … … 73 73 * @see xfRetort 74 74 */ 75 public function respond(xfDocument Hit $hit, $method, array $args = array())75 public function respond(xfDocument $doc, $method, array $args = array()) 76 76 { 77 $response = $this->retort->respond($ hit, $method, $args);77 $response = $this->retort->respond($doc, $method, $args); 78 78 79 79 foreach ($this->filters as $filter) … … 81 81 if ($filter instanceof xfRetortFilterCallback) 82 82 { 83 $response = $filter->filter($response, $ hit, $method, $args);83 $response = $filter->filter($response, $doc, $method, $args); 84 84 } 85 85 elseif (is_callable($filter)) plugins/sfSearchPlugin/trunk/lib/result/xfRetortFilterCallback.interface.php
r8175 r10237 21 21 * 22 22 * @param string $response 23 * @param xfDocument Hit $hit23 * @param xfDocument $doc 24 24 * @param string $method 25 25 * @param array $args 26 26 * @returns string 27 27 */ 28 public function filter($response, xfDocument Hit $hit, $method, array $args = array());28 public function filter($response, xfDocument $doc, $method, array $args = array()); 29 29 } plugins/sfSearchPlugin/trunk/lib/result/xfRetortRoute.class.php
r8545 r10237 64 64 * @see xfRetort 65 65 */ 66 public function can(xfDocument Hit $hit, $method, array $args = array())66 public function can(xfDocument $doc, $method, array $args = array()) 67 67 { 68 68 return $this->method == $method; … … 72 72 * @see xfRetort 73 73 */ 74 public function respond(xfDocument Hit $hit, $method, array $args = array())74 public function respond(xfDocument $doc, $method, array $args = array()) 75 75 { 76 76 $route = $this->template; … … 78 78 foreach ($this->matches as $match) 79 79 { 80 $route = str_replace('$' . $match . '$', $ hit->getDocument()->getField($match)->getValue(), $route);80 $route = str_replace('$' . $match . '$', $doc->getField($match)->getValue(), $route); 81 81 } 82 82 plugins/sfSearchPlugin/trunk/test/functional/xfResultsTest.php
r9405 r10237 17 17 class TitleRetort implements xfRetort 18 18 { 19 public function can(xfDocument Hit $hit, $method, array $args = array())19 public function can(xfDocument $doc, $method, array $args = array()) 20 20 { 21 21 return $method == 'getTitle'; 22 22 } 23 23 24 public function respond(xfDocument Hit $hit, $method, array $args = array())24 public function respond(xfDocument $doc, $method, array $args = array()) 25 25 { 26 return 'Title' . $ hit->getDocument()->getField('input')->getValue();26 return 'Title' . $doc->getField('input')->getValue(); 27 27 } 28 28 } … … 30 30 class DescriptionRetort implements xfRetort 31 31 { 32 public function can(xfDocument Hit $hit, $method, array $args = array())32 public function can(xfDocument $doc, $method, array $args = array()) 33 33 { 34 34 return $method == 'getDescription'; 35 35 } 36 36 37 public function respond(xfDocument Hit $hit, $method, array $args = array())37 public function respond(xfDocument $doc, $method, array $args = array()) 38 38 { 39 return 'Description' . $ hit->getDocument()->getField('input')->getValue();39 return 'Description' . $doc->getField('input')->getValue(); 40 40 } 41 41 } plugins/sfSearchPlugin/trunk/test/mock/result/xfMockRetort.class.php
r8103 r10237 21 21 public $can = true, $response = 42; 22 22 23 public function can(xfDocument Hit$result, $method, array $args = array())23 public function can(xfDocument $result, $method, array $args = array()) 24 24 { 25 25 return $this->can; 26 26 } 27 27 28 public function respond(xfDocument Hit$result, $method, array $args = array())28 public function respond(xfDocument $result, $method, array $args = array()) 29 29 { 30 30 return $this->response; plugins/sfSearchPlugin/trunk/test/mock/result/xfMockRetortFilterCallback.class.php
r8329 r10237 12 12 class xfMockRetortFilterCallback implements xfRetortFilterCallback 13 13 { 14 public function filter($response, xfDocument Hit$hit, $method, array $args = array())14 public function filter($response, xfDocument $hit, $method, array $args = array()) 15 15 { 16 16 return md5($response); plugins/sfSearchPlugin/trunk/test/unit/result/xfRetortFieldTest.php
r8329 r10237 12 12 require 'result/xfRetort.interface.php'; 13 13 require 'result/xfRetortField.class.php'; 14 require 'result/xfDocumentHit.class.php';15 14 require 'document/xfDocument.class.php'; 16 15 require 'document/xfField.class.php'; 17 16 require 'document/xfFieldValue.class.php'; 18 require 'mock/criteria/xfMockCriterionImplementer.class.php';19 17 20 18 $doc = new xfDocument('guid'); 21 19 $doc->addField(new xfFieldValue(new xfField('name', xfField::KEYWORD), 'carl')); 22 $hit = new xfDocumentHit($doc, new xfMockCriterionImplementer);23 20 24 21 $t = new lime_test(4, new lime_output_color); … … 27 24 28 25 $t->diag('->can()'); 29 $t->ok($retort->can($ hit, 'getName'), '->can() returns true if method matches a field in the document');30 $t->ok(!$retort->can($ hit, 'getFoo'), '->can() returns false if method does not match a field in the document');31 $t->ok(!$retort->can($ hit, 'fetchName'), '->can() returns false if method is invalid syntax');26 $t->ok($retort->can($doc, 'getName'), '->can() returns true if method matches a field in the document'); 27 $t->ok(!$retort->can($doc, 'getFoo'), '->can() returns false if method does not match a field in the document'); 28 $t->ok(!$retort->can($doc, 'fetchName'), '->can() returns false if method is invalid syntax'); 32 29 33 30 $t->diag('->respond()'); 34 $t->is($retort->respond($ hit, 'getName'), 'carl', '->respond() returns the field response');31 $t->is($retort->respond($doc, 'getName'), 'carl', '->respond() returns the field response'); plugins/sfSearchPlugin/trunk/test/unit/result/xfRetortFilterTest.php
r8329 r10237 13 13 require 'result/xfRetortFilter.class.php'; 14 14 require 'result/xfRetortFilterCallback.interface.php'; 15 require 'result/xfDocumentHit.class.php';16 15 require 'result/xfResultException.class.php'; 17 16 require 'mock/result/xfMockRetort.class.php'; 18 17 require 'mock/result/xfMockRetortFilterCallback.class.php'; 19 18 require 'document/xfDocument.class.php'; 20 require 'mock/criteria/xfMockCriterionImplementer.class.php';21 19 22 $ hit = new xfDocumentHit(new xfDocument('guid'), new xfMockCriterionImplementer);20 $doc = new xfDocument('guid'); 23 21 24 22 $t = new lime_test(6, new lime_output_color); … … 27 25 $wrapped = new xfMockRetort; 28 26 $retort = new xfRetortFilter($wrapped); 29 $t->ok($retort->can($ hit, 'getFoo'), '->can() wraps the internal retort');27 $t->ok($retort->can($doc, 'getFoo'), '->can() wraps the internal retort'); 30 28 $wrapped->can = false; 31 $t->ok(!$retort->can($ hit, 'getFoo'), '->can() wraps the internal retort');29 $t->ok(!$retort->can($doc, 'getFoo'), '->can() wraps the internal retort'); 32 30 33 31 $t->diag('->respond() - no callable'); 34 32 $wrapped = new xfMockRetort; 35 33 $retort = new xfRetortFilter($wrapped); 36 $t->is($retort->respond($ hit, 'getFoo'), 42, '->respond() wraps the internal retort');34 $t->is($retort->respond($doc, 'getFoo'), 42, '->respond() wraps the internal retort'); 37 35 38 36 $t->diag('->respond() - php callable'); 39 37 $retort->registerFilter('md5'); 40 38 $retort->registerFilter('strtoupper'); 41 $t->is($retort->respond($ hit, 'getFoo'), strtoupper(md5(42)), '->respond() filters response with registered php callable filters in order');39 $t->is($retort->respond($doc, 'getFoo'), strtoupper(md5(42)), '->respond() filters response with registered php callable filters in order'); 42 40 43 41 $t->diag('->respond() - xfRetortFilterCallback callable'); … … 45 43 $retort = new xfRetortFilter($wrapped); 46 44 $retort->registerFilter(new xfMockRetortFilterCallback); 47 $t->is($retort->respond($ hit, 'getFoo'), md5(42), '->respond() filters response with registered xfRetortFilterCallback filters');45 $t->is($retort->respond($doc, 'getFoo'), md5(42), '->respond() filters response with registered xfRetortFilterCallback filters'); 48 46 49 47 $t->diag('->registerFilter() - invalid callable'); plugins/sfSearchPlugin/trunk/test/unit/result/xfRetortRouteTest.php
r8545 r10237 11 11 require 'result/xfRetort.interface.php'; 12 12 require 'result/xfRetortRoute.class.php'; 13 require 'result/xfDocumentHit.class.php';14 13 require 'document/xfDocument.class.php'; 15 14 require 'document/xfField.class.php'; 16 15 require 'document/xfFieldValue.class.php'; 17 require 'mock/criteria/xfMockCriterionImplementer.class.php';18 16 19 17 $doc = new xfDocument('guid'); 20 18 $doc->addField(new xfFieldValue(new xfField('isbn', xfField::KEYWORD), '1234567890')); 21 19 $doc->addField(new xfFieldValue(new xfField('id', xfField::KEYWORD), '42')); 22 $hit = new xfDocumentHit($doc, new xfMockCriterionImplementer);23 20 24 21 $t = new lime_test(5, new lime_output_color); … … 27 24 28 25 $t->diag('->can()'); 29 $t->ok(!$retort->can($ hit, 'getFoo'), '->can() returns false if method does not match');30 $t->ok($retort->can($ hit, 'getRoute'), '->can() returns true if method does match');26 $t->ok(!$retort->can($doc, 'getFoo'), '->can() returns false if method does not match'); 27 $t->ok($retort->can($doc, 'getRoute'), '->can() returns true if method does match'); 31 28 32 29 $t->diag('->respond()'); 33 $t->is($retort->respond($ hit, 'getRoute'), 'show/book?id=42', '->respond() can do a single replacement');30 $t->is($retort->respond($doc, 'getRoute'), 'show/book?id=42', '->respond() can do a single replacement'); 34 31 35 32 $retort = new xfRetortRoute('show/book?id=$id$&isbn=$isbn$'); 36 $t->is($retort->respond($ hit, 'getRoute'), 'show/book?id=42&isbn=1234567890', '->respond() can do a double replacement');33 $t->is($retort->respond($doc, 'getRoute'), 'show/book?id=42&isbn=1234567890', '->respond() can do a double replacement'); 37 34 38 35 $t->diag('->setMethod()'); 39 36 $retort->setMethod('getIt'); 40 $t->ok($retort->can($ hit, 'getIt'), '->setMethod() changes the matching method');37 $t->ok($retort->can($doc, 'getIt'), '->setMethod() changes the matching method');