Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P2120
ConduitIterator.php
Active
Public
Actions
Authored by
joshuaspence
on Jul 18 2019, 10:33 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F6602178: raw.txt
Jul 18 2019, 10:33 PM
2019-07-18 22:33:06 (UTC+0)
Subscribers
None
<?php
final
class
ConduitIterator
implements
Iterator
{
private
$client
;
private
$method
;
private
$parameters
;
private
$current
;
private
$cursor
;
public
function
__construct
(
ConduitClient
$client
,
string
$method
,
array
$parameters
)
{
$this
->
client
=
$client
;
$this
->
method
=
$method
;
$this
->
parameters
=
$parameters
;
}
private
function
execute
():
void
{
$parameters
=
$this
->
parameters
;
if
(
$this
->
cursor
!==
null
)
{
$parameters
[
'after'
]
=
$this
->
cursor
[
'after'
];
}
$response
=
$this
->
client
->
callMethodSynchronous
(
$this
->
method
,
$parameters
);
$this
->
current
=
new
ArrayIterator
(
$response
[
'data'
]);
$this
->
cursor
=
$response
[
'cursor'
];
}
private
function
getResults
():
ArrayIterator
{
if
(
$this
->
current
===
null
)
{
$this
->
execute
();
}
return
$this
->
current
;
}
/* -( Iterator )----------------------------------------------------------- */
public
function
current
()
{
return
$this
->
getResults
()->
current
();
}
public
function
key
()
{
return
$this
->
getResults
()->
key
();
}
public
function
next
():
void
{
$this
->
getResults
()->
next
();
}
public
function
rewind
():
void
{
$this
->
current
=
null
;
$this
->
cursor
=
null
;
}
public
function
valid
():
bool
{
$valid
=
$this
->
getResults
()->
valid
();
if
(!
$valid
)
{
if
(
$this
->
cursor
[
'after'
]
===
null
)
{
return
false
;
}
$this
->
execute
();
return
true
;
}
return
$valid
;
}
}
Event Timeline
joshuaspence
created this paste.
Jul 18 2019, 10:33 PM
2019-07-18 22:33:06 (UTC+0)
Log In to Comment