-
-
Save DaveRandom/352e6ed656c0fb8c9a5088ba6705aede to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Collection implements \Iterator | |
{ | |
/** | |
* @var Room[][] | |
*/ | |
private $rooms = []; | |
/** | |
* @return Room|false | |
*/ | |
public function current() | |
{ | |
if (null === $key = key($this->rooms)) { | |
return false; | |
} | |
return current($this->rooms[$key]); | |
} | |
public function next() | |
{ | |
if (null === $key = key($this->rooms)) { | |
return; | |
} | |
if (next($this->rooms[$key]) !== false) { | |
return; | |
} | |
next($this->rooms); | |
if (null === $key = key($this->rooms)) { | |
return; | |
} | |
reset($this->rooms[$key]); | |
} | |
/** | |
* @return Identifier|null | |
*/ | |
public function key() | |
{ | |
if (false === $room = $this->current()) { | |
return null; | |
} | |
return $room->getIdentifier(); | |
} | |
public function valid() | |
{ | |
return $this->current() !== false; | |
} | |
public function rewind() | |
{ | |
reset($this->rooms); | |
if (null !== $key = key($this->rooms)) { | |
reset($this->rooms[$key]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment