Example #1
0
 /**
  * @param CM_Model_User|string|null $recipient
  * @param array|null                $tplParams
  * @param CM_Site_Abstract|null     $site
  * @throws CM_Exception_Invalid
  */
 public function __construct($recipient = null, array $tplParams = null, CM_Site_Abstract $site = null)
 {
     if ($this->hasTemplate()) {
         $this->setRenderLayout(true);
     }
     if ($tplParams) {
         foreach ($tplParams as $key => $value) {
             $this->setTplParam($key, $value);
         }
     }
     if (!is_null($recipient)) {
         if (is_string($recipient)) {
             $this->addTo($recipient);
         } elseif ($recipient instanceof CM_Model_User) {
             $this->_recipient = $recipient;
             $this->addTo($this->_recipient->getEmail());
             $this->setTplParam('recipient', $recipient);
         } else {
             throw new CM_Exception_Invalid('Invalid Recipient defined.');
         }
     }
     if (!$site && $this->_recipient) {
         $site = $this->_recipient->getSite();
     }
     if (!$site) {
         $site = CM_Site_Abstract::factory();
     }
     $this->_site = $site;
     $this->setTplParam('siteName', $this->_site->getName());
     $this->setSender($this->_site->getEmailAddress(), $this->_site->getName());
 }