Skip to content

Instantly share code, notes, and snippets.

@redpanda
Created September 6, 2011 16:17
Show Gist options
  • Select an option

  • Save redpanda/1198030 to your computer and use it in GitHub Desktop.

Select an option

Save redpanda/1198030 to your computer and use it in GitHub Desktop.
<?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