public function testTextManager() { $texts = json_decode('[ { "afs:t": "KwicString", "text" : "string" }, { "afs:t": "KwicMatch", "match": "match" }, { "afs:t": "KwicString", "text" : "str" }, { "afs:t": "KwicMatch", "match": "mat" }, { "afs:t": "KwicString", "text" : "s" }, { "afs:t": "KwicTruncate" } ]'); $mgr = new AfsTextManager($texts); $visitor = new Visitor(); $this->assertTrue($mgr->visit_text($visitor) == '<s>string</s><m>match</m><s>str</s><m>mat</m><s>s</s><t>...</t>'); }
/** @internal * @brief Common acces for title and abstract reply formatter. * @param $json_text [in] appropriate text block (title/abstract) in JSON * format. * @return formatted text. */ protected function get_text($json_text) { $text_mgr = new AfsTextManager($json_text); return $text_mgr->visit_text($this->visitor); }
/** @brief Same result as @a get_value method * * @param $name [in] name of the first element to retrieve (default=null, * all JSON content is returned as text). Empty string allows to * retrieve text content correctly formatted when highlight is * activated. * @param $unused Hum... * @param $visitor [in] instance of @a AfsTextVisitorInterface used to format * appropriately text content when highlight has been activated * (default=null, @a AfsTextVisitor is used). * * @return formatted text. * * @throws AfsNoResultException when required JSON element is not defined. */ public function get_values($name = null, $unused = array(), $visitor = null) { if (is_null($visitor)) { $visitor = new AfsTextVisitor(); } $contents = $this->client_data->contents; if (is_null($name)) { return json_encode($contents); } else { if (!is_array($contents)) { if (property_exists($contents, $name)) { $text_mgr = new AfsTextManager($contents->{$name}); } else { throw new AfsNoResultException('No client data content named: ' . $name); } } else { $text_mgr = new AfsTextManager($contents); } return $text_mgr->visit_text($visitor); } }