Development

Changeset 15476

You must first sign up to be able to contribute.

Changeset 15476

Show
Ignore:
Timestamp:
02/13/09 10:13:32 (4 years ago)
Author:
garak
Message:

refactored main class, now it's using exceptions instead of returning false

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSphinxPlugin/trunk/README

    r15426 r15476  
    100100 
    101101    <?php $res = $pager->getResults() ?> 
    102     <?php if ($sphinx->getLastError()): ?> 
    103     Error: <?php echo $sphinx->getLastError() ?> 
    104     <?php elseif (empty($res)): ?> 
     102    <?php if (empty($res)): ?> 
    105103    No result matches your query 
    106104    <?php else: ?> 
  • plugins/sfSphinxPlugin/trunk/lib/sfSphinxClient.class.php

    r15436 r15476  
    293293 
    294294  /** 
     295   * check if there's an error or not 
     296   * @return string 
     297   */ 
     298  public function isError() 
     299  { 
     300    return !empty($this->error); 
     301  } 
     302 
     303  /** 
    295304   * get last error message 
    296305   * @return string 
     
    324333   * connect to searchd server 
    325334   * @return resource 
     335   * @throws Exception 
    326336   */ 
    327337  protected function Connect() 
     
    341351      $errstr = trim($errstr); 
    342352      $this->error = "connection to {$this->host}:{$this->port} failed (errno=$errno, msg=$errstr)"; 
    343      return false
     353      throw new Exception($this->error)
    344354    } 
    345355 
     
    351361      fclose($fp); 
    352362      $this->error = "expected searchd protocol version 1+, got version '$v'"; 
    353      return false
     363      throw new Exception($this->error)
    354364    } 
    355365 
     
    364374   * @param  integer  $client_ver 
    365375   * @return string 
     376   * @throws Exception 
    366377   */ 
    367378  protected function GetResponse($fp, $client_ver) 
     
    389400        ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)" 
    390401        : 'received zero-sized searchd response'; 
    391       return false
     402      throw new Exception($this->error)
    392403    } 
    393404 
     
    396407    { 
    397408      $this->error = 'searchd error: ' . substr($response, 4); 
    398       return false
     409      throw new Exception($this->error)
    399410    } 
    400411    if ($status == self::SEARCHD_RETRY) 
    401412    { 
    402413      $this->error = 'temporary searchd error: ' . substr($response, 4); 
    403       return false
     414      throw new Exception($this->error)
    404415    } 
    405416    if ($status != self::SEARCHD_OK) 
    406417    { 
    407418      $this->error = "unknown status code '$status'"; 
    408       return false
     419      throw new Exception($this->error)
    409420    } 
    410421 
     
    662673   *                          'words' 
    663674   *                            hash which maps query terms (stemmed!) to ('docs', 'hits') hash 
     675   * @throws Exception 
    664676   */ 
    665677  public function Query($query, $index = '*', $comment = '') 
     
    670682    { 
    671683      // probably network error; error message should be already filled 
    672       return $this->res = false
     684      throw new Exception($this->error)
    673685    } 
    674686    $this->error = $results[0]['error']; 
     
    676688    if ($results[0]['status'] == self::SEARCHD_ERROR) 
    677689    { 
    678       return $this->res = false
     690      throw new Exception($this->error)
    679691    } 
    680692    else 
    681693    { 
    682       return $this->res = $results[0]; 
     694      $this->res = $results[0]; 
     695      return $this->res; 
    683696    } 
    684697  } 
     
    702715    { 
    703716      $this->error = 'no queries defined, issue AddQuery() first'; 
    704       return false
     717      throw new Exception($this->error)
    705718    } 
    706719 
     
    711724    { 
    712725      $this->MBPop(); 
    713       return false
     726      throw new Exception($this->error)
    714727    } 
    715728 
     
    726739    { 
    727740      $this->MBPop(); 
    728       return false
     741      throw new Exception($this->error)
    729742    } 
    730743 
     
    934947   *                        'around' 
    935948   *                          how much words to highlight around each match, default is 5 
    936    * @return array        strings of excerpts, or false in case of failure 
     949   * @return array        strings of excerpts 
     950   * @throws Exception 
    937951   */ 
    938952  public function BuildExcerpts($docs, $index, $words, $opts = array()) 
     
    943957    { 
    944958      $this->MBPop(); 
    945       return false
     959      throw new Exception($this->error)
    946960    } 
    947961 
     
    9931007    { 
    9941008      $this->MBPop(); 
    995       return false
     1009      throw new Exception($this->error)
    9961010    } 
    9971011 
     
    10101024        $this->error = 'incomplete reply'; 
    10111025        $this->MBPop(); 
    1012         return false
     1026        throw new Exception($this->error)
    10131027      } 
    10141028      $res[] = substr($response, $pos, $len); 
     
    10261040   * @param  boolean $hits 
    10271041   * @return array 
     1042   * @throws Exception 
    10281043   */ 
    10291044  public function BuildKeywords($query, $index, $hits) 
     
    10341049    { 
    10351050      $this->MBPop(); 
    1036       return false
     1051      throw new Exception($this->error)
    10371052    } 
    10381053 
     
    10521067    { 
    10531068      $this->MBPop(); 
    1054       return false
     1069      throw new Exception($this->error)
    10551070    } 
    10561071 
     
    10881103        $this->error = 'incomplete reply'; 
    10891104        $this->MBPop(); 
    1090         return false
     1105        throw new Exception($this->error)
    10911106      } 
    10921107    }