Location: PHPKode > projects > Mocovie web framework > webs/common/controls/dataprovider.php
<?php
/**
 *  Copyright (C) 2010  Kai Dorschner
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Kai Dorschner <the-hide@address.com>
 * @copyright Copyright 2010, Kai Dorschner
 * @license http://www.gnu.org/licenses/gpl.html GPLv3
 * @package mocovi
 * @subpackage controls
 */

//class_exists('Delegate') or require $GLOBALS['library'].'Delegate.php';

//interface DataproviderDelegate extends Delegate {}
/**
 * Generic data provider.
 *
 * Provides methods to deliver data to higher instances (i.e. dataprocessors)
 *
 * @package mocovi
 * @subpackage controls
 * @abstract
 */
abstract class dataprovider_control extends Control implements /*DataproviderDelegate,*/ Iterator
{
	/*protected $delegate		= null;*/
	protected $data				= array();
	protected $defaultOptions	= array();

	/**
	 * This method allows you to define a delegate object which executes methods when data is provided
	 *
	 * @access public
	 * @return void
	 * @param DataproviderDelegate $delegate
	 * @deprecated
	 */
	/*
	public function setDelegate(DataproviderDelegate $delegate)
	{
		$this->delegate = $delegate;
	}
	*/

	/**
	 * Returns the value of a key.
	 *
	 * @access public
	 * @return mixed
	 * @param string $key
	 */
	public function get($key = null)
	{
		if($key)
		{
			if(isset($this->data[$key]))
				return $this->data[$key];
			else
				return null;
		}
		return $this->data;
	}


	/* Iterator methods*/

	public function rewind()
	{
		reset($this->data);
	}

	public function current()
	{
		return current($this->data);
	}

	public function key() 
	{
		return key($this->data);
	}

	public function next() 
	{
		return next($this->data);
	}

	public function valid()
	{
		$key = key($this->data);
		return ($key !== NULL && $key !== FALSE);
	}
}
Return current item: Mocovie web framework