Created
September 6, 2011 16:17
-
-
Save redpanda/1198030 to your computer and use it in GitHub Desktop.
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 characters
| <?php | |
| interface Timelineable | |
| { | |
| } | |
| interface TimelinerInterface | |
| { | |
| public function supports($target); | |
| public function getContent(); | |
| } | |
| class TimelinerProvider | |
| { | |
| protected $timeliners; | |
| public function __construct(array $timeliners = array(), $defaultTimelinerClass = 'DefaultTimeliner') | |
| { | |
| $this->timeliners = array(); | |
| foreach ($timeliners as $timeliner) { | |
| $this->addTimeliner($timeliner); | |
| } | |
| } | |
| public function addTimeliner(TimelinerInterface $timeliner) | |
| { | |
| $this->timeliners[] = $timeliner; | |
| } | |
| public function resolve(TimelineEntry $timelineEntry) | |
| { | |
| $timeliner = false; | |
| foreach ($this->timeliners as $t) { | |
| if ($t->supports($timelineEntry->getTarget())) { | |
| $timeliner = $t; | |
| } | |
| } | |
| if (!$timeliner) { | |
| $timeliner = new $defaultTimeliner(); | |
| } | |
| $timeliner->setTimelineEntry($timelineEntry); | |
| return $timeliner; | |
| } | |
| } | |
| abstract class AbstractTimeliner implements TimelinerInterface | |
| { | |
| protected $timelineEntry; | |
| public function setTimelineEntry(TimelineEntry) | |
| { | |
| $this->timelineEntry = $timelineEntry; | |
| } | |
| public function getTimelineEntry() | |
| { | |
| return $this->timelineEntry; | |
| } | |
| } | |
| class DefaultTimeliner extends AbstractTimeliner | |
| { | |
| public function supports() | |
| { | |
| return true; | |
| } | |
| public function getContent() | |
| { | |
| return $this->getTimelineEntry()->getTarget().' - '.$this->getTimelineEntry()->getActionObject(); | |
| } | |
| } | |
| class TimelineEntry | |
| { | |
| protected $id; | |
| protected $actor; | |
| protected $target; | |
| protected $actionObject; | |
| protected $createdAt; | |
| public function __construct($actor, $target, $actionObject = null) | |
| { | |
| $this->actor = $actor; | |
| $this->target = $target | |
| $this->actionObject = $actionObject; | |
| $this->createdAt = new \DateTime('now'); | |
| } | |
| public function getActor() | |
| { | |
| return $this->actor; | |
| } | |
| public function getTarget() | |
| { | |
| return $this->target; | |
| } | |
| publc function getActionObject() | |
| { | |
| return $this->actionObject; | |
| } | |
| public function getCreatedAt() | |
| { | |
| return $this->createdAt; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment