Updated config management
Updated install Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
parent
4bb4693d2e
commit
fcd1f5b740
58 changed files with 1579 additions and 1695 deletions
|
|
@ -14,10 +14,14 @@ class Wootook_Core_Block_Messages
|
|||
{
|
||||
$messages = array();
|
||||
|
||||
var_dump($this->_storages);
|
||||
foreach ($this->_storages as $namespace) {
|
||||
$session = Wootook::getSession($namespace);
|
||||
var_dump($session);
|
||||
|
||||
foreach ($session->getMessages() as $messageLevel => $messageList) {
|
||||
var_dump(array($messageLevel => $messageList));
|
||||
|
||||
foreach ($session->getData('messages') as $messageLevel => $messageList) {
|
||||
if (!isset($messages[$messageLevel])) {
|
||||
$messages[$messageLevel] = $messageList;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Collection
|
||||
extends Wootook_Core_Model
|
||||
extends Wootook_Core_Database_Resource
|
||||
implements Iterator, Countable
|
||||
{
|
||||
protected $_tableName = null;
|
||||
|
|
@ -254,7 +254,7 @@ SQL_EOF;
|
|||
{
|
||||
$sql = $this->_prepareSql();
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$database = $this->getReadConnection();
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
$args = func_get_args();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Config_Adapter_Abstract
|
||||
extends Wootook_Core_Config_Node
|
||||
{
|
||||
}
|
||||
33
application/code/core/Wootook/Core/Config/Adapter/Array.php
Normal file
33
application/code/core/Wootook/Core/Config/Adapter/Array.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Config_Adapter_Array
|
||||
extends Wootook_Core_Config_Adapter_Abstract
|
||||
{
|
||||
public function __construct($filename = null)
|
||||
{
|
||||
if ($filename !== null) {
|
||||
$this->load($filename);
|
||||
}
|
||||
}
|
||||
|
||||
public function load($filename)
|
||||
{
|
||||
$data = include $filename;
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new Wootook_Core_Exception_DataAccessException(
|
||||
Wootook::__('Configuration file could not be loaded.'));
|
||||
}
|
||||
|
||||
$this->_init($data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function save($filename)
|
||||
{
|
||||
file_put_contents($filename, '<' . '?p' . 'hp return ' . var_export($this->toArray(), true) . ';');
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
204
application/code/core/Wootook/Core/Config/Node.php
Normal file
204
application/code/core/Wootook/Core/Config/Node.php
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Core_Config_Node
|
||||
implements ArrayAccess
|
||||
{
|
||||
protected $_children = array();
|
||||
|
||||
protected $_parent = null;
|
||||
|
||||
protected static $_attributeNameCache = array();
|
||||
|
||||
public function __construct(Array $data = array(), $parent = null)
|
||||
{
|
||||
$this->_init($data, $parent);
|
||||
}
|
||||
|
||||
public function setData(Array $data = array())
|
||||
{
|
||||
$this->_init($data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _init(Array $data, $parent = null)
|
||||
{
|
||||
if ($parent !== null) {
|
||||
$this->_parent = $parent;
|
||||
}
|
||||
|
||||
$this->_children = array();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$this->offsetSet($key, new self($value, $this));
|
||||
} else {
|
||||
$this->offsetSet($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setConfig($path, $value)
|
||||
{
|
||||
$explodedPath = explode('/', $path);
|
||||
|
||||
$length = count($explodedPath);
|
||||
$currentNode = $this;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (!$currentNode->offsetExists($explodedPath[$i])) {
|
||||
$newNode = new Wootook_Core_Config_Node(array(), $currentNode);
|
||||
$currentNode->offsetSet($explodedPath[$i], $newNode);
|
||||
}
|
||||
|
||||
$currentNode = $currentNode->offsetGet($explodedPath[$i]);
|
||||
|
||||
if ($i >= ($length - 1)) {
|
||||
if (is_array($value)) {
|
||||
$currentNode->offsetSet($explodedPath[$i], new self($value, $this));
|
||||
} else {
|
||||
$currentNode->offsetSet($explodedPath[$i], $value);
|
||||
}
|
||||
break;
|
||||
} else if (!$currentNode instanceof Wootook_Core_Config_Node) {
|
||||
throw new Wootook_Core_Exception_RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getConfig($path)
|
||||
{
|
||||
$explodedPath = explode('/', $path);
|
||||
|
||||
$length = count($explodedPath);
|
||||
$currentNode = $this;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (!$currentNode instanceof Wootook_Core_Config_Node) {
|
||||
throw new Wootook_Core_Exception_RuntimeException();
|
||||
}
|
||||
if (!$currentNode->offsetExists($explodedPath[$i])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$currentNode = $currentNode->offsetGet($explodedPath[$i]);
|
||||
}
|
||||
|
||||
return $currentNode;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$result = array();
|
||||
foreach ($this->_children as $key => $child) {
|
||||
if ($child instanceof self) {
|
||||
$result[$key] = $child->toArray();
|
||||
} else if ($child instanceof Wootook_Core_Config_Leaf) {
|
||||
$result[$key] = $child->getValue();
|
||||
} else {
|
||||
$result[$key] = $child;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->_children = array();
|
||||
$this->_parent = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function merge(self $node)
|
||||
{
|
||||
foreach ($node->_children as $offset => $value) {
|
||||
if ($value instanceof self) {
|
||||
if (!$this->offsetExists($offset)) {
|
||||
$this->offsetSet($offset, new self(array(), $this));
|
||||
}
|
||||
$this->offsetGet($offset)->merge($value);
|
||||
} else {
|
||||
$this->offsetSet($offset, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function _resolveAttributeName($key)
|
||||
{
|
||||
if (!isset(self::$_attributeNameCache[$key])) {
|
||||
self::$_attributeNameCache[$key] = str_replace(' ', '-', strtolower(preg_replace('#[A-Z]#', ' \\1', $key)));
|
||||
}
|
||||
return self::$_attributeNameCache[$key];
|
||||
}
|
||||
|
||||
public function __get($offset)
|
||||
{
|
||||
return $this->offsetGet($this->_resolveAttributeName($offset));
|
||||
}
|
||||
|
||||
public function __set($offset, $value)
|
||||
{
|
||||
return $this->offsetSet($this->_resolveAttributeName($offset), $value);
|
||||
}
|
||||
|
||||
public function __isset($offset)
|
||||
{
|
||||
return $this->offsetExists($this->_resolveAttributeName($offset));
|
||||
}
|
||||
|
||||
public function __unset($offset)
|
||||
{
|
||||
return $this->offsetUnset($this->_resolveAttributeName($offset));
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$clone = new self();
|
||||
|
||||
foreach ($this->_children as $childName => $childNode) {
|
||||
if ($childNode instanceof self) {
|
||||
$childNode = clone $childNode;
|
||||
$childNode->_parent = $clone;
|
||||
}
|
||||
|
||||
$clone->offsetSet($childName, $childNode);
|
||||
}
|
||||
|
||||
return $clone;
|
||||
}
|
||||
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
if ($this->offsetExists($offset)) {
|
||||
return $this->_children[$offset];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->_children[$offset] = $value;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
if (isset($this->_children[$offset])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
if ($this->offsetExists($offset)) {
|
||||
unset($this->_children[$offset]);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
application/code/core/Wootook/Core/Database/Resource.php
Normal file
67
application/code/core/Wootook/Core/Database/Resource.php
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Database_Resource
|
||||
extends Wootook_Core_Model
|
||||
{
|
||||
protected $_readConnection = null;
|
||||
protected $_writeConnection = null;
|
||||
|
||||
protected $_tableName = null;
|
||||
|
||||
public function setTableName($tableName)
|
||||
{
|
||||
$this->_tableName = $tableName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->_tableName;
|
||||
}
|
||||
|
||||
public function getReadConnection()
|
||||
{
|
||||
if ($this->_readConnection === null) {
|
||||
$this->_readConnection = Wootook_Database::getConnection('core_read');
|
||||
}
|
||||
|
||||
return $this->_readConnection;
|
||||
}
|
||||
|
||||
public function setReadConnection($connection)
|
||||
{
|
||||
if ($connection instanceof Wootook_Database) {
|
||||
$this->_readConnection = $connection;
|
||||
} else if (is_string($connection)) {
|
||||
$this->_readConnection = Wootook_Database::getConnection($connection);
|
||||
} else {
|
||||
throw new Wootook_Core_Exception_RuntimeException(
|
||||
'First parameter should be either a database connection object or a string identifier.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWriteConnection()
|
||||
{
|
||||
if ($this->_writeConnection === null) {
|
||||
$this->_writeConnection = Wootook_Database::getConnection('core_write');
|
||||
}
|
||||
return $this->_writeConnection;
|
||||
}
|
||||
|
||||
public function setWriteConnection($connection)
|
||||
{
|
||||
if ($connection instanceof Wootook_Database) {
|
||||
$this->_readConnection = $connection;
|
||||
} else if (is_string($connection)) {
|
||||
$this->_readConnection = Wootook_Database::getConnection($connection);
|
||||
} else {
|
||||
throw new Wootook_Core_Exception_RuntimeException(
|
||||
'First parameter should be either a database connection object or a string identifier.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
|
||||
abstract class Wootook_Core_Entity
|
||||
extends Wootook_Core_Model
|
||||
extends Wootook_Core_Database_Resource
|
||||
implements Wootook_Core_EntityInterface
|
||||
{
|
||||
protected $_idFieldName = null;
|
||||
protected $_tableName = null;
|
||||
|
||||
public function setIdFieldName($fieldName)
|
||||
{
|
||||
|
|
@ -19,18 +18,6 @@ abstract class Wootook_Core_Entity
|
|||
return $this->_idFieldName;
|
||||
}
|
||||
|
||||
public function setTableName($tableName)
|
||||
{
|
||||
$this->_tableName = $tableName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->_tableName;
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->setData($this->getIdFieldName(), $id);
|
||||
|
|
@ -48,10 +35,10 @@ abstract class Wootook_Core_Entity
|
|||
$id = func_get_arg(0);
|
||||
|
||||
$idFieldName = self::getIdFieldName();
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$database = $this->getReadConnection();
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
SELECT * FROM {$database->getTable(self::getTableName())}
|
||||
SELECT * FROM {$database->getTable($this->getTableName())}
|
||||
WHERE {$idFieldName}=:id
|
||||
LIMIT 1
|
||||
SQL_EOF;
|
||||
|
|
@ -89,9 +76,9 @@ SQL_EOF;
|
|||
$idFieldName = self::getIdFieldName();
|
||||
$values[$idFieldName] = $this->getId();
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$database = $this->getWriteConnection();
|
||||
$sql =<<<SQL_EOF
|
||||
UPDATE {$database->getTable(self::getTableName())}
|
||||
UPDATE {$database->getTable($this->getTableName())}
|
||||
SET {$fieldsImploded}
|
||||
WHERE {$idFieldName}=:{$idFieldName}
|
||||
SQL_EOF;
|
||||
|
|
@ -113,9 +100,9 @@ SQL_EOF;
|
|||
}
|
||||
$tokensImploded = implode(', ', $tokens);
|
||||
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$database = $this->getWriteConnection();
|
||||
$sql =<<<SQL_EOF
|
||||
INSERT INTO {$database->getTable(self::getTableName())} ($fieldsImploded)
|
||||
INSERT INTO {$database->getTable($this->getTableName())} ($fieldsImploded)
|
||||
VALUES ({$tokensImploded})
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
|
|
@ -140,9 +127,9 @@ SQL_EOF;
|
|||
|
||||
$fieldsImploded = implod(', ', $fields);
|
||||
$idFieldName = self::getIdFieldName();
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$database = $this->getWriteConnection();
|
||||
$sql =<<<SQL_EOF
|
||||
DELETE {$database->getTable(self::getTableName())}
|
||||
DELETE {$database->getTable($this->getTableName())}
|
||||
WHERE {$idFieldName}=:{$idFieldName}
|
||||
SQL_EOF;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@
|
|||
* @uses Wootook_Empire_Model_User
|
||||
*/
|
||||
abstract class Wootook_Core_Entity_SubTable
|
||||
extends Wootook_Core_Model
|
||||
extends Wootook_Core_Database_Resource
|
||||
{
|
||||
private $_isLoaded = false;
|
||||
protected $_tableName = null;
|
||||
protected $_idFieldNames = array();
|
||||
|
||||
protected $_eventPrefix = 'entity.sub-table';
|
||||
|
|
@ -118,16 +117,4 @@ SQL_EOF;
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTableName($tableName)
|
||||
{
|
||||
$this->_tableName = $tableName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->_tableName;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,10 @@ class Wootook_Core_ErrorProfiler
|
|||
|
||||
private $_mute = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Wootook_Core_ErrorProfiler
|
||||
*/
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
|
|
|
|||
|
|
@ -8,81 +8,56 @@
|
|||
* @uses Legacies_Empire
|
||||
*/
|
||||
class Wootook_Core_Model_Config
|
||||
extends Wootook_Core_Model
|
||||
implements Wootook_Core_Singleton
|
||||
extends Wootook_Core_Entity_SubTable
|
||||
{
|
||||
private static $_singleton = null;
|
||||
|
||||
protected $_eventPrefix = 'core.config';
|
||||
protected $_eventObject = 'config';
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
self::$_singleton = new self();
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->load();
|
||||
$this->_tableName = 'core_config';
|
||||
$this->_idFieldNames = array('config_path', 'website_id', 'game_id');
|
||||
}
|
||||
|
||||
protected function _load()
|
||||
public function setWebsiteId($websiteId)
|
||||
{
|
||||
$database = Wootook_Database::getSingleton();
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
SELECT config_name AS attribute, config_value AS value
|
||||
FROM {$database->getTable('config')} AS config
|
||||
SQL_EOF;
|
||||
|
||||
$attributeName = null;
|
||||
$attributeValue = null;
|
||||
|
||||
$statement = $database->prepare($sql);
|
||||
$statement->execute();
|
||||
|
||||
$statement->bindColumn('attribute', $attributeName, PDO::PARAM_STR);
|
||||
$statement->bindColumn('value', $attributeValue, PDO::PARAM_STR);
|
||||
|
||||
while ($statement->fetch(PDO::FETCH_BOUND)) {
|
||||
$this->setData($attributeName, $attributeValue);
|
||||
}
|
||||
return $this;
|
||||
return $this->setData('website_id', $websiteId);
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
public function getWebsiteId()
|
||||
{
|
||||
$database = Wootook_Database::getSingleton();
|
||||
$fields = array();
|
||||
|
||||
$sql =<<<SQL_EOF
|
||||
UPDATE {{table}}
|
||||
SET config_value=:value
|
||||
WHERE config_name=:name
|
||||
SQL_EOF;
|
||||
$statement = $database->prepare($sql);
|
||||
|
||||
foreach ($this->getAllDatas() as $attributeName => $attributeValue) {
|
||||
$statement->execute(array(
|
||||
'name' => $attributeName,
|
||||
'value' => $attributeValue
|
||||
));
|
||||
}
|
||||
|
||||
return $this;
|
||||
return $this->getData('website_id');
|
||||
}
|
||||
|
||||
protected function _delete()
|
||||
public function setGameId($gameId)
|
||||
{
|
||||
// NOP
|
||||
return $this;
|
||||
return $this->setData('game_id', $gameId);
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
public function getGameId()
|
||||
{
|
||||
return (bool) $this->getData('game_disable');
|
||||
return $this->getData('game_id');
|
||||
}
|
||||
|
||||
public function setPath($path)
|
||||
{
|
||||
return $this->setData('config_path', $path);
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return $this->getData('config_path');
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this->setData('config_value', $value);
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->getData('config_value');
|
||||
}
|
||||
}
|
||||
|
|
@ -58,7 +58,8 @@ class Wootook_Core_Model_Session
|
|||
{
|
||||
$messages = $this->_data['messages'];
|
||||
if ($clear == true) {
|
||||
$this->_data['messages'] = array();
|
||||
var_dump($this->_data['messages']);
|
||||
//$this->_data['messages'] = array();
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue