Created
June 19, 2013 10:18
Revisions
-
ftdebugger created this gist
Jun 19, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ <?php /** * @author Evgeny Shpilevsky <[email protected]> */ class Post { /** * @var string */ protected $title; /** * @param string $title */ public function setTitle($title) { $this->title = $title; } /** * @return string */ public function getTitle() { return $this->title; } } class PostContainer implements IteratorAggregate { /** * @var Post[] */ protected $posts; /** * @var int */ protected $archiveCount; /** * @param Post[] $posts * @param int $archiveCount */ public function __construct(array $posts, $archiveCount) { $this->posts = $posts; $this->archiveCount = $archiveCount; } /** * @return int */ public function getArchiveCount() { return $this->archiveCount; } /** * @return ArrayIterator|Traversable */ public function getIterator() { return new ArrayIterator($this->posts); } } $news = new PostContainer($this->getService()->getLatestNews(), $this->getService()->getArchiveCount()); // где-то foreach ($news as $post) { echo $post->getTitle(); // something else } echo $news->getArchiveCount();