Skip to content

Commit 59ade3f

Browse files
authored
Merge pull request #97 from dlubitz/task/optional-symfonymailer
TASK: Make neos/symfonymailer an optional dependency
2 parents 0444150 + b0537c0 commit 59ade3f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Classes/Runtime/Action/EmailAction.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Neos\Flow\Annotations as Flow;
1717
use Neos\Flow\Mvc\ActionResponse;
18+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
1819
use Neos\Flow\ResourceManagement\PersistentResource;
1920
use Neos\Fusion\Form\Runtime\Domain\Exception\ActionException;
2021
use Neos\SymfonyMailer\Service\MailerService;
@@ -28,14 +29,18 @@
2829
class EmailAction extends AbstractAction
2930
{
3031
#[Flow\Inject]
31-
protected MailerService $mailerService;
32+
protected ObjectManagerInterface $objectManager;
3233

3334
/**
3435
* @return ActionResponse|null
3536
* @throws ActionException
3637
*/
3738
public function perform(): ?ActionResponse
3839
{
40+
if (!class_exists(MailerService::class)) {
41+
throw new ActionException('The "neos/symfonymailer" doesn\'t seem to be installed, but is required for the EmailAction to work!', 1503392532);
42+
}
43+
3944
$subject = $this->options['subject'] ?? null;
4045
$text = $this->options['text'] ?? null;
4146
$html = $this->options['html'] ?? null;
@@ -119,7 +124,7 @@ public function perform(): ?ActionResponse
119124
);
120125
return $response;
121126
} else {
122-
$this->mailerService->getMailer()->send($mail);
127+
$this->getMailerService()->getMailer()->send($mail);
123128
}
124129

125130
return null;
@@ -154,4 +159,11 @@ protected function addAttachments(Email $mail): void
154159
}
155160
}
156161
}
162+
163+
private function getMailerService(): MailerService
164+
{
165+
/** @var MailerService $mailerService */
166+
$mailerService = $this->objectManager->get(MailerService::class);
167+
return $mailerService;
168+
}
157169
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
"neos/flow": "^8.0 || ^9.0",
1111
"neos/fusion": "^8.0 || ^9.0",
1212
"neos/fusion-afx": "^1.2 || ^7.0 || ^8.0 || ^9.0",
13-
"neos/symfonymailer": "^0.1.0",
1413
"neos/utility-arrays": "*",
1514
"neos/utility-objecthandling": "*",
1615
"psr/http-factory": "*"
1716
},
1817
"require-dev": {
1918
"phpunit/phpunit": "^7.1 || ^8.0 || ^9.0",
20-
"phpstan/phpstan": "^2.1"
19+
"phpstan/phpstan": "^2.1",
20+
"neos/symfonymailer": "^0.1.0"
2121
},
2222
"suggest": {
2323
"neos/symfonymailer": "Required for the Neos.Fusion.Form.Runtime:Email action to work"

0 commit comments

Comments
 (0)