recode for PHP 7.3
Dieser Commit ist enthalten in:
Ursprung
991872aeb8
Commit
0a56d9c337
|
@ -1,123 +1,86 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Project:
|
|
||||||
* Contenido Content Management System
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Iterator class
|
|
||||||
*
|
|
||||||
* Requirements:
|
|
||||||
* @con_php_req 5.0
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @package Contenido Backend classes
|
|
||||||
* @version 1.0.2
|
|
||||||
* @author unknown
|
|
||||||
* @copyright four for business AG <www.4fb.de>
|
|
||||||
* @license http://www.contenido.org/license/LIZENZ.txt
|
|
||||||
* @link http://www.4fb.de
|
|
||||||
* @link http://www.contenido.org
|
|
||||||
* @since file available since contenido release <= 4.6
|
|
||||||
*
|
|
||||||
* {@internal
|
|
||||||
* created unknown
|
|
||||||
* modified 2008-06-30, Dominik Ziegler, add security fix
|
|
||||||
*
|
|
||||||
* $Id: class.iterator.php 2 2011-07-20 12:00:48Z oldperl $:
|
|
||||||
* }}
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(!defined('CON_FRAMEWORK')) {
|
|
||||||
die('Illegal call');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cIterator: A class which represents the C/C++/JAVA Iterator support.
|
* @package Core
|
||||||
*
|
* @subpackage Util
|
||||||
* Iterating items is a mechanism to "step" trough a list of defined items.
|
* @version $Rev$
|
||||||
* Basically, the iterator is similar to an array, but provides easy functions
|
* @since 2.1
|
||||||
* to step trough the list.
|
* @author Ortwin Pinke <o.pinke@conlite.org>
|
||||||
*
|
* @copyright (c) 2019, conlite.org
|
||||||
* An instance of an iterator is usually created by a class returning multiple
|
* @license http://www.gnu.de/documents/gpl.en.html GPL v3 (english version)
|
||||||
* items and automatically filled using the $aItems parameter of the constructor,
|
* @license http://www.gnu.de/documents/gpl.de.html GPL v3 (deutsche Version)
|
||||||
* and then returned to the caller.
|
* @link http://www.conlite.org ConLite.org
|
||||||
*
|
*
|
||||||
* The caller receives the iterator object and can step trough all items using
|
* $Id:$
|
||||||
* the "next" method.
|
|
||||||
*
|
|
||||||
* @todo Add more stepping methods, as well as retrieving items
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class cIterator
|
// security check
|
||||||
{
|
defined('CON_FRAMEWORK') or die('Illegal call');
|
||||||
|
|
||||||
|
class cIterator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the items which should be iterated
|
* Holds the items which should be iterated
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $_aIteratorItems;
|
var $_aIteratorItems;
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterator constructor
|
|
||||||
*
|
|
||||||
* This function initializes the constructor, adds the passed items
|
|
||||||
* and moves the iterator to the first element.
|
|
||||||
*
|
|
||||||
* @param $aItems array Items to add
|
|
||||||
* @return none
|
|
||||||
*/
|
|
||||||
function __construct ($aItems)
|
|
||||||
{
|
|
||||||
if (is_array($aItems))
|
|
||||||
{
|
|
||||||
$this->_aIteratorItems = $aItems;
|
|
||||||
} else {
|
|
||||||
$this->_aIteratorItems = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Holds the keys of the array which should be iterated
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_aKeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param array $aItems items to add
|
||||||
|
*/
|
||||||
|
public function __construct($aItems) {
|
||||||
|
if (is_array($aItems)) {
|
||||||
|
$this->_aIteratorItems = $aItems;
|
||||||
|
} else {
|
||||||
|
$this->_aIteratorItems = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* reset: Resets the iterator to the first element
|
* reset: Resets the iterator to the first element
|
||||||
*
|
*
|
||||||
* This function moves the iterator to the first element
|
* This function moves the iterator to the first element
|
||||||
*
|
*
|
||||||
* @return none
|
* @return none
|
||||||
*/
|
*/
|
||||||
function reset ()
|
function reset() {
|
||||||
{
|
$this->_aKeys = array_keys($this->_aIteratorItems);
|
||||||
reset($this->_aIteratorItems);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* next: Returns the next item in the iterator
|
* next: Returns the next item in the iterator
|
||||||
*
|
*
|
||||||
* This function returns the item, or false if no
|
* This function returns the item, or false if no
|
||||||
* items are left.
|
* items are left.
|
||||||
*
|
*
|
||||||
* @return mixed item or false if nothing was found
|
* @return mixed item or false if nothing was found
|
||||||
*/
|
*/
|
||||||
function next ()
|
function next() {
|
||||||
{
|
$key = array_shift($this->_aKeys);
|
||||||
$item = each($this->_aIteratorItems);
|
return isset($this->_aIteratorItems[$key]) ? $this->_aIteratorItems[$key] : false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($item === false)
|
/**
|
||||||
{
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return $item["value"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* count: Returns the number of items in the iterator
|
* count: Returns the number of items in the iterator
|
||||||
*
|
*
|
||||||
* @return int Number of items
|
* @return int Number of items
|
||||||
*/
|
*/
|
||||||
function count ()
|
function count() {
|
||||||
{
|
if(is_countable($this->_aIteratorItems)) {
|
||||||
return count($this->_aIteratorItems);
|
return count($this->_aIteratorItems);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Laden…
In neuem Issue referenzieren