本文整理汇总了PHP中Iterator::key方法的典型用法代码示例。如果您正苦于以下问题:PHP Iterator::key方法的具体用法?PHP Iterator::key怎么用?PHP Iterator::key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Iterator
的用法示例。
在下文中一共展示了Iterator::key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: key
public function key(){
if ($this->innerHasItems === true){
return $this->innerIterator->key();
} else {
return $this->defaultKey;
}
}
示例2: key
/**
* Returns the key of the current value
*
* @return Mixed
*/
public function key()
{
if (!isset($this->iterator)) {
$this->getInnerIterator();
}
return $this->iterator->key();
}
示例3: subscribe
/**
* @param ObserverInterface $observer
* @param SchedulerInterface|null $scheduler
* @return \Rx\Disposable\CompositeDisposable|\Rx\DisposableInterface
*/
public function subscribe(ObserverInterface $observer, SchedulerInterface $scheduler = null)
{
$scheduler = $scheduler ?: new ImmediateScheduler();
$key = 0;
return $scheduler->scheduleRecursive(function ($reschedule) use(&$observer, &$key) {
try {
//HHVM requires you to call next() before current()
if (defined('HHVM_VERSION')) {
$this->items->next();
$key = $this->items->key();
}
if (null === $key) {
$observer->onCompleted();
return;
}
$current = $this->items->current();
$observer->onNext($current);
if (!defined('HHVM_VERSION')) {
$this->items->next();
$key = $this->items->key();
}
$reschedule();
} catch (\Exception $e) {
$observer->onError($e);
}
});
}
示例4: key
public function key()
{
if (!$this->usingCache) {
return $this->innerIterator->key();
}
return $this->position;
}
示例5: key
/**
* @return Mixed|null Returns null if out of range
*/
public function key()
{
if (!$this->baseIterator->valid()) {
return null;
// out of range
}
return $this->baseIterator->key();
}
示例6: memo
private function memo()
{
if (!$this->it->valid()) {
return;
}
array_push($this->cache, array($this->it->key(), $this->it->current()));
$this->cacheSize++;
}
示例7: fetch
private function fetch()
{
if ($this->it->valid()) {
$v = $this->it->current();
$k = $this->it->key();
$this->v = $this->valueSelector->select($v, $k);
$this->k = $this->keySelector->select($v, $k);
}
}
示例8: fetch
private function fetch()
{
if ($this->it->valid()) {
$this->v = $this->it->current();
$this->k = $this->it->key();
$fn = $this->fn;
$fn($this->v, $this->k);
}
}
示例9: nextSatisfied
private function nextSatisfied()
{
while ($this->it->valid()) {
if ($this->predicate->predicate($this->it->current(), $this->it->key())) {
break;
} else {
$this->it->next();
}
}
}
示例10: rewind
public function rewind()
{
$this->i = 0;
$this->it->rewind();
while ($this->it->valid()) {
if ($this->predicate->predicate($this->it->current(), $this->it->key())) {
$this->it->next();
} else {
break;
}
}
}
示例11: iterateAndCache
/**
* @return Generator
*/
private function iterateAndCache()
{
foreach ($this->cache as $key => $value) {
(yield $key => $value);
}
if ($this->innerIterator !== null) {
while ($this->innerIterator->valid()) {
$this->cache[$this->innerIterator->key()] = $this->innerIterator->current();
(yield $this->innerIterator->key() => $this->innerIterator->current());
$this->innerIterator->next();
}
$this->innerIterator = null;
}
}
示例12: storeNext
/**
* Internally increments the iterator and saves the value
*
* @return Boolean Returns whether the iterator returned a valid value
*/
private function storeNext()
{
if (!isset($this->iterator)) {
return FALSE;
} else {
if ($this->iterator->valid()) {
$this->cache[$this->internalOffset] = array($this->iterator->key(), $this->iterator->current());
return TRUE;
} else {
unset($this->iterator);
return FALSE;
}
}
}
示例13: solveIntermediateOperationChain
/**
* @param \Iterator $operatorChain
* @param \Iterator $input
*
* @return \ArrayIterator
*/
private function solveIntermediateOperationChain(\Iterator $operatorChain, \Iterator $input)
{
$results = new \ArrayIterator();
$input->rewind();
$continueWIthNextItem = true;
while ($input->valid() && $continueWIthNextItem) {
$result = $input->current();
$useResult = true;
// do the whole intermediate operation chain for the current input
$operatorChain->rewind();
while ($operatorChain->valid() && $useResult) {
/** @var IntermediateOperationInterface $current */
$current = $operatorChain->current();
// apply intermediate operations
$result = $current->apply($result, $input->key(), $useResult, $returnedCanContinue);
// track the continuation flags
$continueWIthNextItem = $continueWIthNextItem && $returnedCanContinue;
// iterate
$operatorChain->next();
}
if ($useResult) {
$results->append($result);
}
// goto next item
$input->next();
}
return $results;
}
示例14: key
/**
* @inheritDoc
*/
public function key()
{
if (!$this->acceptValidated) {
$this->valid();
}
return $this->it->key();
}
示例15: fetchInner
protected function fetchInner()
{
if ($this->valid()) {
$this->v = $this->inner->current();
$this->k = $this->inner->key();
}
}