8000 [WebProfilerBundle] Fix deprecated uses of profiler_dump by nicolas-grekas · Pull Request #20595 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WebProfilerBundle] Fix deprecated uses of profiler_dump #20595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ private function getTraces(RequestDataCollector $request, $method)
{
$traceRequest = Request::create(
$request->getPathInfo(),
$request->getRequestServer()->get('REQUEST_METHOD'),
$request->getRequestAttributes()->all(),
$request->getRequestCookies()->all(),
$request->getRequestServer(true)->get('REQUEST_METHOD'),
$request->getRequestAttributes(true)->all(),
$request->getRequestCookies(true)->all(),
array(),
$request->getRequestServer()->all()
$request->getRequestServer(true)->all()
);

$context = $this->matcher->getContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
{% endif %}

<h3>Request Headers</h3>
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestheaders, labels: ['Header', 'Value'] }, with_context = false) }}
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestheaders, labels: ['Header', 'Value'], maxDepth: 1 }, with_context = false) }}

<h3>Request Content</h3>

Expand Down Expand Up @@ -183,7 +183,7 @@
<div class="tab-content">
<h3>Response Headers</h3>

{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.responseheaders, labels: ['Header', 'Value'] }, with_context = false) }}
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.responseheaders, labels: ['Header', 'Value'], maxDepth: 1 }, with_context = false) }}
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function decorateVar($var)
return new ClassStub($var);
}
}
if (false !== strpos($var, DIRECTORY_SEPARATOR) && false === strpos($var, '://') && file_exists($var)) {
if (false !== strpos($var, DIRECTORY_SEPARATOR) && false === strpos($var, '://') && false === strpos($var, "\0") && is_file($var)) {
return new LinkStub($var);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
namespace Symfony\Component\HttpKernel\DataCollector;

use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
Expand Down Expand Up @@ -54,14 +52,11 @@ public function collect(Request $request, Response $response, \Exception $except
$attributes = array();
$route = '';
foreach ($request->attributes->all() as $key => $value) {
if ('_route' === $key && is_object($value)) {
$attributes[$key] = $this->cloneVar($value->getPath());
} else {
$attributes[$key] = $this->cloneVar($value);
}

if ('_route' === $key) {
$route = is_object($value) ? $value->getPath() : $value;
$attributes[$key] = $route;
} else {
$attributes[$key] = $value;
}
}

Expand Down Expand Up @@ -97,8 +92,8 @@ public function collect(Request $request, Response $response, \Exception $except
'content_type' => $response->headers->get('Content-Type', 'text/html'),
'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '',
'status_code' => $statusCode,
'request_query' => array_map(array($this, 'cloneVar'), $request->query->all()),
'request_request' => array_map(array($this, 'cloneVar'), $request->request->all()),
'request_query' => $request->query->all(),
'request_request' => $request->request->all(),
'request_headers' => $request->headers->all(),
'request_server' => $request->server->all(),
'request_cookies' => $request->cookies->all(),
Expand All @@ -125,6 +120,18 @@ public function collect(Request $request, Response $response, \Exception $except
$this->data['request_request']['_password'] = '******';
}

foreach ($this->data as $key => $value) {
if (!is_array($value)) {
continue;
}
if ('request_headers' === $key || 'response_headers' === $key) {
$value = array_map(function ($v) { return isset($v[1]) ? $v : $v[0]; }, $value);
}
if ('request_server' !== $key && 'request_attributes' !== $key && 'request_cookies' !== $key) {
$this->data[$key] = array_map(array($this, 'cloneVar'), $value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider adding cloneArray/Iterable by now ;-)

}
}

if (isset($this->controllers[$request])) {
$this->data['controller'] = $this->parseController($this->controllers[$request]);
unset($this->controllers[$request]);
Expand Down Expand Up @@ -170,27 +177,27 @@ public function getRequestQuery()

public function getRequestHeaders()
{
return new HeaderBag($this->data['request_headers']);
return new ParameterBag($this->data['request_headers']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are sure this breaks nothing right? In terms of possible unknown method calls by now (see also getResponseHeaders).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As decided in previous PRs about the profiler internals, we don't want to preserve bc here, that would slow us too much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was more thinking about references in core templates ;) but i guess were fine.

}

public function getRequestServer()
public function getRequestServer($raw = false)
{
return new ParameterBag($this->data['request_server']);
return new ParameterBag($raw ? $this->data['request_server'] : array_map(array($this, 'cloneVar'), $this->data['request_server']));
}

public function getRequestCookies()
public function getRequestCookies($raw = false)
{
return new ParameterBag($this->data['request_cookies']);
return new ParameterBag($raw ? $this->data['request_cookies'] : array_map(array($this, 'cloneVar'), $this->data['request_cookies']));
}

public function getRequestAttributes()
public function getRequestAttributes($raw = false)
{
return new ParameterBag($this->data['request_attributes']);
return new ParameterBag($raw ? $this->data['request_attributes'] : array_map(array($this, 'cloneVar'), $this->data['request_attributes']));
}

public function getResponseHeaders()
{
return new ResponseHeaderBag($this->data['response_headers']);
return new ParameterBag($this->data['response_headers']);
}

public function getSessionMetadata()
Expand Down Expand Up @@ -264,7 +271,7 @@ public function getIdentifier()
*/
public function getRouteParams()
{
return isset($this->data['request_attributes']['_route_params']) ? $this->data['request_attributes']['_route_params'] : $this->cloneVar(array());
return isset($this->data['request_attributes']['_route_params']) ? array_map(array($this, 'cloneVar'), $this->data['request_attributes']['_route_params']) : array();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ public function testCollect()
$attributes = $c->getRequestAttributes();

$this->assertSame('request', $c->getName());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getRequestHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestServer());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestCookies());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery());
$this->assertSame('html', $c->getFormat());
$this->assertEquals('foobar', $c->getRoute());
$this->assertEquals($cloner->cloneVar(array('name' => 'foo')), $c->getRouteParams());
$this->assertEquals(array('name' => $cloner->cloneVar('foo')), $c->getRouteParams());
$this->assertSame(array(), $c->getSessionAttributes());
$this->assertSame('en', $c->getLocale());
$this->assertEquals($cloner->cloneVar($request->attributes->get('resource')), $attributes->get('resource'));
$this->assertEquals($cloner->cloneVar($request->attributes->get('object')), $attributes->get('object'));

$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getResponseHeaders());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders());
$this->assertSame('OK', $c->getStatusText());
$this->assertSame(200, $c->getStatusCode());
$this->assertSame('application/json', $c->getContentType());
Expand Down
0