8000 Merge branch '4.2' · symfony/symfony@75eebcf · GitHub
[go: up one dir, main page]

Skip to content

Commit 75eebcf

Browse files
Merge branch '4.2'
* 4.2: [Routing] fix trailing slash redirections involving a trailing var [EventDispatcher] Revers event tracing order [Security] Prefer clone over unserialize(serialize()) for user refreshment [Console] OutputFormatter: move strtolower to createStyleFromString Adjust tests to work in the armhf architecture. Fixes #29281. Vietnamese translations improvement [Form] Fixed FormErrorIterator class phpdoc Renamed test controller from Controller to TestController so it doesn't show up in the IDE autocomplete. Don't use he in docs when its not needed EventSubscriberInterface isn't a man Fix undefined variable in cache ArrayTrait fixed public directory of web server and assets install when configured in composer.json
2 parents f2590d1 + 8a60907 commit 75eebcf

File tree

37 files changed

+1380
-1297
lines changed

37 files changed

+1380
-1297
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Input\InputOption;
1919
use Symfony\Component\Console\Output\OutputInterface;
2020
use Symfony\Component\Console\Style\SymfonyStyle;
21+
use Symfony\Component\DependencyInjection\ContainerInterface;
2122
use Symfony\Component\Filesystem\Exception\IOException;
2223
use Symfony\Component\Filesystem\Filesystem;
2324
use Symfony\Component\Finder\Finder;
@@ -56,7 +57,7 @@ protected function configure()
5657
{
5758
$this
5859
->setDefinition(array(
59-
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'),
60+
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', null),
6061
))
6162
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
6263
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
@@ -94,6 +95,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9495
$kernel = $this->getApplication()->getKernel();
9596
$targetArg = rtrim($input->getArgument('target'), '/');
9697

98+
if (!$targetArg) {
99+
$targetArg = $this->getPublicDirectory($this->getContainer());
100+
}
101+
97102
if (!is_dir($targetArg)) {
98103
$targetArg = $kernel->getProjectDir().'/'.$targetArg;
99104

@@ -250,4 +255,27 @@ private function hardCopy(string $originDir, string $targetDir): string
250255

251256
return self::METHOD_COPY;
252257
}
258+
259+
private function getPublicDirectory(ContainerInterface $container)
260+
{
261+
$defaultPublicDir = 'public';
262+
263+
if (!$container->hasParameter('kernel.project_dir')) {
264+
return $defaultPublicDir;
265+
}
266+
267+
$composerFilePath = $container->getParameter('kernel.project_dir').'/composer.json';
268+
269+
if (!file_exists($composerFilePath)) {
270+
return $defaultPublicDir;
271+
}
272+
273+
$composerConfig = json_decode(file_get_contents($composerFilePath), true);
274+
275+
if (isset($composerConfig['extra']['public-dir'])) {
276+
return $composerConfig['extra']['public-dir'];
277+
}
278+
279+
return $defaultPublicDir;
280+
}
253281
}

src/Symfony/Bundle/WebServerBundle/DependencyInjection/WebServerExtension.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,31 @@ public function load(array $configs, ContainerBuilder $container)
2727
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2828
$loader->load('webserver.xml');
2929

30+
$publicDirectory = $this->getPublicDirectory($container);
31+
$container->getDefinition('web_server.command.server_run')->replaceArgument(0, $publicDirectory);
32+
$container->getDefinition('web_server.command.server_start')->replaceArgument(0, $publicDirectory);
33+
3034
if (!class_exists(ConsoleFormatter::class)) {
3135
$container->removeDefinition('web_server.command.server_log');
3236
}
3337
}
38+
39+
private function getPublicDirectory(ContainerBuilder $container)
40+
{
41+
$kernelProjectDir = $container->getParameter('kernel.project_dir');
42+
$publicDir = 'public';
43+
$composerFilePath = $kernelProjectDir.'/composer.json';
44+
45+
if (!file_exists($composerFilePath)) {
46+
return $kernelProjectDir.'/'.$publicDir;
47+
}
48+
49+
$composerConfig = json_decode(file_get_contents($composerFilePath), true);
50+
51+
if (isset($composerConfig['extra']['public-dir'])) {
52+
$publicDir = $composerConfig['extra']['public-dir'];
53+
}
54+
55+
return $kernelProjectDir.'/'.$publicDir;
56+
}
3457
}

