Server : LiteSpeed System : Linux server 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : alsaif ( 1057) PHP Version : 7.4.33 Disable Function : show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/alsaif/public_html/libraries/vendor/joomla/compat/src/ |
<?php
/**
* Part of the Joomla Framework Compat Package
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
/**
* CallbackFilterIterator using the callback to determine which items are accepted or rejected.
*
* @link http://php.net/manual/en/class.callbackfilteriterator.php
* @since 1.2.0
*/
class CallbackFilterIterator extends \FilterIterator
{
/**
* The callback to check value.
*
* @var callable
*
* @since 1.2.0
*/
protected $callback = null;
/**
* Creates a filtered iterator using the callback to determine
* which items are accepted or rejected.
*
* @param \Iterator $iterator The iterator to be filtered.
* @param callable $callback The callback, which should return TRUE to accept the current item
* or FALSE otherwise. May be any valid callable value.
* The callback should accept up to three arguments: the current item,
* the current key and the iterator, respectively.
* ``` php
* function my_callback($current, $key, $iterator)
* ```
*
* @throws InvalidArgumentException
*
* @since 1.2.0
*/
public function __construct(\Iterator $iterator, $callback)
{
if (!is_callable($callback))
{
throw new \InvalidArgumentException("Argument 2 of CallbackFilterIterator should be callable.");
}
$this->callback = $callback;
parent::__construct($iterator);
}
/**
* This method calls the callback with the current value, current key and the inner iterator.
* The callback is expected to return TRUE if the current item is to be accepted, or FALSE otherwise.
*
* @link http://www.php.net/manual/en/callbackfilteriterator.accept.php
*
* @return boolean True if the current element is acceptable, otherwise false.
*
* @since 1.2.0
*/
public function accept()
{
$inner = $this->getInnerIterator();
return call_user_func_array(
$this->callback,
array(
$inner->current(),
$inner->key(),
$inner
)
);
}
}