8000 Add parameter type declarations to contracts. · symfony/symfony@f0e7df8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f0e7df8

Browse files
committed
Add parameter type declarations to contracts.
1 parent bfdf79e commit f0e7df8

27 files changed

+85
-146
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"twig/twig": "^2.10|^3",
2424
"psr/cache": "~1.0",
2525
"psr/container": "^1.0",
26+
"psr/event-dispatcher": "^1.0",
2627
"psr/link": "^1.0",
2728
"psr/log": "~1.0",
2829
"symfony/contracts": "^1.1.3",

src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class StubTranslator implements TranslatorInterface
1717
{
18-
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
18+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
1919
{
2020
return '[trans]'.strtr($id, $parameters).'[/trans]';
2121
}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.2.9",
20-
"symfony/translation-contracts": "^1.1",
20+
"symfony/translation-contracts": "^1.2",
2121
"twig/twig": "^2.10|^3"
2222
},
2323
"require-dev": {

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getNotImplementingTranslatorBagInterfaceTranslatorClassNames()
108108

109109
class TranslatorWithTranslatorBag implements TranslatorInterface
110110
{
111-
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
111+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
112112
{
113113
}
114114
}

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"symfony/serializer": "^4.4|^5.0",
5252
"symfony/stopwatch": "^4.4|^5.0",
5353
"symfony/translation": "^5.0",
54+
"symfony/translation-contracts": "^1.2",
5455
"symfony/twig-bundle": "^4.4|^5.0",
5556
"symfony/validator": "^4.4|^5.0",
5657
"symfony/var-dumper": "^4.4|^5.0",

src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function hasListeners(string $eventName = null)
129129
/**
130130
* {@inheritdoc}
131131
*/
132-
public function dispatch($event, string $eventName = null): object
132+
public function dispatch(object $event, string $eventName = null): object
133133
{
134134
if (!\is_object($event)) {
135135
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', EventDispatcherInterface::class, \gettype($event)));
@@ -143,7 +143,7 @@ public function dispatch($event, string $eventName = null): object
143143

144144
$currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';
145145

146-
if (null !== $this->logger && ($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
146+
if (null !== $this->logger && $event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
147147
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
148148
}
149149

src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __invoke(object $event, string $eventName, EventDispatcherInterf
121121
$e->stop();
122122
}
123123

124-
if (($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
124+
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
125125
$this->stoppedPropagation = true;
126126
}
127127
}

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct()
4646
/**
4747
* {@inheritdoc}
4848
*/
49-
public function dispatch($event, string $eventName = null): object
49+
public function dispatch(object $event, string $eventName = null): object
5050
{
5151
if (!\is_object($event)) {
5252
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', EventDispatcherInterface::class, \gettype($event)));
@@ -222,7 +222,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
222222
*/
223223
protected function callListeners(iterable $listeners, string $eventName, object $event)
224224
{
225-
$stoppable = $event instanceof Event || $event instanceof StoppableEventInterface;
225+
$stoppable = $event instanceof StoppableEventInterface;
226226

227227
foreach ($listeners as $listener) {
228228
if ($stoppable && $event->isPropagationStopped()) {

src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface EventDispatcherInterface extends ContractsEventDispatcherInterface
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function dispatch($event, string $eventName = null): object;
28+
public function dispatch(object $event, string $eventName = null): object;
2929

3030
/**
3131
* Adds an event listener that listens on the specified events.

src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(EventDispatcherInterface $dispatcher)
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function dispatch($event, string $eventName = null): object
31+
public function dispatch(object $event, string $eventName = null): object
3232
{
3333
return $this->dispatcher->dispatch($event, $eventName);
3434
}

src/Symfony/Component/Form/Tests/Extension/Validator/Type/UploadValidatorExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testPostMaxSizeTranslation()
4141

4242
class DummyTranslator implements TranslatorInterface, LocaleAwareInterface
4343
{
44-
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
44+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
4545
{
4646
return 'translated max {{ max }}!';
4747
}

src/Symfony/Component/Form/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"symfony/http-kernel": "^4.4|^5.0",
3636
"symfony/security-csrf": "^4.4|^5.0",
3737
"symfony/translation": "^4.4|^5.0",
38+
"symfony/translation-contracts": "^1.2",
3839
"symfony/var-dumper": "^4.4|^5.0"
3940
},
4041
"conflict": {

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
5858
/**
5959
* {@inheritdoc}
6060
*/
61-
public function setLocale($locale)
61+
public function setLocale(string $locale)
6262
{
6363
$this->translator->setLocale($locale);
6464
}

src/Symfony/Component/Translation/LoggingTranslator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
5555
/**
5656
* {@inheritdoc}
5757
*/
58-
public function setLocale($locale)
58+
public function setLocale(string $locale)
5959
{
6060
$prev = $this->translator->getLocale();
6161
$this->translator->setLocale($locale);

src/Symfony/Component/Translation/Translator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function addResource(string $format, $resource, string $locale, string $d
141141
/**
142142
* {@inheritdoc}
143143
*/
144-
public function setLocale($locale)
144+
public function setLocale(string $locale)
145145
{
146146
$this->assertValidLocale($locale);
147147
$this->locale = $locale;
@@ -187,9 +187,9 @@ public function getFallbackLocales(): array
187187
/**
188188
* {@inheritdoc}
189189
*/
190-
public function trans($id, array $parameters = [], $domain = null, $locale = null)
190+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null)
191191
{
192-
if ('' === $id = (string) $id) {
192+
if ('' === $id) {
193193
return '';
194194
}
195195

src/Symfony/Component/Translation/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": "^7.2.9",
2020
"symfony/polyfill-mbstring": "~1.0",
21-
"symfony/translation-contracts": "^1.1.6"
21+
"symfony/translation-contracts": "^1.2"
2222
},
2323
"require-dev": {
2424
"symfony/config": "^4.4|^5.0",

src/Symfony/Contracts/Cache/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.1.3",
19+
"php": "^7.2.9",
2020
"psr/cache": "^1.0"
2121
},
2222
"suggest": {
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.1-dev"
31+
"dev-master": "1.2-dev"
3232
}
3333
}
3434
}

src/Symfony/Contracts/EventDispatcher/Event.php

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,84 +13,42 @@
1313

1414
use Psr\EventDispatcher\StoppableEventInterface;
1515

16-
if (interface_exists(StoppableEventInterface::class)) {
16+
/**
17+
* Event is the base class for classes containing event data.
18+
*
19+
* This class contains no event data. It is used by events that do not pass
20+
* state information to an event handler when an event is raised.
21+
*
22+
* You can call the method stopPropagation() to abort the execution of
23+
* further listeners in your event listener.
24+
*
25+
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
26+
* @author Jonathan Wage <jonwage@gmail.com>
27+
* @author Roman Borschel <roman@code-factory.org>
28+
* @author Bernhard Schussek <bschussek@gmail.com>
29+
* @author Nicolas Grekas <p@tchwork.com>
30+
*/
31+
class Event implements StoppableEventInterface
32+
{
33+
private $propagationStopped = false;
34+
1735
/**
18-
* Event is the base class for classes containing event data.
19-
*
20-
* This class contains no event data. It is used by events that do not pass
21-
* state information to an event handler when an event is raised.
22-
*
23-
* You can call the method stopPropagation() to abort the execution of
24-
* further listeners in your event listener.
25-
*
26-
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
27-
* @author Jonathan Wage <jonwage@gmail.com>
28-
* @author Roman Borschel <roman@code-factory.org>
29-
* @author Bernhard Schussek <bschussek@gmail.com>
30-
* @author Nicolas Grekas <p@tchwork.com>
36+
* Returns whether further event listeners should be triggered.
3137
*/
32-
class Event implements StoppableEventInterface
38+
public function isPropagationStopped(): bool
3339
{
34-
private $propagationStopped = false;
35-
36-
/**
37-
* Returns whether further event listeners should be triggered.
38-
*/
39-
public function isPropagationStopped(): bool
40-
{
41-
return $this->propagationStopped;
42-
}
43-
44-
/**
45-
* Stops the propagation of the event to further event listeners.
46-
*
47-
* If multiple event listeners are connected to the same event, no
48-
* further event listener will be triggered once any trigger calls
49-
* stopPropagation().
50-
*/
51-
public function stopPropagation(): void
52-
{
53-
$this->propagationStopped = true;
54-
}
40+
return $this->propagationStopped;
5541
}
56-
} else {
42+
5743
/**
58-
* Event is the base class for classes containing event data.
59-
*
60-
* This class contains no event data. It is used by events that do not pass
61-
* state information to an event handler when an event is raised.
44+
* Stops the propagation of the event to further event listeners.
6245
*
63-
* You can call the method stopPropagation() to abort the execution of
64-
* further listeners in your event listener.
65-
*
66-
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
67-
* @author Jonathan Wage <jonwage@gmail.com>
68-
* @author Roman Borschel <roman@code-factory.org>
69-
* @author Bernhard Schussek <bschussek@gmail.com>
70-
* @author Nicolas Grekas <p@tchwork.com>
46+
* If multiple event listeners are connected to the same event, no
47+
* further event listener will be triggered once any trigger calls
48+
* stopPropagation().
7149
*/
72-
class Event
50+
public function stopPropagation(): void
7351
{
74-
private $propagationStopped = false;
75-
76-
/**
77-
* Returns whether further event listeners should be triggered.
78-
*/
79-
public function isPropagationStopped(): bool
80-
{
81-
return $this->propagationStopped;
82-
}
83-
84-
/**
85-
* Stops the propagation of the event to further event listeners.
86-
*
87-
* If multiple event listeners are connected to the same event, no
88-
* further event listener will be triggered once any trigger calls
89-
* stopPropagation().
90-
*/
91-
public function stopPropagation(): void
92-
{
93-
$this->propagationStopped = true;
94-
}
52+
$this->propagationStopped = true;
9553
}
9654
}

src/Symfony/Contracts/EventDispatcher/EventDispatcherInterface.php

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,23 @@
1313

1414
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
1515

16-
if (interface_exists(PsrEventDispatcherInterface::class)) {
17-
/**
18-
* Allows providing hooks on domain-specific lifecycles by dispatching events.
19-
*/
20-
interface EventDispatcherInterface extends PsrEventDispatcherInterface
21-
{
22-
/**
23-
* Dispatches an event to all registered listeners.
24-
*
25-
* For BC with Symfony 4, the $eventName argument is not declared explicitly on the
26-
* signature of the method. Implementations that are not bound by this BC constraint
27-
* MUST declare it explicitly, as allowed by PHP.
28-
*
29-
* @param object $event The event to pass to the event handlers/listeners
30-
* @param string|null $eventName The name of the event to dispatch. If not supplied,
31-
* the class of $event should be used instead.
32-
*
33-
* @return object The passed $event MUST be returned
34-
*/
35-
public function dispatch($event/*, string $eventName = null*/);
36-
}
37-
} else {
16+
/**
17+
* Allows providing hooks on domain-specific lifecycles by dispatching events.
18+
*/
19+
interface EventDispatcherInterface extends PsrEventDispatcherInterface
20+
{
3821
/**
39-
* Allows providing hooks on domain-specific lifecycles by dispatching events.
22+
* Dispatches an event to all registered listeners.
23+
*
24+
* For BC with Symfony 4, the $eventName argument is not declared explicitly on the
25+
* signature of the method. Implementations that are not bound by this BC constraint
26+
* MUST declare it explicitly, as allowed by PHP.
27+
*
28+
* @param object $event The event to pass to the event handlers/listeners
29+
* @param string|null $eventName The name of the event to dispatch. If not supplied,
30+
* the class of $event should be used instead.
31+
*
32+
* @return object The passed $event MUST be returned
4033
*/
41-
interface EventDispatcherInterface
< 10000 div aria-hidden="true" style="left:-2px" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__in-progress-comment-indicator--hx3m3">
42-
{
43-
/**
44-
* Dispatches an event to all registered listeners.
45-
*
46-
* For BC with Symfony 4, the $eventName argument is not declared explicitly on the
47-
* signature of the method. Implementations that are not bound by this BC constraint
48-
* MUST declare it explicitly, as allowed by PHP.
49-
*
50-
* @param object $event The event to pass to the event handlers/listeners
51-
* @param string|null $eventName The name of the event to dispatch. If not supplied,
52-
* the class of $event should be used instead.
53-
*
54-
* @return object The passed $event MUST be returned
55-
*/
56-
public function dispatch($event/*, string $eventName = null*/);
57-
}
34+
public function dispatch(object $event/*, string $eventName = null*/);
5835
}

src/Symfony/Contracts/EventDispatcher/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.1.3"
19+
"php": "^7.2.9",
20+
"psr/event-dispatcher": "^1"
2021
},
2122
"suggest": {
22-
"psr/event-dispatcher": "",
2323
"symfony/event-dispatcher-implementation": ""
2424
},
2525
"autoload": {
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.1-dev"
31+
"dev-master": "1.2-dev"
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)
0