Skip to content

Instantly share code, notes, and snippets.

@Meroje
Created July 21, 2013 09:45
Show Gist options
  • Save Meroje/6048090 to your computer and use it in GitHub Desktop.
Save Meroje/6048090 to your computer and use it in GitHub Desktop.
<?php
class DBconfiguratorObject implements ArrayAccess, Serializable {
protected $config = array();
protected $table = null;
private static $_instance = null;
public static function instance($tableName = 'config'){
if(self::$_instance === null){
self::$_instance = new self($tableName);
}
return self::$_instance;
}
private function __construct($tableName = 'config'){
$this->table = DB::table($tableName);
$this->config = $this->table->lists('value', 'key');
}
public function offsetGet($key){
return $this->config[$key];
}
public function offsetSet($key, $value){
if($this->offsetExists($key)){
$this->table->where('key', $key)->update(array(
'value' => $value
));
} else {
$this->table->insert(array(
'key' => $key,
'value' => $value
));
}
$this->config[$key] = $value;
}
public function offsetExists($key){
return isset($this->config[$key]);
}
public function offsetUnset($key){
unset($this->config[$key]);
$this->table->where('key', $key)->delete();
}
public function serialize(){
return serialize($this->config);
}
public function unserialize($serialized){
$config = unserialize($serialized);
foreach($config as $key => $value){
$this[$key] = $value;
}
}
public function toJson(){
return json_encode($this->config);
}
}
return DBconfiguratorObject::instance();
@esifis
Copy link

esifis commented Jun 22, 2016

Hello , is possible this script to work like dot style Config?
For example

Config::get(settings.google.driver)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment