Changeset 8994
- Timestamp:
- 05/16/08 05:03:11 (2 months ago)
- Files:
-
- plugins/sfHighlightPlugin/trunk/lib/highlight/xfHighlightToken.class.php (modified) (3 diffs)
- plugins/sfHighlightPlugin/trunk/lib/highlight/xfHighlighter.class.php (modified) (1 diff)
- plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReader.interface.php (modified) (1 diff)
- plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReaderDOM.class.php (modified) (1 diff)
- plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReaderString.class.php (modified) (1 diff)
- plugins/sfHighlightPlugin/trunk/lib/search (added)
- plugins/sfHighlightPlugin/trunk/lib/search/xfHighlightRetortFilterCallback.class.php (added)
- plugins/sfHighlightPlugin/trunk/lib/search/xfHighlightTokenizerCriterionImplementer.class.php (added)
- plugins/sfHighlightPlugin/trunk/lib/tokenizer/xfHighlightTokenizer.interface.php (modified) (1 diff)
- plugins/sfHighlightPlugin/trunk/test/bootstrap/unit.php (modified) (1 diff)
- plugins/sfHighlightPlugin/trunk/test/unit/highlight/xfHighlighterTest.php (modified) (2 diffs)
- plugins/sfHighlightPlugin/trunk/test/unit/search (added)
- plugins/sfHighlightPlugin/trunk/test/unit/search/xfHighlightRetortFilterCallbackTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfHighlightPlugin/trunk/lib/highlight/xfHighlightToken.class.php
r8890 r8994 8 8 */ 9 9 10 // create an xfTokenInterface if unavailable from sfSearch 11 // this is neccessary to remove the dependency on sfSearch 12 if (!interface_exists('xfTokenInterface', true)) 13 { 14 /** 15 * Token interface to achieve duck typing 16 * 17 * @package sfHighlight 18 * @subpackage Highlight 19 * @author Carl Vondrick 20 * @see sfSearch's xfTokenInterface 21 */ 22 interface xfTokenInterface 23 { 24 } 25 } 26 10 27 /** 11 28 * The highlight token. … … 15 32 * @author Carl Vondrick 16 33 */ 17 final class xfHighlightToken 34 final class xfHighlightToken implements xfTokenInterface 18 35 { 19 36 /** … … 95 112 * System to sort the tokens 96 113 * 97 * @param xf HighlightToken$a98 * @param xf HighlightToken$b114 * @param xfTokenInterface $a 115 * @param xfTokenInterface $b 99 116 * @returns int The sort code for usort 100 117 */ 101 static public function getSortCode(xf HighlightToken $a, xfHighlightToken$b)118 static public function getSortCode(xfTokenInterface $a, xfTokenInterface $b) 102 119 { 103 120 if ($a->getStart() < $b->getStart()) plugins/sfHighlightPlugin/trunk/lib/highlight/xfHighlighter.class.php
r8890 r8994 56 56 } 57 57 } 58 58 59 59 /** 60 60 * Does the highlighting on the reader. plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReader.interface.php
r8890 r8994 32 32 * Replaces a token with the new text in the correct text. 33 33 * 34 * @param xf HighlightToken$token34 * @param xfTokenInterface $token 35 35 * @param string $new 36 36 */ 37 public function replaceText(xf HighlightToken$token, $new);37 public function replaceText(xfTokenInterface $token, $new); 38 38 } 39 39 plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReaderDOM.class.php
r8890 r8994 114 114 * @see xfHighlightReader 115 115 */ 116 public function replaceText(xf HighlightToken$token, $replacement)116 public function replaceText(xfTokenInterface $token, $replacement) 117 117 { 118 118 $node = $this->texts[$this->position]; plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReaderString.class.php
r8890 r8994 67 67 * @see xfHighlightReader 68 68 */ 69 public function replaceText(xf HighlightToken$token, $new)69 public function replaceText(xfTokenInterface $token, $new) 70 70 { 71 71 $newText = substr($this->text, 0, $token->getStart()); plugins/sfHighlightPlugin/trunk/lib/tokenizer/xfHighlightTokenizer.interface.php
r8890 r8994 18 18 { 19 19 /** 20 * Tokenizes the text and returns an array of xf HighlightToken-s20 * Tokenizes the text and returns an array of xfTokenInterface 21 21 * 22 22 * @param string $text The text to tokenize 23 * @returns array of xf HighlightToken23 * @returns array of xfTokenInterface 24 24 */ 25 25 public function tokenize($text); plugins/sfHighlightPlugin/trunk/test/bootstrap/unit.php
r8890 r8994 8 8 */ 9 9 10 define('SF_LIB_DIR', '/home/carl/symfony/1.1/lib');10 require dirname(__FILE__) . '/../../../sfSearchPlugin/test/bootstrap/unit.php'; 11 11 12 set_include_path(get_include_path() . PATH_SEPARATOR . SF_LIB_DIR);13 12 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib'); 14 13 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../test'); 15 14 16 require 'vendor/lime/lime.php';plugins/sfHighlightPlugin/trunk/test/unit/highlight/xfHighlighterTest.php
r8890 r8994 20 20 require 'reader/xfHighlightReaderString.class.php'; 21 21 22 $t = new lime_test( 2, new lime_output_color);22 $t = new lime_test(3, new lime_output_color); 23 23 24 24 $keywords = array( … … 33 33 34 34 $t->isa_ok($reader, 'xfHighlightReaderString', '->highlight() returns a xfHighlightReader'); 35 $t->is($reader->getText(), 'FOO is better than BAR if only because of the small amount of [baz]', '->highlight() highlights the string according to the reader and keywords'); 35 36 36 $t->is($ reader->getText(), 'FOO is better than BAR if only because of the small amount of [baz]', '->highlight() highlights the string according to the reader and keywords');37 $t->is($h->highlight(new xfHighlightReaderString('baz! bow before baz for i am baz'))->getText(), '[baz]! bow before [baz] for i am [baz]', '->highlight() works with changing string length');