Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ecad3f

Browse filesBrowse files
Merge branch '4.2' into 4.3
* 4.2: minor: add some test in the ldap component [Bridge\ProxyManager] isProxyCandidate() does not take into account interfaces [Routing][AnnotationClassLoader] fix utf-8 encoding in default route name fixed a phpdoc [Debug] Wrap call to require_once in a try/catch prevent deprecation when filesize matches error code [PropertyInfo] Add missing documentation link in Readme Use the current working dir as default first arg in 'link' binary Respect parent class contract in ContainerAwareDoctrineEventManager [Validator] Add the missing translations for the Danish ("da") locale [PropertyAccess] Add missing property to PropertyAccessor [Cache] fix saving unrelated keys in recursive callback calls [Serializer] Fix denormalization of object with variadic constructor typed argument Allow set 'None' on samesite cookie flag Making cache rebuild correctly with MessageSubscriberInterface return values Fix finding parent definition
2 parents 0c1a3dc + 48258fc commit 2ecad3f
Copy full SHA for 2ecad3f

File tree

26 files changed

+446
-82
lines changed
Filter options

26 files changed

+446
-82
lines changed

‎link

Copy file name to clipboardExpand all lines: link
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ use Symfony\Component\Filesystem\Filesystem;
2323
* @author Kévin Dunglas <dunglas@gmail.com>
2424
*/
2525

26-
if (2 !== $argc) {
27-
echo 'Link dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
28-
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
29-
exit(1);
30-
}
26+
$pathToProject = $argv[1] ?? getcwd();
3127

32-
if (!is_dir("$argv[1]/vendor/symfony")) {
33-
echo "The directory \"$argv[1]\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL;
28+
if (!is_dir("$pathToProject/vendor/symfony")) {
29+
echo 'Link dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
30+
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL.PHP_EOL;
31+
echo "The directory \"$pathToProject\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL;
3432
exit(1);
3533
}
3634

@@ -50,7 +48,7 @@ foreach ($directories as $dir) {
5048
}
5149
}
5250

53-
foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
51+
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
5452
$package = 'symfony/'.basename($dir);
5553
if (is_link($dir)) {
5654
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
@@ -68,6 +66,6 @@ foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir)
6866
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
6967
}
7068

71-
foreach (glob("$argv[1]/var/cache/*") as $cacheDir) {
69+
foreach (glob("$pathToProject/var/cache/*") as $cacheDir) {
7270
$filesystem->remove($cacheDir);
7371
}

‎src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php
+46-43Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,72 +37,61 @@ public function __construct(ContainerInterface $container)
3737
}
3838

