diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php
index ba8a94633282..b6744c585579 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php
+++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php
@@ -216,6 +216,7 @@ public function searchBarAction(Request $request)
if (null === $session = $request->getSession()) {
$ip =
$method =
+ $statusCode =
$url =
$start =
$end =
@@ -224,6 +225,7 @@ public function searchBarAction(Request $request)
} else {
$ip = $request->query->get('ip', $session->get('_profiler_search_ip'));
$method = $request->query->get('method', $session->get('_profiler_search_method'));
+ $statusCode = $request->query->get('status_code', $session->get('_profiler_search_status_code'));
$url = $request->query->get('url', $session->get('_profiler_search_url'));
$start = $request->query->get('start', $session->get('_profiler_search_start'));
$end = $request->query->get('end', $session->get('_profiler_search_end'));
@@ -236,6 +238,7 @@ public function searchBarAction(Request $request)
'token' => $token,
'ip' => $ip,
'method' => $method,
+ 'status_code' => $statusCode,
'url' => $url,
'start' => $start,
'end' => $end,
@@ -269,6 +272,7 @@ public function searchResultsAction(Request $request, $token)
$ip = $request->query->get('ip');
$method = $request->query->get('method');
+ $statusCode = $request->query->get('status_code');
$url = $request->query->get('url');
$start = $request->query->get('start', null);
$end = $request->query->get('end', null);
@@ -278,9 +282,10 @@ public function searchResultsAction(Request $request, $token)
'request' => $request,
'token' => $token,
'profile' => $profile,
- 'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end),
+ 'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end, $statusCode),
'ip' => $ip,
'method' => $method,
+ 'status_code' => $statusCode,
'url' => $url,
'start' => $start,
'end' => $end,
@@ -308,6 +313,7 @@ public function searchAction(Request $request)
$ip = preg_replace('/[^:\d\.]/', '', $request->query->get('ip'));
$method = $request->query->get('method');
+ $statusCode = $request->query->get('status_code');
$url = $request->query->get('url');
$start = $request->query->get('start', null);
$end = $request->query->get('end', null);
@@ -317,6 +323,7 @@ public function searchAction(Request $request)
if (null !== $session = $request->getSession()) {
$session->set('_profiler_search_ip', $ip);
$session->set('_profiler_search_method', $method);
+ $session->set('_profiler_search_status_code', $statusCode);
$session->set('_profiler_search_url', $url);
$session->set('_profiler_search_start', $start);
$session->set('_profiler_search_end', $end);
@@ -328,12 +335,13 @@ public function searchAction(Request $request)
return new RedirectResponse($this->generator->generate('_profiler', array('token' => $token)), 302, array('Content-Type' => 'text/html'));
}
- $tokens = $this->profiler->find($ip, $url, $limit, $method, $start, $end);
+ $tokens = $this->profiler->find($ip, $url, $limit, $method, $start, $end, $statusCode);
return new RedirectResponse($this->generator->generate('_profiler_search_results', array(
'token' => $tokens ? $tokens[0]['token'] : 'empty',
'ip' => $ip,
'method' => $method,
+ 'status_code' => $statusCode,
'url' => $url,
'start' => $start,
'end' => $end,
diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.html.twig
index 3661c8abc646..f25893a9d46d 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.html.twig
+++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.html.twig
@@ -15,6 +15,11 @@
+
+
+
+
+
diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php
index a6b9d3b34024..19443ed0db46 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php
+++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php
@@ -123,6 +123,7 @@ public function testSearchResult()
'tokens' => $tokens,
'ip' => '127.0.0.1',
'method' => 'GET',
+ 'status_code' => null,
'url' => 'http://example.com/',
'start' => null,
'end' => null,
diff --git a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php
index 29da4abf32cc..bd8761f5dd8a 100644
--- a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php
+++ b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php
@@ -49,7 +49,7 @@ public function __construct($dsn)
/**
* {@inheritdoc}
*/
- public function find($ip, $url, $limit, $method, $start = null, $end = null)
+ public function find($ip, $url, $limit, $method, $start = null, $end = null, $statusCode = null)
{
$file = $this->getIndexFilename();
@@ -63,12 +63,10 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
$result = array();
while (count($result) < $limit && $line = $this->readLineFromFile($file)) {
$values = str_getcsv($line);
- list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent) = $values;
- $csvStatusCode = isset($values[6]) ? $values[6] : null;
-
+ list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode) = $values;
$csvTime = (int) $csvTime;
- if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method)) {
+ if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method) || $statusCode && false === strpos($csvStatusCode, $statusCode)) {
continue;
}
@@ -154,6 +152,7 @@ public function write(Profile $profile)
'method' => $profile->getMethod(),
'url' => $profile->getUrl(),
'time' => $profile->getTime(),
+ 'status_code' => $profile->getStatusCode(),
);
if (false === file_put_contents($file, serialize($data))) {
@@ -261,6 +260,7 @@ protected function createProfileFromData($token, $data, $parent = null)
$profile->setMethod($data['method']);
$profile->setUrl($data['url']);
$profile->setTime($data['time']);
+ $profile->setStatusCode($data['status_code']);
$profile->setCollectors($data['data']);
if (!$parent && $data['parent']) {
diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profile.php b/src/Symfony/Component/HttpKernel/Profiler/Profile.php
index a4e4ba6ad66b..1ea045a46f25 100644
--- a/src/Symfony/Component/HttpKernel/Profiler/Profile.php
+++ b/src/Symfony/Component/HttpKernel/Profiler/Profile.php
@@ -287,6 +287,6 @@ public function hasCollector($name)
public function __sleep()
{
- return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time');
+ return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode');
}
}
diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php
index 8373a151b5d6..9ec308caf744 100644
--- a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php
+++ b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php
@@ -134,20 +134,21 @@ public function purge()
/**
* Finds profiler tokens for the given criteria.
*
- * @param string $ip The IP
- * @param string $url The URL
- * @param string $limit The maximum number of tokens to return
- * @param string $method The request method
- * @param string $start The start date to search from
- * @param string $end The end date to search to
+ * @param string $ip The IP
+ * @param string $url The URL
+ * @param string $limit The maximum number of tokens to return
+ * @param string $method The request method
+ * @param string $start The start date to search from
+ * @param string $end The end date to search to
+ * @param string $statusCode The request status code
*
* @return array An array of tokens
*
* @see http://php.net/manual/en/datetime.formats.php for the supported date/time formats
*/
- public function find($ip, $url, $limit, $method, $start, $end)
+ public function find($ip, $url, $limit, $method, $start, $end, $statusCode = null)
{
- return $this->storage->find($ip, $url, $limit, $method, $this->getTimestamp($start), $this->getTimestamp($end));
+ return $this->storage->find($ip, $url, $limit, $method, $this->getTimestamp($start), $this->getTimestamp($end), $statusCode);
}
/**
diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php
index 6f53de831864..435cce475c2a 100644
--- a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php
@@ -127,6 +127,20 @@ public function testRetrieveByIp()
$this->assertCount(0, $this->storage->find('127.0._.1', '', 10, 'GET'), '->find() does not interpret a "_" as a wildcard in the IP');
}
+ public function testRetrieveByStatusCode()
+ {
+ $profile200 = new Profile('statuscode200');
+ $profile200->setStatusCode(200);
+ $this->storage->write($profile200);
+
+ $profile404 = new Profile('statuscode404');
+ $profile404->setStatusCode(404);
+ $this->storage->write($profile404);
+
+ $this->assertCount(1, $this->storage->find(null, null, 10, null, null, null, '200'), '->find() retrieve a record by Status code 200');
+ $this->assertCount(1, $this->storage->find(null, null, 10, null, null, null, '404'), '->find() retrieve a record by Status code 404');
+ }
+
public function testRetrieveByUrl()
{
$profile = new Profile('simple_quote');
diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php
index 6e56f8bcf5c3..fe4f430777be 100644
--- a/src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php
@@ -59,6 +59,13 @@ public function testFindWorksWithInvalidDates()
$this->assertCount(0, $profiler->find(null, null, null, null, 'some string', ''));
}
+ public function testFindWorksWithStatusCode()
+ {
+ $profiler = new Profiler($this->storage);
+
+ $this->assertCount(0, $profiler->find(null, null, null, null, null, null, '204'));
+ }
+
protected function setUp()
{
$this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');