Skip to content

Instantly share code, notes, and snippets.

@ftdebugger
Created June 19, 2013 10:18
Show Gist options
  • Save ftdebugger/5813275 to your computer and use it in GitHub Desktop.
Save ftdebugger/5813275 to your computer and use it in GitHub Desktop.
<?php
/**
* @author Evgeny Shpilevsky <evgeny@shpilevsky.com>
*/
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment