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 e7ffb40

Browse filesBrowse files
[VarDumper] Replace Dumper/ServerDumper by Server/Connection
1 parent 6e0818d commit e7ffb40
Copy full SHA for e7ffb40

File tree

13 files changed

+80
-112
lines changed
Filter options

13 files changed

+80
-112
lines changed

‎src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php
+10-14Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\DependencyInjection\Extension\Extension;
1818
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1919
use Symfony\Component\DependencyInjection\Reference;
20-
use Symfony\Component\VarDumper\Dumper\ServerDumper;
2120

2221
/**
2322
* DebugExtension.
@@ -43,20 +42,21 @@ public function load(array $configs, ContainerBuilder $container)
4342
->addMethodCall('setMaxString', array($config['max_string_length']));
4443

4544
if (null === $config['dump_destination']) {
46-
//no-op
45+
$container->getDefinition('var_dumper.command.server_dump')
46+
->setClass(ServerDumpPlaceholderCommand::class)
47+
;
4748
} elseif (0 === strpos($config['dump_destination'], 'tcp://')) {
48-
$serverDumperHost = $config['dump_destination'];
4949
$container->getDefinition('debug.dump_listener')
5050
->replaceArgument(1, new Reference('var_dumper.server_dumper'))
5151
;
5252
$container->getDefinition('data_collector.dump')
53-
->replaceArgument(4, new Reference('var_dumper.server_dumper'))
53+
->replaceArgument(4, new Reference('var_dumper.server_connection'))
5454
;
5555
$container->getDefinition('var_dumper.dump_server')
56-
->replaceArgument(0, $serverDumperHost)
56+
->replaceArgument(0, $config['dump_destination'])
5757
;
58-
$container->getDefinition('var_dumper.server_dumper')
59-
->replaceArgument(0, $serverDumperHost)
58+
$container->getDefinition('var_dumper.server_connection')
59+
->replaceArgument(0, $config['dump_destination'])
6060
;
6161
} else {
6262
$container->getDefinition('var_dumper.cli_dumper')
@@ -65,13 +65,9 @@ public function load(array $configs, ContainerBuilder $container)
6565
$container->getDefinition('data_collector.dump')
6666
->replaceArgument(4, new Reference('var_dumper.cli_dumper'))
6767
;
68-
}
69-
70-
if (!isset($serverDumperHost)) {
71-
$container->getDefinition('var_dumper.command.server_dump')->setClass(ServerDumpPlaceholderCommand::class);
72-
if (!class_exists(ServerDumper::class)) {
73-
$container->removeDefinition('var_dumper.command.server_dump');
74-
}
68+
$container->getDefinition('var_dumper.command.server_dump')
69+
->setClass(ServerDumpPlaceholderCommand::class)
70+
;
7571
}
7672
}
7773

‎src/Symfony/Bundle/DebugBundle/Resources/config/services.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/DebugBundle/Resources/config/services.xml
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<argument type="service" id="debug.file_link_formatter" on-invalid="ignore"></argument>
2424
<argument>%kernel.charset%</argument>
2525
<argument type="service" id="request_stack" />
26-
<argument>null</argument><!-- var_dumper.cli_dumper or var_dumper.server_dumper when debug.dump_destination is set -->
26+
<argument>null</argument><!-- var_dumper.cli_dumper or var_dumper.server_connection when debug.dump_destination is set -->
2727
</service>
2828

2929
<service id="debug.dump_listener" class="Symfony\Component\HttpKernel\EventListener\DumpListener">
@@ -50,24 +50,23 @@
5050
</call>
5151
</service>
5252

53-
<service id="var_dumper.server_dumper" class="Symfony\Component\VarDumper\Dumper\ServerDumper">
54-
<argument>null</argument> <!-- server host -->
55-
<argument type="service" id="var_dumper.cli_dumper" />
53+
<service id="var_dumper.server_connection" class="Symfony\Component\VarDumper\Server\Connection">
54+
<argument /> <!-- server host -->
5655
<argument type="collection">
5756
<argument type="service" key="source">
58-
<service class="Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider">
57+
<service class="Symfony\Component\VarDumper\Server\ContextProvider\SourceContextProvider">
5958
<argument>%kernel.charset%</argument>
6059
<argument type="string">%kernel.project_dir%</argument>
6160
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
6261
</service>
6362
</argument>
6463
<argument type="service" key="request">
65-
<service class="Symfony\Component\VarDumper\Dumper\ContextProvider\RequestContextProvider">
64+
<service class="Symfony\Component\VarDumper\Server\ContextProvider\RequestContextProvider">
6665
<argument type="service" id="request_stack" />
6766
</service>
6867
</argument>
6968
<argument type="service" key="cli">
70-
<service class="Symfony\Component\VarDumper\Dumper\ContextProvider\CliContextProvider" />
69+
<service class="Symfony\Component\VarDumper\Server\ContextProvider\CliContextProvider" />
7170
</argument>
7271
</argument>
7372
</service>

‎src/Symfony/Bundle/DebugBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/DebugBundle/composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"require": {
1919
"php": "^7.1.3",
2020
"ext-xml": "*",
21-
"symfony/http-kernel": "~3.4|~4.0",
21+
"symfony/http-kernel": "^4.1.1",
2222
"symfony/twig-bridge": "~3.4|~4.0",
23-
"symfony/var-dumper": "~4.1"
23+
"symfony/var-dumper": "^4.1.1"
2424
},
2525
"require-dev": {
2626
"symfony/config": "~3.4|~4.0",

‎src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php
+15-14Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
use Symfony\Component\VarDumper\Cloner\Data;
1919
use Symfony\Component\VarDumper\Cloner\VarCloner;
2020
use Symfony\Component\VarDumper\Dumper\CliDumper;
21-
use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider;
2221
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
2322
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
24-
use Symfony\Component\VarDumper\Dumper\ServerDumper;
23+
use Symfony\Component\VarDumper\Server\Connection;
24+
use Symfony\Component\VarDumper\Server\ContextProvider\SourceContextProvider;
2525

2626
/**
2727
* @author Nicolas Grekas <p@tchwork.com>
@@ -38,17 +38,18 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
3838
private $charset;
3939
private $requestStack;
4040
private $dumper;
41-
private $dumperIsInjected;
4241
private $sourceContextProvider;
4342

44-
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, DataDumperInterface $dumper = null)
43+
/**
44+
* @param DataDumperInterface|Connection|null $dumper
45+
*/
46+
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, $dumper = null)
4547
{
4648
$this->stopwatch = $stopwatch;
4749
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4850
$this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8';
4951
$this->requestStack = $requestStack;
5052
$this->dumper = $dumper;
51-
$this->dumperIsInjected = null !== $dumper;
5253

5354
// All clones share these properties by reference:
5455
$this->rootRefs = array(
@@ -58,7 +59,7 @@ public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null,
5859
&$this->clonesCount,
5960
);
6061

61-
$this->sourceContextProvider = $dumper instanceof ServerDumper && isset($dumper->getContextProviders()['source']) ? $dumper->getContextProviders()['source'] : new SourceContextProvider($this->charset);
62+
$this->sourceContextProvider = $dumper instanceof Connection && isset($dumper->getContextProviders()['source']) ? $dumper->getContextProviders()['source'] : new SourceContextProvider($this->charset);
6263
}
6364

6465
public function __clone()
@@ -71,14 +72,17 @@ public function dump(Data $data)
7172
if ($this->stopwatch) {
7273
$this->stopwatch->start('dump');
7374
}
74-
if ($this->isCollected && !$this->dumper) {
75-
$this->isCollected = false;
76-
}
7775

7876
list('name' => $name, 'file' => $file, 'line' => $line, 'file_excerpt' => $fileExcerpt) = $this->sourceContextProvider->getContext();
7977

80-
if ($this->dumper) {
78+
if ($this->dumper instanceof Connection) {
79+
if (!$this->dumper->write($data)) {
80+
$this->isCollected = false;
81+
}
82+
} elseif ($this->dumper) {
8183
$this->doDump($this->dumper, $data, $name, $file, $line);
84+
} else {
85+
$this->isCollected = false;
8286
}
8387

8488
$this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt');
@@ -141,9 +145,6 @@ public function serialize()
141145
$this->data = array();
142146
$this->dataCount = 0;
143147
$this->isCollected = true;
144-
if (!$this->dumperIsInjected) {
145-
$this->dumper = null;
146-
}
147148

148149
return $ser;
149150
}
@@ -245,7 +246,7 @@ private function doDump(DataDumperInterface $dumper, $data, $name, $file, $line)
245246
};
246247
$contextDumper = $contextDumper->bindTo($dumper, $dumper);
247248
$contextDumper($name, $file, $line, $this->fileLinkFormat);
248-
} elseif (!$dumper instanceof ServerDumper) {
249+
} else {
249250
$cloner = new VarCloner();
250251
$dumper->dump($cloner->cloneVar($name.' on line '.$line.':'));
251252
}

