Skip to content

Instantly share code, notes, and snippets.

@adammbalogh
Last active October 12, 2016 07:58
Show Gist options
  • Save adammbalogh/1b53aeecd2bdd22f222303808f88ad58 to your computer and use it in GitHub Desktop.
Save adammbalogh/1b53aeecd2bdd22f222303808f88ad58 to your computer and use it in GitHub Desktop.
<?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