2008年1月14日

ナガレ×ナガレ


Zend_Mail オブジェクトのほとんどのメソッドは、 流れるようなインターフェイス形式でコールすることもできます。 「流れるようなインターフェイス」とは、 各メソッドの返り値が呼び出し元オブジェクト自身への参照となり、 その返り値からすぐに別のメソッドをコールできる形式のことを表します。


<?php
require_once 'Zend/Mail.php';
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.')
->setFrom('somebody@example.com', 'Some Sender')
->addTo('somebody_else@example.com', 'Some Recipient')
->setSubject('TestSubject')
->send();


Zend Framework:Documentation

これって流れてるの?単なるメソッドチェーンでなくって?
僕がイメージしている流れるようなインターフェイスって下のような感じなんだけど。


new Mail('This is the text of the mail.')
->from('somebody@example.com', 'Some Sender')
->to('somebody_else@example.com', 'Some Recipient')
->about('TestSubject')
->send();