src/Symfony/Bundle/WebServerBundle/Tests/DependencyInjection/WebServerExtensionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ class WebServerExtensionTest extends TestCase
2121
public function testLoad()
2222
{
2323
$container = new ContainerBuilder();
24+
$container->setParameter('kernel.project_dir', __DIR__);
2425
(new WebServerExtension())->load(array(), $container);
2526

27+
$this->assertSame(
28+
__DIR__.'/test',
29+
$container->getDefinition('web_server.command.server_run')->getArgument(0)
30+
);
31+
$this->assertSame(
32+
__DIR__.'/test',
33+
$container->getDefinition('web_server.command.server_start')->getArgument(0)
34+
);
2635
$this->assertTrue($container->hasDefinition('web_server.command.server_run'));
2736
$this->assertTrue($container->hasDefinition('web_server.command.server_start'));
2837
$this->assertTrue($container->hasDefinition('web_server.command.server_stop'));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "test-composer.json",
3+
"extra": {
4+
"public-dir": "test"
5+
}
6+
}

src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function save(CacheItemInterface $item)
124124

125125
return true;
126126
}
127-
if ($this->storeSerialized && null === $value = $this->freeze($value)) {
127+
if ($this->storeSerialized && null === $value = $this->freeze($value, $key)) {
128128
return false;
129129
}
130130
if (null === $expiry && 0 < $item["\0*\0defaultLifetime"]) {

src/Symfony/Component/Cache/Simple/ArrayCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function setMultiple($values, $ttl = null)
129129
$expiry = 0 < $ttl ? microtime(true) + $ttl : PHP_INT_MAX;
130130

131131
foreach ($valuesArray as $key => $value) {
132-
if ($this->storeSerialized && null === $value = $this->freeze($value)) {
132+
if ($this->storeSerialized && null === $value = $this->freeze($value, $key)) {
133133
return false;
134134
}
135135
$this->values[$key] = $value;

src/Symfony/Component/Cache/Traits/ArrayTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private function generateItems(array $keys, $now, $f)
113113
}
114114
}
115115

116-
private function freeze($value)
116+
private function freeze($value, $key)
117117
{
118118
if (null === $value) {
119119
return 'N;';

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function formatAndWrap(string $message, int $width)
166166
if (!$open && !$tag) {
167167
// </>
168168
$this->styleStack->pop();
169-
} elseif (false === $style = $this->createStyleFromString(strtolower($tag))) {
169+
} elseif (false === $style = $this->createStyleFromString($tag)) {
170170
$output .= $this->applyCurrentStyle($text, $output, $width, $currentLineLength);
171171
} elseif ($open) {
172172
$this->styleStack->push($style);
@@ -210,15 +210,16 @@ private function createStyleFromString(string $string)
210210
$style = new OutputFormatterStyle();
211211
foreach ($matches as $match) {
212212
array_shift($match);
213+
$match[0] = strtolower($match[0]);
213214

214215
if ('fg' == $match[0]) {
215-
$style->setForeground($match[1]);
216+
$style->setForeground(strtolower($match[1]));
216217
} elseif ('bg' == $match[0]) {
217-
$style->setBackground($match[1]);
218+
$style->setBackground(strtolower($match[1]));
218219
} elseif ('href' === $match[0]) {
219220
$style->setHref($match[1]);
220221
} elseif ('options' === $match[0]) {
221-
preg_match_all('([^,;]+)', $match[1], $options);
222+
preg_match_all('([^,;]+)', strtolower($match[1]), $options);
222223
$options = array_shift($options);
223224
foreach ($options as $option) {
224225
$style->setOption($option);

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
2929
protected $logger;
3030
protected $stopwatch;
3131

32-
private $called;
32+
private $callStack;
3333
private $dispatcher;
3434
private $wrappedListeners;
3535
private $orphanedEvents;
@@ -39,7 +39,6 @@ public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $sto
3939
$this->dispatcher = $dispatcher;
4040
$this->stopwatch = $stopwatch;
4141
$this->logger = $logger;
42-
$this->called = array();
4342
$this->wrappedListeners = array();
4443
$this->orphanedEvents = array();
4544
}
@@ -125,6 +124,10 @@ public function hasListeners($eventName = null)
125124
*/
126125
public function dispatch($eventName, Event $event = null)
127126
{
127+
if (null === $this->callStack) {
128+
$this->callStack = new \SplObjectStorage();
129+
}
130+
128131
if (null === $event) {
129132
$event = new Event();
130133
}
@@ -160,11 +163,15 @@ public function dispatch($eventName, Event $event = null)
160163
*/
161164
public function getCalledListeners()
162165
{
166+
if (null === $this->callStack) {
167+
return array();
168+
}
169+
163170
$called = array();
164-
foreach ($this->called as $eventName => $listeners) {
165-
foreach ($listeners as $listener) {
166-
$called[$eventName.'.'.$listener->getPretty()] = $listener->getInfo($eventName);
167-
}
171+
foreach ($this->callStack as $listener) {
172+
list($eventName) = $this->callStack->getInfo();
173+
174+
$called[] = $listener->getInfo($eventName);
168175
}
169176

170177
return $called;
@@ -190,9 +197,9 @@ public function getNotCalledListeners()
190197
foreach ($allListeners as $eventName => $listeners) {
191198
foreach ($listeners as $listener) {
192199
$called = false;
193-
if (isset($this->called[$eventName])) {
194-
foreach ($this->called[$eventName] as $l) {
195-
if ($l->getWrappedListener() === $listener) {
200+
if (null !== $this->callStack) {
201+
foreach ($this->callStack as $calledListener) {
202+
if ($calledListener->getWrappedListener() === $listener) {
196203
$called = true;
197204

198205
break;
@@ -204,12 +211,12 @@ public function getNotCalledListeners()
204211
if (!$listener instanceof WrappedListener) {
205212
$listener = new WrappedListener($listener, null, $this->stopwatch, $this);
206213
}
207-
$notCalled[$eventName.'.'.$listener->getPretty()] = $listener->getInfo($eventName);
214+
$notCalled[] = $listener->getInfo($eventName);
208215
}
209216
}
210217
}
211218

212-
uasort($notCalled, array($this, 'sortListenersByPriority'));
219+
uasort($notCalled, array($this, 'sortNotCalledListeners'));
213220

214221
return $notCalled;
215222
}
@@ -221,7 +228,7 @@ public function getOrphanedEvents(): array
221228

222229
public function reset()
223230
{
224-
$this->called = array();
231+
$this->callStack = array();
225232
$this->orphanedEvents = array();
226233
}
227234

@@ -272,6 +279,7 @@ private function preProcess($eventName)
272279
$this->wrappedListeners[$eventName][] = $wrappedListener;
273280
$this->dispatcher->removeListener($eventName, $listener);
274281
$this->dispatcher->addListener($eventName, $wrappedListener, $priority);
282+
$this->callStack->attach($wrappedListener, array($eventName));
275283
}
276284
}
277285

@@ -300,8 +308,8 @@ private function postProcess($eventName)
300308
if (!isset($this->called[$eventName])) {
301309
$this->called[$eventName] = new \SplObjectStorage();
302310
}
303-
304-
$this->called[$eventName]->attach($listener);
311+
} else {
312+
$this->callStack->detach($listener);
305313
}
306314

307315
if (null !== $this->logger && $skipped) {
@@ -318,8 +326,12 @@ private function postProcess($eventName)
318326
}
319327
}
320328

321-
private function sortListenersByPriority($a, $b)
329+
private function sortNotCalledListeners(array $a, array $b)
322330
{
331+
if (0 !== $cmp = strcmp($a['event'], $b['event'])) {
332+
return $cmp;
333+
}
334+
323335
if (\is_int($a['priority']) && !\is_int($b['priority'])) {
324336
return 1;
325337
}

src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function addListener($eventName, $listener, $priority = 0);
4646
/**
4747
* Adds an event subscriber.
4848
*
49-
* The subscriber is asked for all the events he is
49+
* The subscriber is asked for all the events it is
5050
* interested in and added as a listener for these events.
5151
*/
5252
public function addSubscriber(EventSubscriberInterface $subscriber);

src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\EventDispatcher;
1313

1414
/**
15-
* An EventSubscriber knows himself what events he is interested in.
15+
* An EventSubscriber knows itself what events it is interested in.
1616
* If an EventSubscriber is added to an EventDispatcherInterface, the manager invokes
1717
* {@link getSubscribedEvents} and registers the subscriber as a listener for all
1818
* returned events.

src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ public function testGetCalledListeners()
110110
$tdispatcher->addListener('foo', function () {}, 5);
111111

112112
$listeners = $tdispatcher->getNotCalledListeners();
113-
$this->assertArrayHasKey('stub', $listeners['foo.closure']);
114-
unset($listeners['foo.closure']['stub']);
113+
$this->assertArrayHasKey('stub', $listeners[0]);
114+
unset($listeners[0]['stub']);
115115
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
116-
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
116+
$this->assertEquals(array(array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
117117

118118
$tdispatcher->dispatch('foo');
119119

120120
$listeners = $tdispatcher->getCalledListeners();
121-
$this->assertArrayHasKey('stub', $listeners['foo.closure']);
122-
unset($listeners['foo.closure']['stub']);
123-
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
121+
$this->assertArrayHasKey('stub', $listeners[0]);
122+
unset($listeners[0]['stub']);
123+
$this->assertEquals(array(array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
124124
$this->assertEquals(array(), $tdispatcher->getNotCalledListeners());
125125
}
126126

@@ -133,10 +133,10 @@ public function testClearCalledListeners()
133133
$tdispatcher->reset();
134134

135135
$listeners = $tdispatcher->getNotCalledListeners();
136-
$this->assertArrayHasKey('stub', $listeners['foo.closure']);
137-
unset($listeners['foo.closure']['stub']);
136+
$this->assertArrayHasKey('stub', $listeners[0]);
137+
unset($listeners[0]['stub']);
138138
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
139-
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
139+
$this->assertEquals(array(array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
140140
}
141141

142142
public function testGetCalledListenersNested()

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private function addSubForm(FormBuilderInterface $builder, string $name, ChoiceV
378378
if ($options['multiple']) {
379379
$choiceType = __NAMESPACE__.'\CheckboxType';
380380
// The user can check 0 or more checkboxes. If required
381-
// is true, he is required to check all of them.
381+
// is true, they are required to check all of them.
382382
$choiceOpts['required'] = false;
383383
} else {
384384
$choiceType = __NAMESPACE__.'\RadioType';

src/Symfony/Component/Form/FormErrorIterator.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
/**
2020
* Iterates over the errors of a form.
2121
*
22-
* Optionally, this class supports recursive iteration. In order to iterate
23-
* recursively, set the constructor argument $deep to true. Now each element
24-
* returned by the iterator is either an instance of {@link FormError} or of
25-
* {@link FormErrorIterator}, in case the errors belong to a sub-form.
22+
* This class supports recursive iteration. In order to iterate recursively,
23+
* pass a structure of {@link FormError} and {@link FormErrorIterator} objects
24+
* to the $errors constructor argument.
2625
*
2726
* You can also wrap the iterator into a {@link \RecursiveIteratorIterator} to
2827
* flatten the recursive structure into a flat list of errors.

0 commit comments

Comments
 (0)
0