From 823d71ced9b4947b1a5a5ade7245d521ed490061 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 7 Jun 2016 15:17:49 +0200 Subject: * renaming php directory --- app/frontend/db/ActiveRecord.php | 69 +++++++++++++++++++++++++++++++++++++++ app/frontend/db/DBConnection.php | 28 ++++++++++++++++ app/frontend/db/DBModule.php | 40 +++++++++++++++++++++++ app/frontend/db/DBTransaction.php | 53 ++++++++++++++++++++++++++++++ app/frontend/db/config.json | 1 + app/frontend/db/config.xml | 10 ++++++ 6 files changed, 201 insertions(+) create mode 100644 app/frontend/db/ActiveRecord.php create mode 100644 app/frontend/db/DBConnection.php create mode 100644 app/frontend/db/DBModule.php create mode 100644 app/frontend/db/DBTransaction.php create mode 120000 app/frontend/db/config.json create mode 100644 app/frontend/db/config.xml (limited to 'app/frontend/db') diff --git a/app/frontend/db/ActiveRecord.php b/app/frontend/db/ActiveRecord.php new file mode 100644 index 0000000..1176767 --- /dev/null +++ b/app/frontend/db/ActiveRecord.php @@ -0,0 +1,69 @@ + 2) { + $method .= $parameter[2]; + } + } + } + } + } + return $method; + } + + public function __get($name) { + $name = $this->_getMappedPropertyName($name); + if (property_exists($this, $name)) { + return $this->$name; + } + return parent::__get($name); + } + + public function __set($name, $value) { + $name = $this->_getMappedPropertyName($name); + if (property_exists($this, $name)) { + return $this->$name = $value; + } + return parent::__set($name, $value); + } + + public function __call($method, $args) { + return parent::__call($this->_getMappedMethodName($method), $args); + } + +} + +?> diff --git a/app/frontend/db/DBConnection.php b/app/frontend/db/DBConnection.php new file mode 100644 index 0000000..92ab0fb --- /dev/null +++ b/app/frontend/db/DBConnection.php @@ -0,0 +1,28 @@ +_transaction->getActive()) { + $this->_transaction = NULL; + } + return $this->_transaction; + } + + public function beginTransaction() { + if ($this->_transaction && $this->_transaction->getActive()) { + $this->_transaction->beginNestedTransaction(); + } + else { + $this->_transaction = parent::beginTransaction(); + } + return $this->_transaction; + } + +} + +?> diff --git a/app/frontend/db/DBModule.php b/app/frontend/db/DBModule.php new file mode 100644 index 0000000..462b6f6 --- /dev/null +++ b/app/frontend/db/DBModule.php @@ -0,0 +1,40 @@ +getAttributes() as $attr => $val) { + $newXML->setAttribute($attr, $val); + } + $dbXML = new TXmlElement('database'); + $config = json_decode(file_get_contents( + Prado::getPathOfNamespace($this->_config, '.json') + )); + if (isset($config->cset)) { + $dbXML->setAttribute('Charset', $config->cset); + } + $dbXML->setAttribute('Username', $config->user); + $dbXML->setAttribute('Password', $config->pass); + $dbXML->setAttribute( + 'ConnectionString', + sprintf( + '%s:host=%s;dbname=%s', + $config->type, $config->host, $config->name + ) + ); + $newXML->Elements[] = $dbXML; + parent::init($newXML); + } + + public function setConfig($config) { + $this->_config = TPropertyValue::ensureString($config); + } + +} + +?> diff --git a/app/frontend/db/DBTransaction.php b/app/frontend/db/DBTransaction.php new file mode 100644 index 0000000..b176453 --- /dev/null +++ b/app/frontend/db/DBTransaction.php @@ -0,0 +1,53 @@ +getActive()) { + $this->_nestedCount++; + } + } + + public function commit() { + if ($this->_rolledBack) { + $childTransaction = (bool)($this->_nestedCount); + $this->rollback(); + if (!$childTransaction) { + throw new TDbException('Nested transaction was rolled back, unable to commit.'); + } + } + else { + if ($this->_nestedCount) { + $this->_nestedCount--; + } + else { + parent::commit(); + } + } + } + + public function rollback() { + if (!$this->getActive()) { + $this->_nestedCount = 0; + return; + } + if ($this->_nestedCount) { + $this->_rolledBack = TRUE; + $this->_nestedCount--; + } + else { + parent::rollback(); + $this->_nestedCount = 0; + $this->_rolledBack = FALSE; + } + } + +} + +?> diff --git a/app/frontend/db/config.json b/app/frontend/db/config.json new file mode 120000 index 0000000..89a492f --- /dev/null +++ b/app/frontend/db/config.json @@ -0,0 +1 @@ +../../../config/db.json \ No newline at end of file diff --git a/app/frontend/db/config.xml b/app/frontend/db/config.xml new file mode 100644 index 0000000..3210593 --- /dev/null +++ b/app/frontend/db/config.xml @@ -0,0 +1,10 @@ + + + + + + -- cgit v1.2.3