Created
July 21, 2013 09:45
-
-
Save Meroje/6048090 to your computer and use it in GitHub Desktop.
Get Config from database
http://forums.laravel.io/viewtopic.php?pid=45540#p45540
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello , is possible this script to work like dot style Config?
For example
Config::get(settings.google.driver)