Skip to content

Commit d30b670

Browse files
committed
docs: update events chapter
1 parent 519b6a1 commit d30b670

4 files changed

Lines changed: 70 additions & 54 deletions

File tree

Documentation/Events/Index.rst

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
.. _events:
66

7-
=============
8-
PSR-14 events
9-
=============
7+
============
8+
PSR-14 event
9+
============
1010

1111
Target group: **Developers**
1212

@@ -16,8 +16,6 @@ if you are not familiar with PSR-14 events.
1616
RateLimitExceededEvent
1717
======================
1818

19-
.. versionadded:: 1.2.0
20-
2119
This event is dispatched when the rate limit for a form has been exceeded. This
2220
way you can create an event listener which notifies you about the exceeded
2321
limit: add a log entry, send an email, inform a third-party system, etc.
@@ -38,60 +36,12 @@ provides the following methods:
3836
Returns the configured :ref:`policy <options-policy>`.
3937

4038
:php:`->getRequest(): \Psr\Http\Message\ServerRequestInterface`
41-
.. versionadded:: 1.3.0
42-
4339
Returns the :ref:`PSR-7 request object <t3coreapi:typo3-request>`.
4440

4541
Example
4642
-------
4743

4844
This example adds an entry to the TYPO3 log:
4945

50-
.. code-block:: php
46+
.. literalinclude:: _FormRateLimitExceededLogger.php
5147
:caption: EXT:your_extension/Classes/EventListener/FormRateLimitExceededLogger.php
52-
53-
<?php
54-
55-
declare(strict_types=1);
56-
57-
namespace YourVendor\YourExtension\EventListener;
58-
59-
use Brotkrueml\FormRateLimit\Event\RateLimitExceededEvent;
60-
use Psr\Log\LoggerInterface;
61-
62-
final class FormRateLimitExceededLogger
63-
{
64-
private LoggerInterface $logger;
65-
66-
public function __construct(LoggerInterface $logger)
67-
{
68-
$this->logger = $logger;
69-
}
70-
71-
public function __invoke(RateLimitExceededEvent $event): void
72-
{
73-
$this->logger->warning(
74-
'The form with identifier "{formIdentifier}" was sent more than {limit} times within {interval}',
75-
[
76-
'formIdentifier' => $event->getFormIdentifier(),
77-
'limit' => $event->getLimit(),
78-
'interval' => $event->getInterval()
79-
]
80-
);
81-
}
82-
}
83-
84-
Registration of the event listener:
85-
86-
.. code-block:: yaml
87-
:caption: EXT:your_extension/Configuration/Services.yaml
88-
89-
services:
90-
# Place here the default dependency injection configuration
91-
92-
YourVendor\YourExtension\EventListener\FormRateLimitExceededLogger:
93-
tags:
94-
- name: event.listener
95-
identifier: 'yourFormRateLimitExceededLogger'
96-
97-
Read :ref:`how to configure dependency injection in extensions <t3coreapi:dependency-injection-in-extensions>`.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the "form_rate_limit" extension for TYPO3 CMS.
7+
*
8+
* For the full copyright and license information, please read the
9+
* LICENSE.txt file that was distributed with this source code.
10+
*/
11+
12+
namespace YourVendor\YourExtension\EventListener;
13+
14+
use Brotkrueml\FormRateLimit\Event\RateLimitExceededEvent;
15+
use Psr\Log\LoggerInterface;
16+
use TYPO3\CMS\Core\Attribute\AsEventListener;
17+
18+
#[AsEventListener(
19+
identifier: 'your-extension/form-rate-limit-exceeded-logger',
20+
)]
21+
final readonly class FormRateLimitExceededLogger
22+
{
23+
public function __construct(
24+
private LoggerInterface $logger,
25+
) {}
26+
27+
public function __invoke(RateLimitExceededEvent $event): void
28+
{
29+
$this->logger->warning(
30+
'The form with identifier "{formIdentifier}" was sent more than {limit} times within {interval}',
31+
[
32+
'formIdentifier' => $event->getFormIdentifier(),
33+
'limit' => $event->getLimit(),
34+
'interval' => $event->getInterval(),
35+
],
36+
);
37+
}
38+
}

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ cs-check: cs-php-check ## Only check coding standards
2929

3030
cs-php: vendor ## Check and fix PHP coding standards
3131
.Build/bin/ecs check --fix
32+
.Build/bin/ecs check --fix --config=ecs.docs.php
3233

3334
cs-php-check: vendor ## Only check PHP coding standards
3435
.Build/bin/ecs check
36+
.Build/bin/ecs check --config=ecs.docs.php
3537

3638
docs: ## Render documentation
3739
docker run --rm --pull always -v "$(shell pwd)":/project -t ghcr.io/typo3-documentation/render-guides:latest --config=Documentation

ecs.docs.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
5+
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
6+
use Symplify\EasyCodingStandard\Config\ECSConfig;
7+
8+
return static function (ECSConfig $config): void {
9+
$header = <<<HEADER
10+
This file is part of the "form_rate_limit" extension for TYPO3 CMS.
11+
12+
For the full copyright and license information, please read the
13+
LICENSE.txt file that was distributed with this source code.
14+
HEADER;
15+
16+
$config->import(__DIR__ . '/.Build/vendor/brotkrueml/coding-standards/config/common.php');
17+
18+
$config->paths([
19+
__DIR__ . '/Documentation',
20+
]);
21+
$config->ruleWithConfiguration(HeaderCommentFixer::class, [
22+
'comment_type' => 'comment',
23+
'header' => $header,
24+
'separate' => 'both',
25+
]);
26+
};

0 commit comments

Comments
 (0)