3939
/**
40-
* Dispatches an event to all registered listeners.
41-
*
42-
* @param string $eventName The name of the event to dispatch. The name of the event is
43-
* the name of the method that is invoked on listeners.
44-
* @param EventArgs $eventArgs The event arguments to pass to the event handlers/listeners.
45-
* If not supplied, the single empty EventArgs instance is used.
46-
*
47-
* @return bool
40+
* {@inheritdoc}
4841
*/
4942
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
5043
{
51-
if (isset($this->listeners[$eventName])) {
52-
$eventArgs = null === $eventArgs ? EventArgs::getEmptyInstance() : $eventArgs;
44+
if (!isset($this->listeners[$eventName])) {
45+
return;
46+
}
5347

54-
$initialized = isset($this->initialized[$eventName]);
48+
$eventArgs = null === $eventArgs ? EventArgs::getEmptyInstance() : $eventArgs;
5549

56-
foreach ($this->listeners[$eventName] as $hash => $listener) {
57-
if (!$initialized && \is_string($listener)) {
58-
$this->listeners[$eventName][$hash] = $listener = $this->container->get($listener);
59-
}
50+
if (!isset($this->initialized[$eventName])) {
51+
$this->initializeListeners($eventName);
52+
}
6053

61-
$listener->$eventName($eventArgs);
62-
}
63-
$this->initialized[$eventName] = true;
54+
foreach ($this->listeners[$eventName] as $hash => $listener) {
55+
$listener->$eventName($eventArgs);
6456
}
6557
}
6658

6759
/**
68-
* Gets the listeners of a specific event or all listeners.
69-
*
70-
* @param string $event The name of the event
71-
*
72-
* @return array The event listeners for the specified event, or all event listeners
60+
* {@inheritdoc}
7361
*/
7462
public function getListeners($event = null)
7563
{
76-
return $event ? $this->listeners[$event] : $this->listeners;
64+
if (null !== $event) {
65+
if (!isset($this->initialized[$event])) {
66+
$this->initializeListeners($event);
67+
}
68+
69+
return $this->listeners[$event];
70+
}
71+
72+
foreach ($this->listeners as $event => $listeners) {
73+
if (!isset($this->initialized[$event])) {
74+
$this->initializeListeners($event);
75+
}
76+
}
77+
78+
return $this->listeners;
7779
}
7880

7981
/**
80-
* Checks whether an event has any registered listeners.
81-
*
82-
* @param string $event
83-
*
84-
* @return bool TRUE if the specified event has any listeners, FALSE otherwise
82+
* {@inheritdoc}
8583
*/
8684
public function hasListeners($event)
8785
{
8886
return isset($this->listeners[$event]) && $this->listeners[$event];
8987
}
9088

9189
/**
92-
* Adds an event listener that listens on the specified events.
93-
*
94-
* @param string|array $events The event(s) to listen on
95-
* @param object|string $listener The listener object
96-
*
97-
* @throws \RuntimeException
90+
* {@inheritdoc}
9891
*/
9992
public function addEventListener($events, $listener)
10093
{
10194
if (\is_string($listener)) {
102-
if ($this->initialized) {
103-
throw new \RuntimeException('Adding lazy-loading listeners after construction is not supported.');
104-
}
105-
10695
$hash = '_service_'.$listener;
10796
} else {
10897
// Picks the hash code related to that listener
@@ -113,14 +102,15 @@ public function addEventListener($events, $listener)
113102
// Overrides listener if a previous one was associated already
114103
// Prevents duplicate listeners on same event (same instance only)
115104
$this->listeners[$event][$hash] = $listener;
105+
106+
if (\is_string($listener)) {
107+
unset($this->initialized[$event]);
108+
}
116109
}
117110
}
118111

119112
/**
120-
* Removes an event listener from the specified events.
121-
*
122-
* @param string|array $events
123-
* @param object|string $listener
113+
* {@inheritdoc}
124114
*/
125115
public function removeEventListener($events, $listener)
126116
{
@@ -138,4 +128,17 @@ public function removeEventListener($events, $listener)
138128
}
139129
}
140130
}
131+
132+
/**
133+
* @param string $eventName
134+
*/
135+
private function initializeListeners($eventName)
136+
{
137+
foreach ($this->listeners[$eventName] as $hash => $listener) {
138+
if (\is_string($listener)) {
139+
$this->listeners[$eventName][$hash] = $this->container->get($listener);
140+
}
141+
}
142+
$this->initialized[$eventName] = true;
143+
}
141144
}

‎src/Symfony/Bridge/Doctrine/Tests/ContainerAwareEventManagerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/ContainerAwareEventManagerTest.php
+60-10Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ protected function setUp()
2828

2929
public function testDispatchEvent()
3030
{
31-
$this->container->set('foobar', $listener1 = new MyListener());
32-
$this->evm->addEventListener('foo', 'foobar');
31+
$this->container->set('lazy', $listener1 = new MyListener());
32+
$this->evm->addEventListener('foo', 'lazy');
3333
$this->evm->addEventListener('foo', $listener2 = new MyListener());
3434

3535
$this->evm->dispatchEvent('foo');
@@ -38,19 +38,69 @@ public function testDispatchEvent()
3838
$this->assertTrue($listener2->called);
3939
}
4040

