Skip to content

Commit 7c5358a

Browse files
author
olaru
committed
Contact form inject method
1 parent 2953fbe commit 7c5358a

7 files changed

Lines changed: 12 additions & 64 deletions

File tree

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"doctrine/data-fixtures": "^2.2",
3333
"doctrine/doctrine-fixtures-bundle": "^4.3",
3434
"dotkernel/dot-cache": "^4.0",
35+
"dotkernel/dot-dependency-injection": "^1.4",
3536
"dotkernel/dot-errorhandler": "^5.0.0",
3637
"dotkernel/dot-mail": "^5.4",
3738
"dotkernel/dot-response-header": "^3.6",

‎config/config.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
\Mezzio\Twig\ConfigProvider::class,
2626

2727
// Dotkernel packages
28+
\Dot\DependencyInjection\ConfigProvider::class,
2829
\Dot\ErrorHandler\ConfigProvider::class,
2930
\Dot\Log\ConfigProvider::class,
3031
\Dot\Mail\ConfigProvider::class,

‎src/App/src/ConfigProvider.php‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
1111
use Dot\Cache\Adapter\ArrayAdapter;
1212
use Dot\Cache\Adapter\FilesystemAdapter;
13+
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
1314
use Light\App\DBAL\Types\UuidType;
14-
use Light\App\Factory\ContactServiceFactory;
1515
use Light\App\Factory\EntityListenerResolverFactory;
1616
use Light\App\Factory\FeedGeneratorFactory;
1717
use Light\App\Factory\GetFeedViewHandlerFactory;
@@ -25,7 +25,6 @@
2525
use Light\App\Factory\MarkdownExtensionFactory;
2626
use Light\App\Factory\MarkdownRuntimeLoaderFactory;
2727
use Light\App\Factory\PackageGeneratorFactory;
28-
use Light\App\Factory\PostContactCreateHandlerFactory;
2928
use Light\App\Factory\SitemapGeneratorFactory;
3029
use Light\App\Handler\GetFeedViewHandler;
3130
use Light\App\Handler\GetIndexViewHandler;
@@ -146,8 +145,8 @@ public function getDependencies(): array
146145
GetMarkdownArticleHandler::class => GetMarkdownArticleHandlerFactory::class,
147146
GetSitemapViewHandler::class => GetSitemapViewHandlerFactory::class,
148147
GetPackagesViewHandler::class => GetPackagesViewHandlerFactory::class,
149-
PostContactCreateHandler::class => PostContactCreateHandlerFactory::class,
150-
ContactService::class => ContactServiceFactory::class,
148+
PostContactCreateHandler::class => AttributedServiceFactory::class,
149+
ContactService::class => AttributedServiceFactory::class,
151150
FeedGenerator::class => FeedGeneratorFactory::class,
152151
SitemapGenerator::class => SitemapGeneratorFactory::class,
153152
GitHubClient::class => GitHubClientFactory::class,

‎src/App/src/Factory/ContactServiceFactory.php‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎src/App/src/Factory/PostContactCreateHandlerFactory.php‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎src/App/src/Handler/PostContactCreateHandler.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Light\App\Handler;
66

7+
use Dot\DependencyInjection\Attribute\Inject;
78
use Laminas\Diactoros\Response\HtmlResponse;
89
use Laminas\Diactoros\Response\RedirectResponse;
910
use Light\App\Service\ContactService;
@@ -18,6 +19,10 @@ class PostContactCreateHandler implements RequestHandlerInterface
1819
{
1920
public const string TEMPLATE = 'page::contact';
2021

22+
#[Inject(
23+
TemplateRendererInterface::class,
24+
ContactService::class,
25+
)]
2126
public function __construct(
2227
protected TemplateRendererInterface $template,
2328
protected ContactService $contactService,

‎src/App/src/Service/ContactService.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Light\App\Service;
66

7+
use Dot\DependencyInjection\Attribute\Inject;
78
use Dot\Mail\Service\MailServiceInterface;
89
use Laminas\Validator\EmailAddress;
910
use Laminas\Validator\NotEmpty;
@@ -49,6 +50,7 @@ final class ContactService
4950

5051
private const array RESERVED_FIELDS = ['topic', 'name', 'email', 'company', 'stack', 'message', 'contact'];
5152

53+
#[Inject('dot-mail.service.contact')]
5254
public function __construct(private readonly MailServiceInterface $mailService)
5355
{
5456
}

0 commit comments

Comments
 (0)