There is a ForumThread
class:
class ForumThread extends DbTable
{
public function insert ($threadId, $comment)
{
SQL INSERT INTO parent::tablename VALUES $threadId, $comment
// email sending how?
// putting this on a "notice-wall", how?
}
}
some other functions should be done here, e.g. email sending. I cant put it here otherwise I violate the SRP. I cant put it neither to controller
, as I want to insert post elsewhere too. Im planning to implement the Observed pattern, but I cant extend from two classes.
With the observer pattern you would have to dispatch a notification from this method in order to execute the relevant observers code.
You would execute something like this from within the insert method:
$this->notify('table_insertion', $data);
Then somewhere else before the notify line is executed, the event must be registered like so:
static::$observers['table_insertion'][] = array('class_to_call' => 'method_in_class_to_call');
The notify method would be something like:
public function notify($event, $data) {
foreach(static::$observer[$event] as $class => $method) {
new $class->$method($data);
}
}
Hope this makes sense.