mirror of
https://github.com/dg/dibi.git
synced 2025-08-11 00:24:19 +02:00
Substitution moved from class dibi to DibiConnection
This commit is contained in:
@@ -42,6 +42,9 @@ class DibiConnection extends DibiObject
|
||||
/** @var bool Is connected? */
|
||||
private $connected = FALSE;
|
||||
|
||||
/** @var DibiLazyStorage Substitutes for identifiers */
|
||||
private $substitutes;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -99,7 +102,7 @@ class DibiConnection extends DibiObject
|
||||
$config['name'] = $name;
|
||||
$this->config = $config;
|
||||
$this->driver = new $class;
|
||||
$this->translator = new DibiTranslator($this->driver);
|
||||
$this->translator = new DibiTranslator($this);
|
||||
|
||||
// profiler
|
||||
$profilerCfg = & $config['profiler'];
|
||||
@@ -119,9 +122,10 @@ class DibiConnection extends DibiObject
|
||||
$this->setProfiler(new $class($profilerCfg));
|
||||
}
|
||||
|
||||
$this->substitutes = new DibiLazyStorage(create_function('$expr', 'return ":$expr:";'));
|
||||
if (!empty($config['substitutes'])) {
|
||||
foreach ($config['substitutes'] as $key => $value) {
|
||||
dibi::addSubst($key, $value);
|
||||
$this->substitutes->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,6 +586,42 @@ class DibiConnection extends DibiObject
|
||||
|
||||
|
||||
|
||||
/********************* substitutions ****************d*g**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns substitution hashmap.
|
||||
* @return DibiLazyStorage
|
||||
*/
|
||||
public function getSubstitutes()
|
||||
{
|
||||
return $this->substitutes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides substitution.
|
||||
* @return string
|
||||
*/
|
||||
public function substitute($value)
|
||||
{
|
||||
return strpos($value, ':') === FALSE ? $value : preg_replace_callback('#:([^:\s]*):#', array($this, 'subCb'), $value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Substitution callback.
|
||||
*/
|
||||
private function subCb($m)
|
||||
{
|
||||
return $this->substitutes->{$m[1]};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************* shortcuts ****************d*g**/
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user