Skip to content

Commit 120a869

Browse files
derrabusnicolas-grekas
authored andcommitted
Add parameter type declarations to contracts.
1 parent f51bca9 commit 120a869

15 files changed

+64
-141
lines changed

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": "2.0-dev"
3232
}
3333
}
3434
}

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 <[email protected]>
26+
* @author Jonathan Wage <[email protected]>
27+
* @author Roman Borschel <[email protected]>
28+
* @author Bernhard Schussek <[email protected]>
29+
* @author Nicolas Grekas <[email protected]>
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 <[email protected]>
27-
* @author Jonathan Wage <[email protected]>
28-
* @author Roman Borschel <[email protected]>
29-
* @author Bernhard Schussek <[email protected]>
30-
* @author Nicolas Grekas <[email protected]>
36+
* {@inheritdoc}
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 <[email protected]>
67-
* @author Jonathan Wage <[email protected]>
68-
* @author Roman Borschel <[email protected]>
69-
* @author Bernhard Schussek <[email protected]>
70-
* @author Nicolas Grekas <[email protected]>
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
}

EventDispatcher/EventDispatcherInterface.php

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,19 @@
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+
* @param object $event The event to pass to the event handlers/listeners
25+
* @param string|null $eventName The name of the event to dispatch. If not supplied,
26+
* the class of $event should be used instead.
27+
*
28+
* @return object The passed $event MUST be returned
4029
*/
41-
interface EventDispatcherInterface
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-
}
30+
public function dispatch(object $event, string $eventName = null): object;
5831
}

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": "2.0-dev"
3232
}
3333
}
3434
}

HttpClient/ChunkInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
* MUST be thrown by the destructor unless one was already thrown by another method.
2222
*
2323
* @author Nicolas Grekas <[email protected]>
24-
*
25-
* @experimental in 1.1
2624
*/
2725
interface ChunkInterface
2826
{

HttpClient/HttpClientInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
* @see HttpClientTestCase for a reference test suite
2121
*
2222
* @author Nicolas Grekas <[email protected]>
23-
*
24-
* @experimental in 1.1
2523
*/
2624
interface HttpClientInterface
2725
{

HttpClient/ResponseInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
* A (lazily retrieved) HTTP response.
2323
*
2424
* @author Nicolas Grekas <[email protected]>
25-
*
26-
* @experimental in 1.1
2725
*/
2826
interface ResponseInterface
2927
{

HttpClient/ResponseStreamInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* Yields response chunks, returned by HttpClientInterface::stream().
1616
*
1717
* @author Nicolas Grekas <[email protected]>
18-
*
19-
* @experimental in 1.1
2018
*/
2119
interface ResponseStreamInterface extends \Iterator
2220
{

HttpClient/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
},
2121
"suggest": {
2222
"symfony/http-client-implementation": ""
@@ -27,7 +27,7 @@
2727
"minimum-stability": "dev",
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "1.1-dev"
30+
"dev-master": "2.0-dev"
3131
}
3232
}
3333
}

Service/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/container": "^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": "2.0-dev"
3232
}
3333
}
3434
}

Translation/LocaleAwareInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface LocaleAwareInterface
2020
*
2121
* @throws \InvalidArgumentException If the locale contains invalid characters
2222
*/
23-
public function setLocale($locale);
23+
public function setLocale(string $locale);
2424

2525
/**
2626
* Returns the current locale.

Translation/TranslatorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ interface TranslatorInterface
6161
*
6262
* @throws \InvalidArgumentException If the locale contains invalid characters
6363
*/
64-
public function trans($id, array $parameters = [], $domain = null, $locale = null);
64+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null);
6565
}

Translation/TranslatorTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ trait TranslatorTrait
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function setLocale($locale)
28+
public function setLocale(string $locale)
2929
{
30-
$this->locale = (string) $locale;
30+
$this->locale = $locale;
3131
}
3232

3333
/**
@@ -41,9 +41,9 @@ public function getLocale()
4141
/**
4242
* {@inheritdoc}
4343
*/
44-
public function trans($id, array $parameters = [], $domain = null, $locale = null)
44+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null): string
4545
{
46-
if ('' === $id = (string) $id) {
46+
if (null === $id || '' === $id) {
4747
return '';
4848
}
4949

@@ -52,7 +52,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
5252
}
5353

5454
$number = (float) $parameters['%count%'];
55-
$locale = (string) $locale ?: $this->getLocale();
55+
$locale = $locale ?: $this->getLocale();
5656

5757
$parts = [];
5858
if (preg_match('/^\|++$/', $id)) {

Translation/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
},
2121
"suggest": {
2222
"symfony/translation-implementation": ""
@@ -27,7 +27,7 @@
2727
"minimum-stability": "dev",
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "1.1-dev"
30+
"dev-master": "2.0-dev"
3131
}
3232
}
3333
}

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.1.3",
19+
"php": "^7.2.9",
2020
"psr/cache": "^1.0",
21-
"psr/container": "^1.0"
21+
"psr/container": "^1.0",
22+
"psr/event-dispatcher": "^1.0"
2223
},
2324
"require-dev": {
2425
"symfony/polyfill-intl-idn": "^1.10"
@@ -31,7 +32,6 @@
3132
"symfony/translation-contracts": "self.version"
3233
},
3334
"suggest": {
34-
"psr/event-dispatcher": "When using the EventDispatcher contracts",
3535
"symfony/cache-implementation": "",
3636
"symfony/event-dispatcher-implementation": "",
3737
"symfony/http-client-implementation": "",
@@ -47,7 +47,7 @@
4747
"minimum-stability": "dev",
4848
"extra": {
4949
"branch-alias": {
50-
"dev-master": "1.1-dev"
50+
"dev-master": "2.0-dev"
5151
}
5252
}
5353
}

0 commit comments

Comments
 (0)