Skip to content
Permalink
Browse files

Nette 3

  • Loading branch information...
mabar authored and f3l1x committed Jun 8, 2019
1 parent cb87c5e commit 0e446f2f9dbf1593638801c45966ef3419e330e5
Showing with 38 additions and 32 deletions.
  1. +6 −5 README.md
  2. +7 −8 composer.json
  3. +20 −16 src/DI/MailingExtension.php
  4. +1 −1 src/NetteMailSender.php
  5. +4 −2 tests/cases/MailBuilderFactory.phpt
@@ -22,11 +22,12 @@ Sending emails with pleasure and prepared templates.

## Versions

| State | Version | Branch | PHP |
|-------------|---------|----------|----------|
| dev | `^0.3` | `master` | `>= 7.1` |
| stable | `^0.2` | `master` | `>= 7.1` |
| stable | `^0.1` | `master` | `>= 5.6` |
| State | Version | Branch | Nette | PHP |
|-------------|---------|----------|-------|---------|
| dev | `^0.4` | `master` | 3.0+ | `^7.2` |
| stable | `^0.3` | `master` | 3.0+ | `^7.2` |
| stable | `^0.2` | `master` | 2.4 | `>=7.1` |
| stable | `^0.1` | `master` | 2.4 | `>=5.6` |

## Maintainers

@@ -16,12 +16,11 @@
}
],
"require": {
"php": ">= 7.1",
"nette/application": "~2.4.12",
"nette/di": "~2.4.12",
"nette/mail": "~2.4.5",
"nette/utils": "~2.5.2",
"latte/latte": "~2.4.8 || ~2.5.1"
"php": "^7.2",
"nette/application": "~3.0.0",
"nette/di": "~3.0.0",
"nette/mail": "~3.0.1",
"latte/latte": "~2.5.1"
},
"require-dev": {
"mockery/mockery": "^0.9.9",
@@ -34,7 +33,7 @@
"phpstan/phpstan-strict-rules": "^0.11"
},
"conflict": {
"nette/http": "<2.4.9"
"nette/di": "<3.0.0"
},
"autoload": {
"psr-4": {
@@ -53,7 +52,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.3.x-dev"
"dev-master": "0.4.x-dev"
}
}
}
@@ -9,26 +9,30 @@
use Contributte\Mailing\NetteMailSender;
use Contributte\Mailing\NetteTemplateFactory;
use Nette\DI\CompilerExtension;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use stdClass;
/**
* @property-read stdClass $config
*/
class MailingExtension extends CompilerExtension
{
/** @var mixed[] */
private $defaults = [
'template' => [
'defaults' => [
'layout' => '@@default',
],
'config' => [
'layout' => '@@default',
],
],
];
public function getConfigSchema(): Schema
{
return Expect::structure([
'template' => Expect::structure([
'defaults' => Expect::arrayOf('mixed')->default(['layout' => '@@default']),
'config' => Expect::arrayOf('mixed')->default(['layout' => '@@default']),
]),
]);
}
public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);
$config = $this->config;
$builder->addDefinition($this->prefix('builderFactory'))
->setType(IMailBuilderFactory::class)
@@ -42,12 +46,12 @@ public function loadConfiguration(): void
->setType(IMailTemplateFactory::class)
->setFactory(NetteTemplateFactory::class);
if ($config['template']['defaults']) {
$templateFactory->addSetup('setDefaults', [$config['template']['defaults']]);
if ($config->template->defaults) {
$templateFactory->addSetup('setDefaults', [$config->template->defaults]);
}
if ($config['template']['config']) {
$templateFactory->addSetup('setConfig', [$config['template']['config']]);
if ($config->template->config) {
$templateFactory->addSetup('setConfig', [$config->template->config]);
}
}
@@ -25,7 +25,7 @@ public function send(MailBuilder $builder): void
$template->add('_mail', $message);
// Set template to message
$message->setHtmlBody($template);
$message->setHtmlBody($template->__toString());
// Send message
$this->mailer->send($message);
@@ -13,14 +13,16 @@ use Contributte\Mailing\NetteTemplateFactory;
use Latte\Engine;
use Mockery;
use Nette\Application\LinkGenerator;
use Nette\Application\Routers\RouteList;
use Nette\Bridges\ApplicationLatte\ILatteFactory;
use Nette\Bridges\ApplicationLatte\TemplateFactory;
use Nette\Http\UrlScript;
use Tester\Assert;
require_once __DIR__ . '/../bootstrap.php';
test(function (): void {
$linkGenerator = Mockery::mock(LinkGenerator::class);
$linkGenerator = new LinkGenerator(new RouteList(), new UrlScript());
$sender = Mockery::mock(IMailSender::class);
$sender->shouldReceive('send')
@@ -31,7 +33,7 @@ test(function (): void {
$message = $builder->getMessage();
$template = $builder->getTemplate();
$template->add('_mail', $message);
$message->setHtmlBody($template);
$message->setHtmlBody($template->__toString());
$filename = TEMP_DIR . date('Y-m-d H-i-s') . microtime() . '.eml';
file_put_contents($filename, $message->generateMessage());

0 comments on commit 0e446f2

Please sign in to comment.
You can’t perform that action at this time.