‎src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
1818
use Symfony\Component\VarDumper\Cloner\Data;
1919
use Symfony\Component\VarDumper\Dumper\CliDumper;
20-
use Symfony\Component\VarDumper\Dumper\ServerDumper;
20+
use Symfony\Component\VarDumper\Server\Connection;
2121

2222
/**
2323
* @author Nicolas Grekas <p@tchwork.com>
@@ -57,13 +57,13 @@ public function testDump()
5757
$this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
5858
}
5959

60-
public function testDumpWithServerDumper()
60+
public function testDumpWithServerConnection()
6161
{
6262
$data = new Data(array(array(123)));
6363

6464
// Server is up, server dumper is used
65-
$serverDumper = $this->getMockBuilder(ServerDumper::class)->disableOriginalConstructor()->getMock();
66-
$serverDumper->expects($this->once())->method('dump');
65+
$serverDumper = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
66+
$serverDumper->expects($this->once())->method('write')->willReturn(true);
6767

6868
$collector = new DumpDataCollector(null, null, null, null, $serverDumper);
6969
$collector->dump($data);

‎src/Symfony/Component/HttpKernel/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"symfony/stopwatch": "~3.4|~4.0",
3838
"symfony/templating": "~3.4|~4.0",
3939
"symfony/translation": "~3.4|~4.0",
40-
"symfony/var-dumper": "~4.1",
40+
"symfony/var-dumper": "^4.1.1",
4141
"psr/cache": "~1.0"
4242
},
4343
"provide": {
@@ -46,7 +46,7 @@
4646
"conflict": {
4747
"symfony/config": "<3.4",
4848
"symfony/dependency-injection": "<4.1",
49-
"symfony/var-dumper": "<4.1",
49+
"symfony/var-dumper": "<4.1.1",
5050
"twig/twig": "<1.34|<2.4,>=2"
5151
},
5252
"suggest": {

‎src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function dump(Data $data, $output = null)
164164
*/
165165
protected function dumpLine($depth)
166166
{
167-
call_user_func($this->lineDumper, $this->line, $depth, $this->indentPad);
167+
\call_user_func($this->lineDumper, $this->line, $depth, $this->indentPad);
168168
$this->line = '';
169169
}
170170

‎src/Symfony/Component/VarDumper/Dumper/ServerDumper.php renamed to ‎src/Symfony/Component/VarDumper/Server/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Server/Connection.php
+19-36Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,33 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\VarDumper\Dumper;
12+
namespace Symfony\Component\VarDumper\Server;
1313

1414
use Symfony\Component\VarDumper\Cloner\Data;
15-
use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;
15+
use Symfony\Component\VarDumper\Server\ContextProvider\ContextProviderInterface;
1616

1717
/**
18-
* ServerDumper forwards serialized Data clones to a server.
18+
* Forwards serialized Data clones to a server.
1919
*
2020
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
2121
*/
22-
class ServerDumper implements DataDumperInterface
22+
class Connection
2323
{
2424
private $host;
25-
private $wrappedDumper;
2625
private $contextProviders;
2726
private $socket;
2827

2928
/**
3029
* @param string $host The server host
31-
* @param DataDumperInterface|null $wrappedDumper A wrapped instance used whenever we failed contacting the server
3230
* @param ContextProviderInterface[] $contextProviders Context providers indexed by context name
3331
*/
34-
public function __construct(string $host, DataDumperInterface $wrappedDumper = null, array $contextProviders = array())
32+
public function __construct(string $host, array $contextProviders = array())
3533
{
3634
if (false === strpos($host, '://')) {
3735
$host = 'tcp://'.$host;
3836
}
3937

4038
$this->host = $host;
41-
$this->wrappedDumper = $wrappedDumper;
4239
$this->contextProviders = $contextProviders;
4340
}
4441

@@ -47,66 +44,52 @@ public function getContextProviders(): array
4744
return $this->contextProviders;
4845
}
4946

