Development

Changeset 10237

You must first sign up to be able to contribute.

Changeset 10237

Show
Ignore:
Timestamp:
07/12/08 09:22:27 (4 months ago)
Author:
Carl.Vondrick
Message:

sfSearch: changed xfRetort's dependency on xfDocumentHit to be on xfDocument only.

Notes:

  • In order to fit nicely into MVC, the result field data must be the same no matter the query that was searched for.
  • This commit introduces a regression in sfHighlight because it can no longer highlight results, but that broke MVC anyways. A new method will be introduced to do this (and more) in the generator.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSearchPlugin/trunk/lib/result/xfDocumentHit.class.php

    r9420 r10237  
    7171    foreach ($this->retorts as $retort) 
    7272    { 
    73       if ($retort->can($this, $method, $args)) 
     73      if ($retort->can($this->document, $method, $args)) 
    7474      { 
    75         return $retort->respond($this, $method, $args); 
     75        return $retort->respond($this->document, $method, $args); 
    7676      } 
    7777    } 
  • plugins/sfSearchPlugin/trunk/lib/result/xfRetort.interface.php

    r8175 r10237  
    99 
    1010/** 
    11  * A retort extends xfDocumentHit to provide advanced functionality. 
     11 * A retort extends xfDocument to provide advanced functionality. 
    1212 * 
    1313 * @package sfSearch 
     
    2020   * Determines if this retort can in fact respond. 
    2121   * 
    22    * @param xfDocumentHit $result The result 
     22   * @param xfDocument $doc The result 
    2323   * @param string $method The method called 
    2424   * @param array $args The args passed (optional) 
    2525   * @returns mixed The retort response 
    2626   */ 
    27   public function can(xfDocumentHit $result, $method, array $args = array()); 
     27  public function can(xfDocument $doc, $method, array $args = array()); 
    2828 
    2929  /** 
    3030   * Generates a response for this retort 
    3131   * 
    32    * @param xfDocumentHit $result The result 
     32   * @param xfDocument $doc The result 
    3333   * @param string $method The method called 
    3434   * @param array $args The args passed (optional) 
    3535   * @returns mixed The retort response 
    3636   */ 
    37   public function respond(xfDocumentHit $result, $method, array $args = array()); 
     37  public function respond(xfDocument $doc, $method, array $args = array()); 
    3838} 
  • plugins/sfSearchPlugin/trunk/lib/result/xfRetortField.class.php

    r8175 r10237  
    3131   * @see xfRetort 
    3232   */ 
    33   public function can(xfDocumentHit $result, $method, array $args = array()) 
     33  public function can(xfDocument $doc, $method, array $args = array()) 
    3434  { 
    3535    if (substr($method, 0, 3) == 'get') 
     
    3737      $field = $this->normalize($method); 
    3838 
    39       return $result->getDocument()->hasField($field); 
     39      return $doc->hasField($field); 
    4040    } 
    4141 
     
    4646   * @see xfRetort 
    4747   */ 
    48   public function respond(xfDocumentHit $result, $method, array $args = array()) 
     48  public function respond(xfDocument $doc, $method, array $args = array()) 
    4949  { 
    5050    $field = $this->normalize($method); 
    5151 
    52     return $result->getDocument()->getField($field)->getValue(); 
     52    return $doc->getField($field)->getValue(); 
    5353  } 
    5454 
  • plugins/sfSearchPlugin/trunk/lib/result/xfRetortFilter.class.php

    r8175 r10237  
    6565   * @see xfRetort 
    6666   */ 
    67   public function can(xfDocumentHit $hit, $method, array $args = array()) 
     67  public function can(xfDocument $doc, $method, array $args = array()) 
    6868  { 
    69     return $this->retort->can($hit, $method, $args); 
     69    return $this->retort->can($doc, $method, $args); 
    7070  } 
    7171 
     
    7373   * @see xfRetort 
    7474   */ 
    75   public function respond(xfDocumentHit $hit, $method, array $args = array()) 
     75  public function respond(xfDocument $doc, $method, array $args = array()) 
    7676  { 
    77     $response = $this->retort->respond($hit, $method, $args); 
     77    $response = $this->retort->respond($doc, $method, $args); 
    7878 
    7979    foreach ($this->filters as $filter) 
     
    8181      if ($filter instanceof xfRetortFilterCallback) 
    8282      { 
    83         $response = $filter->filter($response, $hit, $method, $args); 
     83        $response = $filter->filter($response, $doc, $method, $args); 
    8484      } 
    8585      elseif (is_callable($filter)) 
  • plugins/sfSearchPlugin/trunk/lib/result/xfRetortFilterCallback.interface.php

    r8175 r10237  
    2121   * 
    2222   * @param string $response 
    23    * @param xfDocumentHit $hit 
     23   * @param xfDocument $doc 
    2424   * @param string $method 
    2525   * @param array $args 
    2626   * @returns string 
    2727   */ 
    28   public function filter($response, xfDocumentHit $hit, $method, array $args = array()); 
     28  public function filter($response, xfDocument $doc, $method, array $args = array()); 
    2929} 
  • plugins/sfSearchPlugin/trunk/lib/result/xfRetortRoute.class.php

    r8545 r10237  
    6464   * @see xfRetort 
    6565   */ 
    66   public function can(xfDocumentHit $hit, $method, array $args = array()) 
     66  public function can(xfDocument $doc, $method, array $args = array()) 
    6767  { 
    6868    return $this->method == $method; 
     
    7272   * @see xfRetort 
    7373   */ 
    74   public function respond(xfDocumentHit $hit, $method, array $args = array()) 
     74  public function respond(xfDocument $doc, $method, array $args = array()) 
    7575  { 
    7676    $route = $this->template; 
     
    7878    foreach ($this->matches as $match) 
    7979    { 
    80       $route = str_replace('$' . $match . '$', $hit->getDocument()->getField($match)->getValue(), $route); 
     80      $route = str_replace('$' . $match . '$', $doc->getField($match)->getValue(), $route); 
    8181    } 
    8282 
  • plugins/sfSearchPlugin/trunk/test/functional/xfResultsTest.php

    r9405 r10237  
    1717class TitleRetort implements xfRetort 
    1818{ 
    19   public function can(xfDocumentHit $hit, $method, array $args = array()) 
     19  public function can(xfDocument $doc, $method, array $args = array()) 
    2020  { 
    2121    return $method == 'getTitle'; 
    2222  } 
    2323 
    24   public function respond(xfDocumentHit $hit, $method, array $args = array()) 
     24  public function respond(xfDocument $doc, $method, array $args = array()) 
    2525  { 
    26     return 'Title' . $hit->getDocument()->getField('input')->getValue(); 
     26    return 'Title' . $doc->getField('input')->getValue(); 
    2727  } 
    2828} 
     
    3030class DescriptionRetort implements xfRetort 
    3131{ 
    32   public function can(xfDocumentHit $hit, $method, array $args = array()) 
     32  public function can(xfDocument $doc, $method, array $args = array()) 
    3333  { 
    3434    return $method == 'getDescription'; 
    3535  } 
    3636 
    37   public function respond(xfDocumentHit $hit, $method, array $args = array()) 
     37  public function respond(xfDocument $doc, $method, array $args = array()) 
    3838  { 
    39     return 'Description' . $hit->getDocument()->getField('input')->getValue(); 
     39    return 'Description' . $doc->getField('input')->getValue(); 
    4040  } 
    4141} 
  • plugins/sfSearchPlugin/trunk/test/mock/result/xfMockRetort.class.php

    r8103 r10237  
    2121  public $can = true, $response = 42; 
    2222 
    23   public function can(xfDocumentHit $result, $method, array $args = array()) 
     23  public function can(xfDocument $result, $method, array $args = array()) 
    2424  { 
    2525    return $this->can; 
    2626  } 
    2727 
    28   public function respond(xfDocumentHit $result, $method, array $args = array()) 
     28  public function respond(xfDocument $result, $method, array $args = array()) 
    2929  { 
    3030    return $this->response; 
  • plugins/sfSearchPlugin/trunk/test/mock/result/xfMockRetortFilterCallback.class.php

    r8329 r10237  
    1212class xfMockRetortFilterCallback implements xfRetortFilterCallback 
    1313{ 
    14   public function filter($response, xfDocumentHit $hit, $method, array $args = array()) 
     14  public function filter($response, xfDocument $hit, $method, array $args = array()) 
    1515  { 
    1616    return md5($response); 
  • plugins/sfSearchPlugin/trunk/test/unit/result/xfRetortFieldTest.php

    r8329 r10237  
    1212require 'result/xfRetort.interface.php'; 
    1313require 'result/xfRetortField.class.php'; 
    14 require 'result/xfDocumentHit.class.php'; 
    1514require 'document/xfDocument.class.php'; 
    1615require 'document/xfField.class.php'; 
    1716require 'document/xfFieldValue.class.php'; 
    18 require 'mock/criteria/xfMockCriterionImplementer.class.php'; 
    1917 
    2018$doc = new xfDocument('guid'); 
    2119$doc->addField(new xfFieldValue(new xfField('name', xfField::KEYWORD), 'carl')); 
    22 $hit = new xfDocumentHit($doc, new xfMockCriterionImplementer); 
    2320 
    2421$t = new lime_test(4, new lime_output_color); 
     
    2724 
    2825$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'); 
    3229 
    3330$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  
    1313require 'result/xfRetortFilter.class.php'; 
    1414require 'result/xfRetortFilterCallback.interface.php'; 
    15 require 'result/xfDocumentHit.class.php'; 
    1615require 'result/xfResultException.class.php'; 
    1716require 'mock/result/xfMockRetort.class.php'; 
    1817require 'mock/result/xfMockRetortFilterCallback.class.php'; 
    1918require 'document/xfDocument.class.php'; 
    20 require 'mock/criteria/xfMockCriterionImplementer.class.php'; 
    2119 
    22 $hit = new xfDocumentHit(new xfDocument('guid'), new xfMockCriterionImplementer); 
     20$doc = new xfDocument('guid'); 
    2321 
    2422$t = new lime_test(6, new lime_output_color); 
     
    2725$wrapped = new xfMockRetort; 
    2826$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'); 
    3028$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'); 
    3230 
    3331$t->diag('->respond() - no callable'); 
    3432$wrapped = new xfMockRetort; 
    3533$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'); 
    3735 
    3836$t->diag('->respond() - php callable'); 
    3937$retort->registerFilter('md5'); 
    4038$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'); 
    4240 
    4341$t->diag('->respond() - xfRetortFilterCallback callable'); 
     
    4543$retort = new xfRetortFilter($wrapped); 
    4644$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'); 
    4846 
    4947$t->diag('->registerFilter() - invalid callable'); 
  • plugins/sfSearchPlugin/trunk/test/unit/result/xfRetortRouteTest.php

    r8545 r10237  
    1111require 'result/xfRetort.interface.php'; 
    1212require 'result/xfRetortRoute.class.php'; 
    13 require 'result/xfDocumentHit.class.php'; 
    1413require 'document/xfDocument.class.php'; 
    1514require 'document/xfField.class.php'; 
    1615require 'document/xfFieldValue.class.php'; 
    17 require 'mock/criteria/xfMockCriterionImplementer.class.php'; 
    1816 
    1917$doc = new xfDocument('guid'); 
    2018$doc->addField(new xfFieldValue(new xfField('isbn', xfField::KEYWORD), '1234567890')); 
    2119$doc->addField(new xfFieldValue(new xfField('id', xfField::KEYWORD), '42')); 
    22 $hit = new xfDocumentHit($doc, new xfMockCriterionImplementer); 
    2320 
    2421$t = new lime_test(5, new lime_output_color); 
     
    2724 
    2825$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'); 
    3128 
    3229$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'); 
    3431 
    3532$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'); 
    3734 
    3835$t->diag('->setMethod()'); 
    3936$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');