Skip to content
Permalink
Browse files

SQLiteJournal: checking for extension pdo_sqlite is lazy, service cac…

…he.journal is created always
  • Loading branch information
dg committed Jul 18, 2016
1 parent 9a41df4 commit 7212326d59d0d40dc81e3ce8a5bd146bc1cf6be4
Showing with 11 additions and 11 deletions.
  1. +3 −0 composer.json
  2. +4 −8 src/Bridges/CacheDI/CacheExtension.php
  3. +4 −3 src/Caching/Storages/SQLiteJournal.php
@@ -24,6 +24,9 @@
"latte/latte": "~2.4",
"tracy/tracy": "^2.4"
},
"suggest": {
"ext-pdo_sqlite": "to use SQLiteStorage or SQLiteJournal"
},
"conflict": {
"nette/nette": "<2.2"
},
@@ -29,20 +29,16 @@ public function loadConfiguration()
{
$builder = $this->getContainerBuilder();

if (extension_loaded('pdo_sqlite')) {
$builder->addDefinition($this->prefix('journal'))
->setClass(Nette\Caching\Storages\IJournal::class)
->setFactory(Nette\Caching\Storages\SQLiteJournal::class, [$this->tempDir . '/cache/journal.s3db']);
}
$builder->addDefinition($this->prefix('journal'))
->setClass(Nette\Caching\Storages\IJournal::class)
->setFactory(Nette\Caching\Storages\SQLiteJournal::class, [$this->tempDir . '/cache/journal.s3db']);

$builder->addDefinition($this->prefix('storage'))
->setClass(Nette\Caching\IStorage::class)
->setFactory(Nette\Caching\Storages\FileStorage::class, [$this->tempDir . '/cache']);

if ($this->name === 'cache') {
if (extension_loaded('pdo_sqlite')) {
$builder->addAlias('nette.cacheJournal', $this->prefix('journal'));
}
$builder->addAlias('nette.cacheJournal', $this->prefix('journal'));
$builder->addAlias('cacheStorage', $this->prefix('storage'));
}
}
@@ -30,15 +30,16 @@ class SQLiteJournal implements IJournal
*/
public function __construct($path)
{
if (!extension_loaded('pdo_sqlite')) {
throw new Nette\NotSupportedException('SQLiteJournal requires PHP extension pdo_sqlite which is not loaded.');
}
$this->path = $path;
}


private function open()
{
if (!extension_loaded('pdo_sqlite')) {
throw new Nette\NotSupportedException('SQLiteJournal requires PHP extension pdo_sqlite which is not loaded.');
}

if ($this->path !== ':memory:' && !is_file($this->path)) {
touch($this->path); // ensures ordinary file permissions
}

0 comments on commit 7212326

Please sign in to comment.
You can’t perform that action at this time.