[Profiler] Sync with master
This commit is contained in:
parent
1aef4e806b
commit
5f2226807c
@ -287,7 +287,7 @@ class ProfilerController extends ContainerAware
|
||||
protected function getTemplateNames($profiler)
|
||||
{
|
||||
$templates = array();
|
||||
foreach ($this->container->getParameter('data_collector.templates') as $id => $arguments) {
|
||||
foreach ($this->container->getParameter('data_collector.templates') as $arguments) {
|
||||
if (null === $arguments) {
|
||||
continue;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
<div class="clear_fix"></div>
|
||||
<label for="method">Method</label>
|
||||
<select name="method" id="method">
|
||||
{% for m in ['', 'DELETE', 'GET', 'HEAD', 'POST', 'PUT'] %}
|
||||
{% for m in ['', 'DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'] %}
|
||||
<option{{ m == method ? ' selected="selected"' : '' }}>{{ m }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
@ -46,7 +46,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find($ip, $url, $limit)
|
||||
public function find($ip, $url, $limit, $method)
|
||||
{
|
||||
$file = $this->getIndexFilename();
|
||||
|
||||
@ -66,26 +66,27 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
break;
|
||||
}
|
||||
|
||||
if ($line === "") {
|
||||
if ($line === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
list($csvToken, $csvIp, $csvUrl, $csvTime, $csvParent) = str_getcsv($line);
|
||||
list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent) = str_getcsv($line);
|
||||
|
||||
if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url)) {
|
||||
if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = array(
|
||||
'token' => $csvToken,
|
||||
'ip' => $csvIp,
|
||||
'method' => $csvMethod,
|
||||
'url' => $csvUrl,
|
||||
'time' => $csvTime,
|
||||
'parent' => $csvParent,
|
||||
);
|
||||
|
||||
$result[] = $row;
|
||||
$limit--;
|
||||
--$limit;
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
@ -143,6 +144,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
|
||||
'data' => $profile->getCollectors(),
|
||||
'ip' => $profile->getIp(),
|
||||
'method' => $profile->getMethod(),
|
||||
'url' => $profile->getUrl(),
|
||||
'time' => $profile->getTime(),
|
||||
);
|
||||
@ -159,6 +161,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
fputcsv($file, array(
|
||||
$profile->getToken(),
|
||||
$profile->getIp(),
|
||||
$profile->getMethod(),
|
||||
$profile->getUrl(),
|
||||
$profile->getTime(),
|
||||
$profile->getParent() ? $profile->getParent()->getToken() : null,
|
||||
@ -219,7 +222,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
break;
|
||||
}
|
||||
|
||||
$str = $char . $str;
|
||||
$str = $char.$str;
|
||||
|
||||
if (ftell($file) === 1) {
|
||||
// All file is read, so we move cursor to the position 0
|
||||
@ -237,6 +240,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
{
|
||||
$profile = new Profile($token);
|
||||
$profile->setIp($data['ip']);
|
||||
$profile->setMethod($data['method']);
|
||||
$profile->setUrl($data['url']);
|
||||
$profile->setTime($data['time']);
|
||||
$profile->setCollectors($data['data']);
|
||||
|
@ -37,9 +37,9 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
|
||||
*
|
||||
* @return array An array of tokens
|
||||
*/
|
||||
public function find($ip, $url, $limit)
|
||||
public function find($ip, $url, $limit, $method)
|
||||
{
|
||||
$cursor = $this->getMongo()->find($this->buildQuery($ip, $url), array('_id', 'parent', 'ip', 'url', 'time'))->sort(array('time' => -1))->limit($limit);
|
||||
$cursor = $this->getMongo()->find($this->buildQuery($ip, $url, $method), array('_id', 'parent', 'ip', 'method', 'url', 'time'))->sort(array('time' => -1))->limit($limit);
|
||||
|
||||
$tokens = array();
|
||||
foreach ($cursor as $profile) {
|
||||
@ -93,6 +93,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
|
||||
'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null,
|
||||
'data' => serialize($profile->getCollectors()),
|
||||
'ip' => $profile->getIp(),
|
||||
'method' => $profile->getMethod(),
|
||||
'url' => $profile->getUrl(),
|
||||
'time' => $profile->getTime()
|
||||
);
|
||||
@ -165,9 +166,10 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
|
||||
/**
|
||||
* @param string $ip
|
||||
* @param string $url
|
||||
* @param string $method
|
||||
* @return array
|
||||
*/
|
||||
private function buildQuery($ip, $url)
|
||||
private function buildQuery($ip, $url, $method)
|
||||
{
|
||||
$query = array();
|
||||
|
||||
@ -179,6 +181,10 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
|
||||
$query['url'] = $url;
|
||||
}
|
||||
|
||||
if (!empty($method)) {
|
||||
$query['method'] = $method;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
@ -192,6 +198,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
|
||||
'token' => $data['_id'],
|
||||
'parent' => isset($data['parent']) ? $data['parent'] : null,
|
||||
'ip' => isset($data['ip']) ? $data['ip'] : null,
|
||||
'method' => isset($data['method']) ? $data['method'] : null,
|
||||
'url' => isset($data['url']) ? $data['url'] : null,
|
||||
'time' => isset($data['time']) ? $data['time'] : null,
|
||||
'data' => isset($data['data']) ? $data['data'] : null,
|
||||
@ -206,6 +213,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
|
||||
{
|
||||
$profile = new Profile($data['token']);
|
||||
$profile->setIp($data['ip']);
|
||||
$profile->setMethod($data['method']);
|
||||
$profile->setUrl($data['url']);
|
||||
$profile->setTime($data['time']);
|
||||
$profile->setCollectors(unserialize($data['data']));
|
||||
|
@ -199,8 +199,8 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
|
||||
{
|
||||
$profile = new Profile($token);
|
||||
$profile->setIp($data['ip']);
|
||||
$profile->setUrl($data['url']);
|
||||
$profile->setMethod($data['method']);
|
||||
$profile->setUrl($data['url']);
|
||||
$profile->setTime($data['time']);
|
||||
$profile->setCollectors(unserialize(base64_decode($data['data'])));
|
||||
|
||||
|
@ -42,7 +42,8 @@ class SqliteProfilerStorage extends PdoProfilerStorage
|
||||
|
||||
$db->exec('PRAGMA temp_store=MEMORY; PRAGMA journal_mode=MEMORY;');
|
||||
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token STRING, data STRING, ip STRING, method STRING, url STRING, time INTEGER, parent STRING, created_at INTEGER)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS data_created_at ON sf_profiler_data (created_at)'); $db->exec('CREATE INDEX IF NOT EXISTS data_ip ON sf_profiler_data (ip)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS data_created_at ON sf_profiler_data (created_at)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS data_ip ON sf_profiler_data (ip)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS data_method ON sf_profiler_data (method)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS data_url ON sf_profiler_data (url)');
|
||||
$db->exec('CREATE INDEX IF NOT EXISTS data_parent ON sf_profiler_data (parent)');
|
||||
|
@ -25,8 +25,7 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$iterator = new \RecursiveDirectoryIterator(self::$tmpDir, $flags);
|
||||
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
foreach ($iterator as $file)
|
||||
{
|
||||
foreach ($iterator as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
@ -58,9 +57,10 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$profile = new Profile('token_'.$i);
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
}
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar', 20)), 10, '->write() stores data in the database');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar', 20, 'GET')), 10, '->write() stores data in the database');
|
||||
}
|
||||
|
||||
|
||||
@ -130,12 +130,13 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$profile = new Profile('token');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setMethod('GET');
|
||||
|
||||
self::$storage->write($profile);
|
||||
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', '', 10)), 1, '->find() retrieve a record by IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.%.1', '', 10)), 0, '->find() does not interpret a "%" as a wildcard in the IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0._.1', '', 10)), 0, '->find() does not interpret a "_" as a wildcard in the IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', '', 10, 'GET')), 1, '->find() retrieve a record by IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.%.1', '', 10, 'GET')), 0, '->find() does not interpret a "%" as a wildcard in the IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0._.1', '', 10, 'GET')), 0, '->find() does not interpret a "_" as a wildcard in the IP');
|
||||
}
|
||||
|
||||
public function testRetrieveByUrl()
|
||||
@ -143,38 +144,44 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$profile = new Profile('simple_quote');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/\'');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('double_quote');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/"');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('backslash');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo\\bar/');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('percent');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/%');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('underscore');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/_');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('semicolon');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/;');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10)), 1, '->find() accepts single quotes in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10)), 1, '->find() accepts double quotes in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10)), 1, '->find() accepts backslash in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/;', 10)), 1, '->find() accepts semicolon in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10)), 1, '->find() does not interpret a "%" as a wildcard in the URL');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10)), 1, '->find() does not interpret a "_" as a wildcard in the URL');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10, 'GET')), 1, '->find() accepts single quotes in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10, 'GET')), 1, '->find() accepts double quotes in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10, 'GET')), 1, '->find() accepts backslash in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/;', 10, 'GET')), 1, '->find() accepts semicolon in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10, 'GET')), 1, '->find() does not interpret a "%" as a wildcard in the URL');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10, 'GET')), 1, '->find() does not interpret a "_" as a wildcard in the URL');
|
||||
}
|
||||
}
|
||||
|
@ -47,9 +47,10 @@ class SqliteProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$profile = new Profile('token_'.$i);
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
}
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar', 20)), 10, '->write() stores data in the database');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar', 20, 'GET')), 10, '->write() stores data in the database');
|
||||
}
|
||||
|
||||
public function testStoreSpecialCharsInUrl()
|
||||
@ -89,12 +90,13 @@ class SqliteProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$profile = new Profile('token');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setMethod('GET');
|
||||
|
||||
self::$storage->write($profile);
|
||||
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', '', 10)), 1, '->find() retrieve a record by IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.%.1', '', 10)), 0, '->find() does not interpret a "%" as a wildcard in the IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0._.1', '', 10)), 0, '->find() does not interpret a "_" as a wildcard in the IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', '', 10, 'GET')), 1, '->find() retrieve a record by IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.%.1', '', 10, 'GET')), 0, '->find() does not interpret a "%" as a wildcard in the IP');
|
||||
$this->assertEquals(count(self::$storage->find('127.0._.1', '', 10, 'GET')), 0, '->find() does not interpret a "_" as a wildcard in the IP');
|
||||
}
|
||||
|
||||
public function testRetrieveByUrl()
|
||||
@ -102,32 +104,37 @@ class SqliteProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$profile = new Profile('simple_quote');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/\'');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('double_quote');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/"');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('backslash');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo\\bar/');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('percent');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/%');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$profile = new Profile('underscore');
|
||||
$profile->setIp('127.0.0.1');
|
||||
$profile->setUrl('http://foo.bar/_');
|
||||
$profile->setMethod('GET');
|
||||
self::$storage->write($profile);
|
||||
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10)), 1, '->find() accepts single quotes in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10)), 1, '->find() accepts double quotes in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10)), 1, '->find() accepts backslash in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10)), 1, '->find() does not interpret a "%" as a wildcard in the URL');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10)), 1, '->find() does not interpret a "_" as a wildcard in the URL');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10, 'GET')), 1, '->find() accepts single quotes in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10, 'GET')), 1, '->find() accepts double quotes in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10, 'GET')), 1, '->find() accepts backslash in URLs');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10, 'GET')), 1, '->find() does not interpret a "%" as a wildcard in the URL');
|
||||
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10, 'GET')), 1, '->find() does not interpret a "_" as a wildcard in the URL');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user