mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
parent
b2dafe9e5e
commit
0b7afb5b7b
438 changed files with 6049 additions and 5203 deletions
183
rainloop/v/1.3.10.490/app/libraries/MailSo/Base/Collection.php
Normal file
183
rainloop/v/1.3.10.490/app/libraries/MailSo/Base/Collection.php
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
|
||||
namespace MailSo\Base;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Base
|
||||
*/
|
||||
abstract class Collection
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $aItems;
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
$this->aItems = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mItem
|
||||
* @param bool $bToTop = false
|
||||
* @return self
|
||||
*/
|
||||
public function Add($mItem, $bToTop = false)
|
||||
{
|
||||
if ($bToTop)
|
||||
{
|
||||
\array_unshift($this->aItems, $mItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
\array_push($this->aItems, $mItem);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aItems
|
||||
* @return self
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function AddArray($aItems)
|
||||
{
|
||||
if (!\is_array($aItems))
|
||||
{
|
||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
|
||||
}
|
||||
|
||||
foreach ($aItems as $mItem)
|
||||
{
|
||||
$this->Add($mItem);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public function Clear()
|
||||
{
|
||||
$this->aItems = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function CloneAsArray()
|
||||
{
|
||||
return $this->aItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function Count()
|
||||
{
|
||||
return \count($this->aItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function &GetAsArray()
|
||||
{
|
||||
return $this->aItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mCallback
|
||||
*/
|
||||
public function MapList($mCallback)
|
||||
{
|
||||
$aResult = array();
|
||||
if (\is_callable($mCallback))
|
||||
{
|
||||
foreach ($this->aItems as $oItem)
|
||||
{
|
||||
$aResult[] = \call_user_func($mCallback, $oItem);
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mCallback
|
||||
* @return array
|
||||
*/
|
||||
public function FilterList($mCallback)
|
||||
{
|
||||
$aResult = array();
|
||||
if (\is_callable($mCallback))
|
||||
{
|
||||
foreach ($this->aItems as $oItem)
|
||||
{
|
||||
if (\call_user_func($mCallback, $oItem))
|
||||
{
|
||||
$aResult[] = $oItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mCallback
|
||||
* @return void
|
||||
*/
|
||||
public function ForeachList($mCallback)
|
||||
{
|
||||
if (\is_callable($mCallback))
|
||||
{
|
||||
foreach ($this->aItems as $oItem)
|
||||
{
|
||||
\call_user_func($mCallback, $oItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed | null
|
||||
* @return mixed
|
||||
*/
|
||||
public function &GetByIndex($iIndex)
|
||||
{
|
||||
$mResult = null;
|
||||
if (\key_exists($iIndex, $this->aItems))
|
||||
{
|
||||
$mResult = $this->aItems[$iIndex];
|
||||
}
|
||||
|
||||
return $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aItems
|
||||
* @return self
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public function SetAsArray($aItems)
|
||||
{
|
||||
if (!\is_array($aItems))
|
||||
{
|
||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
|
||||
}
|
||||
|
||||
$this->aItems = $aItems;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue