summaryrefslogtreecommitdiff
path: root/idiorm.php
diff options
context:
space:
mode:
Diffstat (limited to 'idiorm.php')
-rw-r--r--idiorm.php71
1 files changed, 69 insertions, 2 deletions
diff --git a/idiorm.php b/idiorm.php
index 5b327a6..2f4bb2f 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -65,6 +65,7 @@
'driver_options' => null,
'identifier_quote_character' => null, // if this is null, will be autodetected
'logging' => false,
+ 'logger' => null,
'caching' => false,
'return_result_sets' => false,
);
@@ -197,6 +198,19 @@
}
/**
+ * Retrieve configuration options by key, or as whole array.
+ * @param string $key
+ * @param string $connection_name Which connection to use
+ */
+ public static function get_config($key = null, $connection_name = self::DEFAULT_CONNECTION) {
+ if ($key) {
+ return self::$_config[$connection_name][$key];
+ } else {
+ return self::$_config[$connection_name];
+ }
+ }
+
+ /**
* Despite its slightly odd name, this is actually the factory
* method used to acquire instances of the class. It is named
* this way for the sake of a readable interface, ie
@@ -394,6 +408,13 @@
self::$_last_query = $bound_query;
self::$_query_log[$connection_name][] = $bound_query;
+
+
+ if(is_callable(self::$_config[$connection_name]['logger'])){
+ $logger = self::$_config[$connection_name]['logger'];
+ $logger($bound_query);
+ }
+
return true;
}
@@ -616,8 +637,11 @@
if('*' != $column) {
$column = $this->_quote_identifier($column);
}
+ $result_columns = $this->_result_columns;
+ $this->_result_columns = array();
$this->select_expr("$sql_function($column)", $alias);
$result = $this->find_one();
+ $this->_result_columns = $result_columns;
$return_value = 0;
if($result !== false && isset($result->$alias)) {
@@ -936,7 +960,12 @@
protected function _add_simple_condition($type, $column_name, $separator, $value) {
// Add the table name in case of ambiguous columns
if (count($this->_join_sources) > 0 && strpos($column_name, '.') === false) {
- $column_name = "{$this->_table_name}.{$column_name}";
+ $table = $this->_table_name;
+ if (!is_null($this->_table_alias)) {
+ $table = $this->_table_alias;
+ }
+
+ $column_name = "{$table}.{$column_name}";
}
$column_name = $this->_quote_identifier($column_name);
return $this->_add_condition($type, "{$column_name} {$separator} ?", $value);
@@ -1657,7 +1686,7 @@
}
}
- $this->_dirty_fields = array();
+ $this->_dirty_fields = $this->_expr_fields = array();
return $success;
}
@@ -1775,6 +1804,44 @@
public function __isset($key) {
return $this->offsetExists($key);
}
+
+ /**
+ * Magic method to capture calls to undefined class methods.
+ * In this case we are attempting to convert camel case formatted
+ * methods into underscore formatted methods.
+ *
+ * This allows us to call ORM methods using camel case and remain
+ * backwards compatible.
+ *
+ * @param string $name
+ * @param array $arguments
+ * @return ORM
+ */
+ public function __call($name, $arguments)
+ {
+ $method = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name));
+
+ return call_user_func_array(array($this, $method), $arguments);
+ }
+
+ /**
+ * Magic method to capture calls to undefined static class methods.
+ * In this case we are attempting to convert camel case formatted
+ * methods into underscore formatted methods.
+ *
+ * This allows us to call ORM methods using camel case and remain
+ * backwards compatible.
+ *
+ * @param string $name
+ * @param array $arguments
+ * @return ORM
+ */
+ public static function __callStatic($name, $arguments)
+ {
+ $method = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name));
+
+ return call_user_func_array(array('ORM', $method), $arguments);
+ }
}
/**