05-11-2009, 06:22 PM
|
#8 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
I'm not convinced that there needs to be any Singleton here. Why would you only ever want one instance of this class?
Also, I know your design goal was to remove the cruft that is attached to Twitter's API responses but how about having the ability to get at extra stuff if/when needed? (You are allowed to say no.)
Rather than wrapping the meat of a method within an if statment, determine whether the cache is available and return early instead. For example:
PHP Code:
public function getDirectMessages($date_format = null, $params = null, $use_href = true)
{
// In internal cache, return early
if( ! empty($this->data['direct_messages']))
{
return $this->data['direct_messages'];
}
$buffer = $this->APICall('direct_messages', $params);
foreach($buffer as $message)
{
if($use_href)
{
$message->text = preg_replace('/@([a-z0-9]+)/i', '<a href="http://www.twitter.com/$1" title="$1 on Twitter">@$1</a>', $message->text);
}
$this->data['direct_messages'][] = array(
'id' => $message->id,
'from-name' => $message->sender->name,
'from-screen_name' => $message->sender_screen_name,
'text' => $message->text,
'time' => $date_format !== null ? date($date_format, strtotime($message->created_at)) : strtotime($message->created_at)
);
}
$this->modified = true;
return $this->data['direct_messages'];
}
|
|
|
|