| Server IP : 213.186.33.4 / Your IP : 216.73.216.193 Web Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : awebpaca ( 35430) PHP Version : 8.5.0 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/awebpaca/blog/libraries/kunena/collection/ |
Upload File : |
<?php
/**
* Kunena Component
* @package Kunena.Framework
* @subpackage Collection
*
* @copyright (C) 2008 - 2018 Kunena Team. All rights reserved.
* @license https://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
**/
defined('_JEXEC') or die();
/**
* Kunena Item Collection.
*/
class KunenaCollection implements ArrayAccess, Countable, IteratorAggregate
{
/**
* The items in the collection.
*
* @var array
*/
protected $items = array();
/**
* Create a new collection.
*
* @param array $items Initial items to be added into the collection.
*/
public function __construct(array $items = array())
{
$this->items = $items;
}
/**
* Get all items in the collection.
*
* @return array
*/
public function all()
{
return $this->items;
}
/**
* Get the first item from the collection.
*
* @return mixed|null
*/
public function first()
{
return !empty($this->items) ? reset($this->items) : null;
}
/**
* Get the last item from the collection.
*
* @return mixed|null
*/
public function last()
{
return !empty($this->items) ? end($this->items) : null;
}
/**
* Run a filter over each of the items.
*
* @param Closure $callback
*
* @return KunenaCollection
*/
public function filter(Closure $callback)
{
return new static(array_filter($this->items, $callback));
}
/**
* Execute a callback over each item.
*
* @param Closure $callback
*
* @return KunenaCollection
*/
public function each(Closure $callback)
{
array_map($callback, $this->items);
return $this;
}
/**
* Run a map over each of the items.
*
* @param Closure $callback
*
* @return KunenaCollection
*/
public function map(Closure $callback)
{
return new static(array_map($callback, $this->items, array_keys($this->items)));
}
/**
* Get an iterator for the items.
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->items);
}
/**
* Count the number of items in the collection.
*
* @return integer
*/
public function count()
{
return count($this->items);
}
/**
* Determine if an item exists at an offset.
*
* @param mixed $key
* @return boolean
*/
public function offsetExists($key)
{
return array_key_exists($key, $this->items);
}
/**
* Get an item at a given offset.
*
* @param mixed $key
* @return mixed
*/
public function offsetGet($key)
{
return $this->items[$key];
}
/**
* Set the item at a given offset.
*
* @param mixed $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value)
{
if (is_null($key))
{
$this->items[] = $value;
}
else
{
$this->items[$key] = $value;
}
}
/**
* Unset the item at a given offset.
*
* @param string $key
* @return void
*/
public function offsetUnset($key)
{
unset($this->items[$key]);
}
}