50-
/**
51-
* {@inheritdoc}
52-
*/
53-
public function dump(Data $data, $output = null): void
47+
public function write(Data $data): bool
5448
{
5549
set_error_handler(array(self::class, 'nullErrorHandler'));
56-
57-
$failed = false;
5850
try {
5951
if (!$this->socket = $this->socket ?: $this->createSocket()) {
60-
$failed = true;
61-
62-
return;
52+
return false;
6353
}
6454
} finally {
6555
restore_error_handler();
66-
if ($failed && $this->wrappedDumper) {
67-
$this->wrappedDumper->dump($data);
68-
}
6956
}
7057

71-
set_error_handler(array(self::class, 'nullErrorHandler'));
72-
73-
$context = array('timestamp' => time());
58+
$context = array('timestamp' => microtime(true));
7459
foreach ($this->contextProviders as $name => $provider) {
7560
$context[$name] = $provider->getContext();
7661
}
7762
$context = array_filter($context);
78-
7963
$encodedPayload = base64_encode(serialize(array($data, $context)))."\n";
80-
$failed = false;
8164

65+
set_error_handler(array(self::class, 'nullErrorHandler'));
8266
try {
8367
$retry = 3;
84-
while ($retry > 0 && $failed = (-1 === stream_socket_sendto($this->socket, $encodedPayload))) {
68+
while (true) {
69+
if (-1 !== stream_socket_sendto($this->socket, $encodedPayload)) {
70+
return true;
71+
}
8572
stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
86-
if ($failed = !$this->socket = $this->createSocket()) {
73+
74+
if (0 === --$retry || !$this->socket = $this->createSocket()) {
8775
break;
8876
}
89-
90-
--$retry;
9177
}
9278
} finally {
9379
restore_error_handler();
94-
if ($failed && $this->wrappedDumper) {
95-
$this->wrappedDumper->dump($data);
96-
}
9780
}
81+
82+
return false;
9883
}
9984

10085
private static function nullErrorHandler()
10186
{
102-
// noop
87+
// no-op
10388
}
10489

10590
private function createSocket()
10691
{
107-
$socket = stream_socket_client($this->host, $errno, $errstr, 1, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);
108-
109-
if ($socket) {
92+
if ($socket = stream_socket_client($this->host, $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_PERSISTENT)) {
11093
stream_set_blocking($socket, false);
11194
}
11295

‎src/Symfony/Component/VarDumper/Dumper/ContextProvider/CliContextProvider.php renamed to ‎src/Symfony/Component/VarDumper/Server/ContextProvider/CliContextProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Server/ContextProvider/CliContextProvider.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\VarDumper\Dumper\ContextProvider;
12+
namespace Symfony\Component\VarDumper\Server\ContextProvider;
1313

1414
/**
1515
* Tries to provide context on CLI.
1616
*
1717
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
18+
*
19+
* @final
1820
*/
19-
final class CliContextProvider implements ContextProviderInterface
21+
class CliContextProvider implements ContextProviderInterface
2022
{
2123
public function getContext(): ?array
2224
{

‎src/Symfony/Component/VarDumper/Dumper/ContextProvider/ContextProviderInterface.php renamed to ‎src/Symfony/Component/VarDumper/Server/ContextProvider/ContextProviderInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Server/ContextProvider/ContextProviderInterface.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\VarDumper\Dumper\ContextProvider;
12+
namespace Symfony\Component\VarDumper\Server\ContextProvider;
1313

1414
/**
1515
* Interface to provide contextual data about dump data clones sent to a server.

0 commit comments

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