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.
This commit is contained in:
Fabien Potencier 2012-03-05 15:47:23 +01:00
commit af52362841
9 changed files with 15 additions and 15 deletions

View File

@ -34,7 +34,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
public function __construct($dsn)
{
if (0 !== strpos($dsn, 'file:')) {
throw new \InvalidArgumentException("FileStorage DSN must start with file:");
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));
}
$this->folder = substr($dsn, 5);

View File

@ -34,12 +34,12 @@ class MemcacheProfilerStorage extends BaseMemcacheProfilerStorage
protected function getMemcache()
{
if (null === $this->memcache) {
if (!preg_match('#^memcache://(.*)/(.*)$#', $this->dsn, $matches)) {
throw new \RuntimeException('Please check your configuration. You are trying to use Memcache with an invalid dsn. "' . $this->dsn . '"');
if (!preg_match('#^memcache://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
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));
}
$host = $matches[1];
$port = $matches[2];
$host = $matches[1] ?: $matches[2];
$port = $matches[3];
$memcache = new Memcache;
$memcache->addServer($host, $port);

View File

@ -34,12 +34,12 @@ class MemcachedProfilerStorage extends BaseMemcacheProfilerStorage
protected function getMemcached()
{
if (null === $this->memcached) {
if (!preg_match('#^memcached://(.*)/(.*)$#', $this->dsn, $matches)) {
throw new \RuntimeException('Please check your configuration. You are trying to use Memcached with an invalid dsn. "' . $this->dsn . '"');
if (!preg_match('#^memcached://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
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));
}
$host = $matches[1];
$port = $matches[2];
$host = $matches[1] ?: $matches[2];
$port = $matches[3];
$memcached = new Memcached;

View File

@ -119,7 +119,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
$collection = $matches[3];
$this->mongo = $mongo->selectCollection($database, $collection);
} else {
throw new \RuntimeException('Please check your configuration. You are trying to use MongoDB with an invalid dsn. "'.$this->dsn.'"');
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));
}
}

View File

@ -25,7 +25,7 @@ class MysqlProfilerStorage extends PdoProfilerStorage
{
if (null === $this->db) {
if (0 !== strpos($this->dsn, 'mysql')) {
throw new \RuntimeException('Please check your configuration. You are trying to use Mysql with a wrong dsn. "'.$this->dsn.'"');
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));
}
if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {

View File

@ -190,7 +190,7 @@ class RedisProfilerStorage implements ProfilerStorageInterface
{
if (null === $this->redis) {
if (!preg_match('#^redis://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
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));
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));
}
$host = $matches[1] ?: $matches[2];

View File

@ -26,7 +26,7 @@ class SqliteProfilerStorage extends PdoProfilerStorage
{
if (null === $this->db || $this->db instanceof \SQLite3) {
if (0 !== strpos($this->dsn, 'sqlite')) {
throw new \RuntimeException('You are trying to use Sqlite with a wrong dsn. "'.$this->dsn.'"');
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));
}
if (class_exists('SQLite3')) {
$db = new \SQLite3(substr($this->dsn, 7, strlen($this->dsn)), \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE);

View File

@ -42,7 +42,7 @@ class MemcacheProfilerStorageTest extends AbstractProfilerStorageTest
$this->markTestSkipped('MemcacheProfilerStorageTest requires that the extension memcache is loaded');
}
self::$storage = new DummyMemcacheProfilerStorage('memcache://127.0.0.1/11211', '', '', 86400);
self::$storage = new DummyMemcacheProfilerStorage('memcache://127.0.0.1:11211', '', '', 86400);
try {
self::$storage->getMemcache();
$stats = self::$storage->getMemcache()->getExtendedStats();

View File

@ -42,7 +42,7 @@ class MemcachedProfilerStorageTest extends AbstractProfilerStorageTest
$this->markTestSkipped('MemcachedProfilerStorageTest requires that the extension memcached is loaded');
}
self::$storage = new DummyMemcachedProfilerStorage('memcached://127.0.0.1/11211', '', '', 86400);
self::$storage = new DummyMemcachedProfilerStorage('memcached://127.0.0.1:11211', '', '', 86400);
try {
self::$storage->getMemcached();
} catch (\Exception $e) {