Last active
October 12, 2016 07:58
-
-
Save adammbalogh/1b53aeecd2bdd22f222303808f88ad58 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 | |
final class TaskCollection implements IteratorAggregate | |
{ | |
/** @var Task[] */ | |
private $tasks; | |
/** | |
* @param Task[] $tasks | |
*/ | |
public function __construct(array $tasks) | |
{ | |
$this->tasks = $tasks; | |
} | |
/** | |
* @param string $name | |
* | |
* @return Task | |
*/ | |
public function add($name) | |
{ | |
$task = new Task($name); | |
$this->tasks[] = $task; | |
return $task; | |
} | |
public function getIterator() { | |
foreach ($this->tasks as $task) { | |
yield $task; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment