svn: /pear2/sandbox/SimpleChannelFrontend/trunk/src/SimpleChannelFrontend/ Search.php

From: Date: Fri, 25 Jun 2010 22:11:57 +0000
Subject: svn: /pear2/sandbox/SimpleChannelFrontend/trunk/src/SimpleChannelFrontend/ Search.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-9539@lists.php.net to get a copy of this message
gauthierm Fri, 25 Jun 2010 22:11:57 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=300756 Log: Allow counting search results and don't fail when an empty search string is used. Changed paths: U pear2/sandbox/SimpleChannelFrontend/trunk/src/SimpleChannelFrontend/Search.php Modified: pear2/sandbox/SimpleChannelFrontend/trunk/src/SimpleChannelFrontend/Search.php =================================================================== --- pear2/sandbox/SimpleChannelFrontend/trunk/src/SimpleChannelFrontend/Search.php 2010-06-25 22:10:05 UTC (rev 300755) +++ pear2/sandbox/SimpleChannelFrontend/trunk/src/SimpleChannelFrontend/Search.php 2010-06-25 22:11:57 UTC (rev 300756) @@ -1,24 +1,41 @@ -<?php +<?php + namespace PEAR2\SimpleChannelFrontend; use PEAR2\Pyrus\Channel; -class Search extends \FilterIterator +class Search extends \FilterIterator implements \Countable { public $query; - function __construct($options = array()) + public function __construct($options = array()) { - if (isset($options['q'])) { $this->query = $options['q']; } - parent::__construct(new \PEAR2\Pyrus\Channel\RemotePackages(Main::$channel)); + parent::__construct( + new \PEAR2\Pyrus\Channel\RemotePackages(Main::$channel) + ); } - function accept() + public function accept() { - return (bool)stristr($this->current()->name, $this->query); + if ($this->query == '') { + $accept = false; + } else { + $accept = (bool)stristr($this->current()->name, $this->query); + } + + return $accept; } -} \ No newline at end of file + public function count() + { + $count = 0; + foreach ($this as $package) { + $count++; + } + return $count; + } + +}

« previous php.pear.core (#9539) next »