From 3fe69d5a76ca05fb6fb2a2ad3ae89cf71a52bf62 Mon Sep 17 00:00:00 2001 From: Johan Date: Wed, 10 Feb 2021 16:06:34 +0700 Subject: [PATCH] Implement IteratorAggregate interface --- src/UtmParameters.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/UtmParameters.php b/src/UtmParameters.php index ccf2d94..25ae1cb 100644 --- a/src/UtmParameters.php +++ b/src/UtmParameters.php @@ -4,6 +4,7 @@ namespace Devlop\UtmParameters; +use ArrayIterator; use DateInterval; use DateTimeImmutable; use DateTimeInterface; @@ -14,9 +15,10 @@ use Devlop\UtmParameters\RequestHandlerInterface; use Devlop\UtmParameters\ResponseHandlerInterface; use InvalidArgumentException; +use IteratorAggregate; use Webmozart\Assert\Assert; -final class UtmParameters implements UtmParametersFactoryInterface, UtmParametersInterface +final class UtmParameters implements UtmParametersFactoryInterface, UtmParametersInterface, IteratorAggregate { public const SOURCE = 'utm_source'; @@ -259,6 +261,16 @@ public function getContent() : ?string return $this->content; } + /** + * Required by the IteratorAggregate interface. + * + * Returns an external iterator. + */ + public function getIterator() : ArrayIterator + { + return new ArrayIterator($this->toArray()); + } + /** * Get all parameters as a key => value array *