AcMailer\Controller\Plugin\SendMailPlugin::__invoke PHP Method

__invoke() public method

If any argument is provided, they will be used to configure the MailService and send an email. The result object will be returned in that case
public __invoke ( null | string | Zend\View\Model\ViewModel | array $bodyOrConfig = null, null | string $subject = null, null | array $to = null, null | string | array $from = null, null | array $cc = null, null | array $bcc = null, null | array $attachments = null, null | array $replyTo = null, $encoding = null ) : AcMailer\Service\MailServiceInterface | AcMailer\Result\ResultInterface
$bodyOrConfig null | string | Zend\View\Model\ViewModel | array
$subject null | string
$to null | array
$from null | string | array
$cc null | array
$bcc null | array
$attachments null | array
$replyTo null | array
return AcMailer\Service\MailServiceInterface | AcMailer\Result\ResultInterface
    public function __invoke($bodyOrConfig = null, $subject = null, $to = null, $from = null, $cc = null, $bcc = null, $attachments = null, $replyTo = null, $encoding = null)
    {
        $args = func_get_args();
        if (empty($args)) {
            return $this->mailService;
        }
        $args = $this->normalizeMailArgs($args);
        $this->applyArgsToMailService($args);
        return $this->mailService->send();
    }

Usage Example

 public function testBodyIsValidAsViewModel()
 {
     $result = $this->plugin->__invoke(new ViewModel());
     $this->assertInstanceOf('AcMailer\\Result\\ResultInterface', $result);
     $this->assertEquals('ViewModel body', $this->service->getMessage()->getBody());
 }