Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99309721
PhutilChunkedIterator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jan 23, 08:25
Size
1 KB
Mime Type
text/x-php
Expires
Sat, Jan 25, 08:25 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23774071
Attached To
rPHU libphutil
PhutilChunkedIterator.php
View Options
<?php
/**
* This is an iterator version of array_chunk().
*/
final
class
PhutilChunkedIterator
implements
Iterator
{
private
$iterator
;
private
$size
;
private
$key
=
0
;
private
$current
;
/**
* @param Iterator
* @param int
*/
public
function
__construct
(
Iterator
$iterator
,
$size
)
{
$this
->
iterator
=
$iterator
;
$this
->
size
=
$size
;
}
public
function
rewind
()
{
$this
->
iterator
->
rewind
();
$this
->
next
();
$this
->
key
=
0
;
}
/**
* @return int
*/
public
function
key
()
{
return
$this
->
key
;
}
/**
* @return array
*/
public
function
current
()
{
return
$this
->
current
;
}
public
function
next
()
{
$this
->
current
=
array
();
while
(
$this
->
iterator
->
valid
())
{
$key
=
$this
->
iterator
->
key
();
$this
->
current
[
$key
]
=
$this
->
iterator
->
current
();
$this
->
iterator
->
next
();
if
(
count
(
$this
->
current
)
>=
$this
->
size
)
{
break
;
}
}
$this
->
key
++;
}
public
function
valid
()
{
return
(
bool
)
$this
->
current
;
}
}
Event Timeline
Log In to Comment