41+
public function testAddEventListenerAfterDispatchEvent()
42+
{
43+
$this->container->set('lazy1', $listener1 = new MyListener());
44+
$this->evm->addEventListener('foo', 'lazy1');
45+
$this->evm->addEventListener('foo', $listener2 = new MyListener());
46+
47+
$this->evm->dispatchEvent('foo');
48+
49+
$this->container->set('lazy2', $listener3 = new MyListener());
50+
$this->evm->addEventListener('foo', 'lazy2');
51+
$this->evm->addEventListener('foo', $listener4 = new MyListener());
52+
53+
$this->evm->dispatchEvent('foo');
54+
55+
$this->assertTrue($listener1->called);
56+
$this->assertTrue($listener2->called);
57+
$this->assertTrue($listener3->called);
58+
$this->assertTrue($listener4->called);
59+
}
60+
61+
public function testGetListenersForEvent()
62+
{
63+
$this->container->set('lazy', $listener1 = new MyListener());
64+
$this->evm->addEventListener('foo', 'lazy');
65+
$this->evm->addEventListener('foo', $listener2 = new MyListener());
66+
67+
$this->assertSame([$listener1, $listener2], array_values($this->evm->getListeners('foo')));
68+
}
69+
70+
public function testGetListeners()
71+
{
72+
$this->container->set('lazy', $listener1 = new MyListener());
73+
$this->evm->addEventListener('foo', 'lazy');
74+
$this->evm->addEventListener('foo', $listener2 = new MyListener());
75+
76+
$this->assertSame([$listener1, $listener2], array_values($this->evm->getListeners()['foo']));
77+
}
78+
4179
public function testRemoveEventListener()
4280
{
43-
$this->evm->addEventListener('foo', 'bar');
44-
$this->evm->addEventListener('foo', $listener = new MyListener());
81+
$this->container->set('lazy', $listener1 = new MyListener());
82+
$this->evm->addEventListener('foo', 'lazy');
83+
$this->evm->addEventListener('foo', $listener2 = new MyListener());
84+
85+
$this->evm->removeEventListener('foo', $listener2);
86+
$this->assertSame([$listener1], array_values($this->evm->getListeners('foo')));
4587

46-
$listeners = ['foo' => ['_service_bar' => 'bar', spl_object_hash($listener) => $listener]];
47-
$this->assertSame($listeners, $this->evm->getListeners());
48-
$this->assertSame($listeners['foo'], $this->evm->getListeners('foo'));
88+
$this->evm->removeEventListener('foo', 'lazy');
89+
$this->assertSame([], $this->evm->getListeners('foo'));
90+
}
91+
92+
public function testRemoveEventListenerAfterDispatchEvent()
93+
{
94+
$this->container->set('lazy', $listener1 = new MyListener());
95+
$this->evm->addEventListener('foo', 'lazy');
96+
$this->evm->addEventListener('foo', $listener2 = new MyListener());
97+
98+
$this->evm->dispatchEvent('foo');
4999

50-
$this->evm->removeEventListener('foo', $listener);
51-
$this->assertSame(['_service_bar' => 'bar'], $this->evm->getListeners('foo'));
100+
$this->evm->removeEventListener('foo', $listener2);
101+
$this->assertSame([$listener1], array_values($this->evm->getListeners('foo')));
52102

53-
$this->evm->removeEventListener('foo', 'bar');
103+
$this->evm->removeEventListener('foo', 'lazy');
54104
$this->assertSame([], $this->evm->getListeners('foo'));
55105
}
56106
}

‎src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
1616
use Symfony\Component\DependencyInjection\Definition;
17+
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
1718

