[Xapian-discuss] Another PHP 5 wrapper...

Paul Dixon lordelph at gmail.com
Sun Apr 16 08:54:22 BST 2006


> OK, I've reworked it...here's the wrapper file it produces for Xapian
> (renamed to .phps so you can view it!):
>
> http://www.oligarchy.co.uk/xapian/patches/xapian.phps
>

Looks great!

I've been wondering how best to add Iterator support to those
auto-generated classes. Perhaps the cleanest way is to have a separate
file which extends the generated classes, e.g.

/* override "begin" methods to return an object
  which supports the Iterator interface */
PHP5XapianDocument extends XapianDocument
{
	function termlist_begin()
	{
		$begin=Document_termlist_begin($this->swig_ptr);
    	        $end=Document_termlist_end($this->swig_ptr);
    	        return new PHP5TermIterator($begin,$end);
	}
}

class PHP5TermIterator extends XapianTermIterator implements Iterator
{
        /* extension of XapianTermIterator implementing the
           Iterator interface */
}

This is similar to the approach I adopted in the wrapper I wrote
(http://blog.dixo.net/2006/04/04/xapian-php5-wrapper/). Doing it this
way allows these specifics to remain hand-coded in a separate file,
but with the benefits of auto-generation of everything else.

Paul



More information about the Xapian-discuss mailing list