Created
June 19, 2013 10:18
-
-
Save ftdebugger/5813275 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 | |
/** | |
* @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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment