8000 merged branch pulzarraider/memcache_profiler_settings_change (PR #3499) · symfony/symfony@af52362 · GitHub
[go: up one dir, main page]

Skip to content

Commit af52362

Browse files
committed
merged branch pulzarraider/memcache_profiler_settings_change (PR #3499)
Commits ------- 100d59b Modified Memcache(d) dsn to be more intuitive. Chnged Exception texts in other storages. Discussion ---------- [HttpKernel] Modified Memcache(d)ProfilerStorage dsn to be more intuitive Bug fix: no Feature addition: - Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - Todo: - Before: ``` #app/config/config_dev.yml ... framework: ... profiler: ... dsn: memcache://127.0.0.1/11211 ... ``` Now: ``` #app/config/config_dev.yml ... framework: ... profiler: ... dsn: memcache://127.0.0.1:11211 ... ``` If Memcache host is IPv6 address: ``` #app/config/config_dev.yml ... framework: ... profiler: ... dsn: memcache://[::1]:11211 ... ``` I changed texts of some exceptions to be more consistent, too.
2 parents ba02981 + 100d59b commit af52362

9 files changed

+15
-15
lines changed

src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
3434
public function __construct($dsn)
3535
{
3636
if (0 !== strpos($dsn, 'file:')) {
37-
throw new \InvalidArgumentException("FileStorage DSN must start with file:");
37+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use FileStorage with an invalid dsn "%s". The expected format is "file:/path/to/the/storage/folder".', $this->dsn));
3838
}
3939
$this->folder = substr($dsn, 5);
4040

src/Symfony/Component/HttpKernel/Profiler/MemcacheProfilerStorage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class MemcacheProfilerStorage extends BaseMemcacheProfilerStorage
3434
protected function getMemcache()
3535
{
3636
if (null === $this->memcache) {
37-
if (!preg_match('#^memcache://(.*)/(.*)$#', $this->dsn, $matches)) {
38-
throw new \RuntimeException('Please check your configuration. You are trying to use Memcache with an invalid dsn. "' . $this->dsn . '"');
37+
if (!preg_match('#^memcache://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
38+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Memcache with an invalid dsn "%s". The expected format is "memcache://[host]:port".', $this->dsn));
3939
}
4040

41-
$host = $matches[1];
42-
$port = $matches[2];
41+
$host = $matches[1] ?: $matches[2];
42+
$port = $matches[3];
4343

4444
$memcache = new Memcache;
4545
$memcache->addServer($host, $port);

src/Symfony/Component/HttpKernel/Profiler/MemcachedProfilerStorage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class MemcachedProfilerStorage extends BaseMemcacheProfilerStorage
3434
protected function getMemcached()
3535
{
3636
if (null === $this->memcached) {
37-
if (!preg_match('#^memcached://(.*)/(.*)$#', $this->dsn, $matches)) {
38-
throw new \RuntimeException('Please check your configuration. You are trying to use Memcached with an invalid dsn. "' . $this->dsn . '"');
37+
if (!preg_match('#^memcached://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
38+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Memcached with an invalid dsn "%s". The expected format is "memcached://[host]:port".', $this->dsn));
3939
}
4040

41-
$host = $matches[1];
42-
$port = $matches[2];
41+
$host = $matches[1] ?: $matches[2];
42+
$port = $matches[3];
4343

4444
$memcached = new Memcached;
4545

src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected function getMongo()
119119
$collection = $matches[3];
120120
$this->mongo = $mongo->selectCollection($database, $collection);
121121
} else {
122-
throw new \RuntimeException('Please check your configuration. You are trying to use MongoDB with an invalid dsn. "'.$this->dsn.'"');
122+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use MongoDB with an invalid dsn "%s". The expected format is "mongodb://user:pass@location/database/collection"', $this->dsn));
123123
}
124124
}
125125

src/Symfony/Component/HttpKernel/Profiler/MysqlProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function initDb()
2525
{
2626
if (null === $this->db) {
2727
if (0 !== strpos($this->dsn, 'mysql')) {
28-
throw new \RuntimeException('Please check your configuration. You are trying to use Mysql with a wrong dsn. "'.$this->dsn.'"');
28+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Mysql with an invalid dsn "%s". The expected format is "mysql:dbname=database_name;host=host_name".', $this->dsn));
2929
}
3030

3131
if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {

src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected function getRedis()
190190
{
191191
if (null === $this->redis) {
192192
if (!preg_match('#^redis://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
193-
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Redis with an invalid dsn. "%s". The expected format is redis://host:port, redis://127.0.0.1:port, redis://[::1]:port', $this->dsn));
193+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Redis with an invalid dsn "%s". The expected format is "redis://[host]:port".', $this->dsn));
194194
}
195195

196196
$host = $matches[1] ?: $matches[2];

src/Symfony/Component/HttpKernel/Profiler/SqliteProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function initDb()
2626
{
2727
if (null === $this->db || $this->db instanceof \SQLite3) {
2828
if (0 !== strpos($this->dsn, 'sqlite')) {
29-
throw new \RuntimeException('You are trying to use Sqlite with a wrong dsn. "'.$this->dsn.'"');
29+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Sqlite with an invalid dsn "%s". The expected format is "sqlite:/path/to/the/db/file".', $this->dsn));
3030
}
3131
if (class_exists('SQLite3')) {
3232
$db = new \SQLite3(substr($this->dsn, 7, strlen($this->dsn)), \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE);

tests/Symfony/Tests/Component/HttpKernel/Profiler/MemcacheProfilerStorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function setUp()
4242
$this->markTestSkipped('MemcacheProfilerStorageTest requires that the extension memcache is loaded');
4343
}
4444

45-
self::$storage = new DummyMemcacheProfilerStorage('memcache://127.0.0.1/11211', '', '', 86400);
45+
self::$storage = new DummyMemcacheProfilerStorage('memcache://127.0.0.1:11211', '', '', 86400);
4646
try {
4747
self::$storage->getMemcache();
4848
$stats = self::$storage->getMemcache()->getExtendedStats();

tests/Symfony/Tests/Component/HttpKernel/Profiler/MemcachedProfilerStorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function setUp()
4242
$this->markTestSkipped('MemcachedProfilerStorageTest requires that the extension memcached is loaded');
4343
}
4444

45-
self::$storage = new DummyMemcachedProfilerStorage('memcached://127.0.0.1/11211', '', '', 86400);
45+
self::$storage = new DummyMemcachedProfilerStorage('memcached://127.0.0.1:11211', '', '', 86400);
4646
try {
4747
self::$storage->getMemcached();
4848
} catch (\Exception $e) {

0 commit comments

Comments
 (0)
0