1819
/**
1920
* Tests for {@see \Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper}.
@@ -182,6 +183,7 @@ public function getProxyCandidates()
182183
$definitions = [
183184
[new Definition(__CLASS__), true],
184185
[new Definition('stdClass'), true],
186+
[new Definition(DumperInterface::class), true],
185187
[new Definition(uniqid('foo', true)), false],
186188
[new Definition(), false],
187189
];

‎src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ public function testGet()
5959
$this->assertFalse($isHit);
6060
}
6161

62+
public function testRecursiveGet()
63+
{
64+
if (isset($this->skippedTests[__FUNCTION__])) {
65+
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
66+
}
67+
68+
$cache = $this->createCachePool(0, __FUNCTION__);
69+
70+
$v = $cache->get('k1', function () use (&$counter, $cache) {
71+
$v = $cache->get('k2', function () use (&$counter) { return ++$counter; });
72+
$v = $cache->get('k2', function () use (&$counter) { return ++$counter; });
73+
74+
return $v;
75+
});
76+
77+
$this->assertSame(1, $counter);
78+
$this->assertSame(1, $v);
79+
$this->assertSame(1, $cache->get('k2', function () { return 2; }));
80+
}
81+
6282
public function testGetMetadata()
6383
{
6484
if (isset($this->skippedTests[__FUNCTION__])) {

‎src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class PhpArrayAdapterTest extends AdapterTestCase
2323
{
2424
protected $skippedTests = [
2525
'testGet' => 'PhpArrayAdapter is read-only.',
26+
'testRecursiveGet' => 'PhpArrayAdapter is read-only.',
2627
'testBasicUsage' => 'PhpArrayAdapter is read-only.',
2728
'testBasicUsageWithLongKey' => 'PhpArrayAdapter is read-only.',
2829
'testClear' => 'PhpArrayAdapter is read-only.',

‎src/Symfony/Component/Cache/Traits/ContractsTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/ContractsTrait.php
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ trait ContractsTrait
3232
}
3333

3434
private $callbackWrapper = [LockRegistry::class, 'compute'];
35+
private $computing = [];
3536

3637
/**
3738
* Wraps the callback passed to ->get() in a callable.
@@ -69,26 +70,27 @@ function (CacheItem $item, float $startTime, ?array &$metadata) {
6970
CacheItem::class
7071
);
7172

72-
return $this->contractsGet($pool, $key, function (CacheItem $item, bool &$save) use ($pool, $callback, $setMetadata, &$metadata) {
73+
return $this->contractsGet($pool, $key, function (CacheItem $item, bool &$save) use ($pool, $callback, $setMetadata, &$metadata, $key) {
7374
// don't wrap nor save recursive calls
74-
if (null === $callbackWrapper = $this->callbackWrapper) {
75+
if (isset($this->computing[$key])) {
7576
$value = $callback($item, $save);
7677
$save = false;
7778

7879
return $value;
7980
}
80-
$this->callbackWrapper = null;
81+
82+
$this->computing[$key] = $key;
8183
$startTime = microtime(true);
8284

8385
try {
84-
$value = $callbackWrapper($callback, $item, $save, $pool, function (CacheItem $item) use ($setMetadata, $startTime, &$metadata) {
86+
$value = ($this->callbackWrapper)($callback, $item, $save, $pool, function (CacheItem $item) use ($setMetadata, $startTime, &$metadata) {
8587
$setMetadata($item, $startTime, $metadata);
8688
}, $this->logger ?? null);
8789
$setMetadata($item, $startTime, $metadata);
8890

8991
return $value;
9092
} finally {
91-
$this->callbackWrapper = $callbackWrapper;
93+
unset($this->computing[$key]);
9294
}
9395
}, $beta, $metadata, $this->logger ?? null);
9496
}

‎src/Symfony/Component/Config/Resource/ReflectionClassResource.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Resource/ReflectionClassResource.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface as LegacyServiceSubscriberInterface;
1515
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16+
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
1617
use Symfony\Contracts\Service\ServiceSubscriberInterface;
1718

1819
/**
@@ -158,6 +159,13 @@ private function generateSignature(\ReflectionClass $class)
158159
yield print_r($class->name::getSubscribedEvents(), true);
159160
}
160161

162+
if (interface_exists(MessageSubscriberInterface::class, false) && $class->isSubclassOf(MessageSubscriberInterface::class)) {
163+
yield MessageSubscriberInterface::class;
164+
foreach ($class->name::getHandledMessages() as $key => $value) {
165+
yield $key.print_r($value, true);
166+
}
167+
}
168+
161169
if (interface_exists(LegacyServiceSubscriberInterface::class, false) && $class->isSubclassOf(LegacyServiceSubscriberInterface::class)) {
162170
yield LegacyServiceSubscriberInterface::class;
163171
yield print_r([$class->name, 'getSubscribedServices'](), true);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.