From 9b3f13cc585622ce82522d85c712022339cfc571 Mon Sep 17 00:00:00 2001 From: m4 Date: Thu, 12 Sep 2013 17:38:25 +0400 Subject: improved typecasting for aggregate db functions --- idiorm.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/idiorm.php b/idiorm.php index dd5cea2..7575f3e 100644 --- a/idiorm.php +++ b/idiorm.php @@ -711,7 +711,10 @@ $return_value = 0; if($result !== false && isset($result->$alias)) { - if((int) $result->$alias == (float) $result->$alias) { + if (!is_numeric($result->$alias)) { + $return_value = $result->$alias; + } + elseif((int) $result->$alias == (float) $result->$alias) { $return_value = (int) $result->$alias; } else { $return_value = (float) $result->$alias; -- cgit v1.2.3 From 1e81b41c1eba7ec17887826a3504afa0b15947bd Mon Sep 17 00:00:00 2001 From: falmp Date: Wed, 2 Oct 2013 15:05:59 +0100 Subject: Changed $_db access to ensure it's always properly setup Changed configure() to directly set $_config Fixed typo on comment ('mulitple' -> 'multiple') --- idiorm.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/idiorm.php b/idiorm.php index dd5cea2..92d7cad 100644 --- a/idiorm.php +++ b/idiorm.php @@ -189,7 +189,7 @@ // Shortcut: If only one array argument is passed, // assume it's an array of configuration settings foreach ($key as $conf_key => $conf_value) { - self::configure($conf_key, $conf_value, $connection_name); + self::$_config[$connection_name][$conf_key] = $conf_value; } } else { if (is_null($value)) { @@ -233,7 +233,6 @@ * @return ORM */ public static function for_table($table_name, $connection_name = self::DEFAULT_CONNECTION) { - self::_setup_db($connection_name); return new self($table_name, array(), $connection_name); } @@ -259,7 +258,7 @@ } /** - * Ensures configuration (mulitple connections) is at least set to default. + * Ensures configuration (multiple connections) is at least set to default. * @param string $connection_name Which connection to use */ protected static function _setup_db_config($connection_name) { @@ -324,7 +323,7 @@ * @return string */ protected static function _detect_identifier_quote_character($connection_name) { - switch(self::$_db[$connection_name]->getAttribute(PDO::ATTR_DRIVER_NAME)) { + switch(self::get_db($connection_name)->getAttribute(PDO::ATTR_DRIVER_NAME)) { case 'pgsql': case 'sqlsrv': case 'dblib': @@ -347,7 +346,7 @@ * @return string Limit clause style keyword/constant */ protected static function _detect_limit_clause_style($connection_name) { - switch(self::$_db[$connection_name]->getAttribute(PDO::ATTR_DRIVER_NAME)) { + switch(self::get_db($connection_name)->getAttribute(PDO::ATTR_DRIVER_NAME)) { case 'sqlsrv': case 'dblib': case 'mssql': @@ -406,7 +405,7 @@ */ protected static function _execute($query, $parameters = array(), $connection_name = self::DEFAULT_CONNECTION) { self::_log_query($query, $parameters, $connection_name); - $statement = self::$_db[$connection_name]->prepare($query); + $statement = self::get_db($connection_name)->prepare($query); self::$_last_statement = $statement; @@ -438,7 +437,7 @@ if (count($parameters) > 0) { // Escape the parameters - $parameters = array_map(array(self::$_db[$connection_name], 'quote'), $parameters); + $parameters = array_map(array(self::get_db($connection_name), 'quote'), $parameters); // Avoid %format collision for vsprintf $query = str_replace("%", "%%", $query); @@ -1477,7 +1476,7 @@ $fragment = ''; if (!is_null($this->_limit) && self::$_config[$this->_connection_name]['limit_clause_style'] == ORM::LIMIT_STYLE_LIMIT) { - if (self::$_db[$this->_connection_name]->getAttribute(PDO::ATTR_DRIVER_NAME) == 'firebird') { + if (self::get_db($this->_connection_name)->getAttribute(PDO::ATTR_DRIVER_NAME) == 'firebird') { $fragment = 'ROWS'; } else { $fragment = 'LIMIT'; @@ -1493,7 +1492,7 @@ protected function _build_offset() { if (!is_null($this->_offset)) { $clause = 'OFFSET'; - if (self::$_db[$this->_connection_name]->getAttribute(PDO::ATTR_DRIVER_NAME) == 'firebird') { + if (self::get_db($this->_connection_name)->getAttribute(PDO::ATTR_DRIVER_NAME) == 'firebird') { $clause = 'TO'; } return "$clause " . $this->_offset; @@ -1754,10 +1753,11 @@ if ($this->_is_new) { $this->_is_new = false; if (is_null($this->id())) { - if(self::$_db[$this->_connection_name]->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { + $db = self::get_db($this->_connection_name); + if($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { $this->_data[$this->_get_id_column_name()] = self::get_last_statement()->fetchColumn(); } else { - $this->_data[$this->_get_id_column_name()] = self::$_db[$this->_connection_name]->lastInsertId(); + $this->_data[$this->_get_id_column_name()] = $db->lastInsertId(); } } } @@ -1800,7 +1800,7 @@ $placeholders = $this->_create_placeholders($this->_dirty_fields); $query[] = "({$placeholders})"; - if (self::$_db[$this->_connection_name]->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { + if (self::get_db($this->_connection_name)->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { $query[] = 'RETURNING ' . $this->_quote_identifier($this->_get_id_column_name()); } -- cgit v1.2.3 From 7ed8aacc50ce09c78701a06699ae6c58269b3315 Mon Sep 17 00:00:00 2001 From: falmp Date: Wed, 20 Nov 2013 10:46:08 +0000 Subject: Removed premature optimization as requested --- idiorm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idiorm.php b/idiorm.php index 92d7cad..f628004 100644 --- a/idiorm.php +++ b/idiorm.php @@ -189,7 +189,7 @@ // Shortcut: If only one array argument is passed, // assume it's an array of configuration settings foreach ($key as $conf_key => $conf_value) { - self::$_config[$connection_name][$conf_key] = $conf_value; + self::configure($conf_key, $conf_value, $connection_name); } } else { if (is_null($value)) { -- cgit v1.2.3 From 0140d2753a7973d880b6684eaa6cf4922d74b300 Mon Sep 17 00:00:00 2001 From: Paul Tarjan Date: Fri, 13 Dec 2013 11:29:10 -0800 Subject: Add HHVM to build matrix Edit Now that HHVM can run your projects, lets keep it that way --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5e5da38..48e2254 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,5 @@ php: - 5.2 - 5.3 - 5.4 -script: "phpunit --colors --coverage-text" \ No newline at end of file + - hhvm +script: "phpunit --colors --coverage-text" -- cgit v1.2.3 From 7346022dcfadf628e8e3e89e31739ddcc02ead05 Mon Sep 17 00:00:00 2001 From: Michel Kollenhoven Date: Thu, 26 Dec 2013 16:14:24 +0000 Subject: Allow unsetting the db (ORM::set_db(null)) to make the test work again --- idiorm.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/idiorm.php b/idiorm.php index 7ac1652..143ecb7 100644 --- a/idiorm.php +++ b/idiorm.php @@ -279,8 +279,10 @@ public static function set_db($db, $connection_name = self::DEFAULT_CONNECTION) { self::_setup_db_config($connection_name); self::$_db[$connection_name] = $db; - self::_setup_identifier_quote_character($connection_name); - self::_setup_limit_clause_style($connection_name); + if(!is_null(self::$_db[$connection_name])) { + self::_setup_identifier_quote_character($connection_name); + self::_setup_limit_clause_style($connection_name); + } } /** -- cgit v1.2.3 From 3530b21fec1ee958a2c0d9c31ed83d53ac66ceee Mon Sep 17 00:00:00 2001 From: michaelward82 Date: Sat, 14 Sep 2013 14:35:54 +0100 Subject: Adds new IdiormMethodMissingException class for missing magic method calls to ORM and IdiormResultSet --- idiorm.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/idiorm.php b/idiorm.php index 32dddee..f1ce00c 100644 --- a/idiorm.php +++ b/idiorm.php @@ -1886,7 +1886,11 @@ { $method = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name)); - return call_user_func_array(array($this, $method), $arguments); + if (method_exists($this, $method)) { + return call_user_func_array(array($this, $method), $arguments); + } else { + throw new IdiormMethodMissingException("Method $name() does not exist in class " . get_class($this)); + } } /** @@ -2136,7 +2140,11 @@ */ public function __call($method, $params = array()) { foreach($this->_results as $model) { - call_user_func_array(array($model, $method), $params); + if (method_exists($model, $method)) { + call_user_func_array(array($model, $method), $params); + } else { + throw new IdiormMethodMissingException("Method $method() does not exist in class " . get_class($this)); + } } return $this; } @@ -2146,3 +2154,5 @@ * A placeholder for exceptions eminating from the IdiormString class */ class IdiormStringException extends Exception {} + + class IdiormMethodMissingException extends Exception {} \ No newline at end of file -- cgit v1.2.3 From 9363ae11bac70a6e5bb2c02410d05690e75cf95f Mon Sep 17 00:00:00 2001 From: michaelward82 Date: Sat, 14 Sep 2013 14:38:28 +0100 Subject: Adds regression tests for missing magic method calls to ORM and IdiormResultSet --- test/ORMTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/ORMTest.php b/test/ORMTest.php index ebd3d17..e0e4900 100644 --- a/test/ORMTest.php +++ b/test/ORMTest.php @@ -84,4 +84,19 @@ class ORMTest extends PHPUnit_Framework_TestCase { $this->assertInstanceOf('MockPDOStatement', $statement); } + /** + * @expectedException IdiormMethodMissingException + */ + public function testInvalidORMFunctionCallShouldCreateException() { + $orm = ORM::for_table('test'); + $orm->invalidFunctionCall(); + } + + /** + * @expectedException IdiormMethodMissingException + */ + public function testInvalidResultsSetFunctionCallShouldCreateException() { + $resultSet = ORM::for_table('test')->find_result_set(); + $resultSet->invalidFunctionCall(); + } } \ No newline at end of file -- cgit v1.2.3 From 0545618c84c2eec2ee49db92cfd9864933cb6711 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Thu, 26 Dec 2013 17:04:17 +0000 Subject: Add change log details --- README.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.markdown b/README.markdown index e187d0a..820c56a 100644 --- a/README.markdown +++ b/README.markdown @@ -74,6 +74,14 @@ foreach ($tweets as $tweet) { Changelog --------- +#### 1.5.0 - release 2014-01-XX + +* Reduce the type casting on aggregate functions to allow characters [[herroffizier](https://github.com/herroffizier)] - [issue #150](https://github.com/j4mie/idiorm/issues/150) +* Prevent invalid method calls from triggering infinite recursion [[michaelward82](https://github.com/michaelward82)] - [issue #152](https://github.com/j4mie/idiorm/issues/152) +* Changed database array access to ensure it's always properly setup [[falmp](https://github.com/falmp)] - [issue #159](https://github.com/j4mie/idiorm/issues/159) +* Allow unsetting the db (ORM::set_db(null)) to make the test work again [[borrel](https://github.com/borrel)] - [issue #160](https://github.com/j4mie/idiorm/issues/160) +* Add HHVM to travis-ci build matrix [[ptarjan](https://github.com/ptarjan)] - [issue #168](https://github.com/j4mie/idiorm/issues/168) + #### 1.4.1 - release 2013-12-12 **Patch update to remove a broken pull request** - may have consequences for users of 1.4.0 that exploited the "`find_many()` now returns an associative array with the databases primary ID as the array keys" change that was merged in 1.4.0. -- cgit v1.2.3 From 472123d14eb8785bc54240a8d7a88addb1424d55 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Tue, 21 Jan 2014 11:20:16 +0000 Subject: Remove Durham and increment copyright year --- docs/conf.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 1d407d0..87e1792 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -41,7 +41,7 @@ master_doc = 'index' # General information about the project. project = u'Idiorm' -copyright = u'2013, Jamie Matthews, Simon Holywell, Durham Hale' +copyright = u'2014, Jamie Matthews and Simon Holywell' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -184,7 +184,7 @@ latex_elements = { # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'Idiorm.tex', u'Idiorm Documentation', - u'Jamie Matthews, Simon Holywell, Durham Hale', 'manual'), + u'Jamie Matthews and Simon Holywell', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -214,7 +214,7 @@ latex_documents = [ # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'idiorm', u'Idiorm Documentation', - [u'Jamie Matthews, Simon Holywell, Durham Hale'], 1) + [u'Jamie Matthews and Simon Holywell'], 1) ] # If true, show URL addresses after external links. @@ -228,7 +228,7 @@ man_pages = [ # dir menu entry, description, category) texinfo_documents = [ ('index', 'Idiorm', u'Idiorm Documentation', - u'Jamie Matthews, Simon Holywell, Durham Hale', 'Idiorm', 'One line description of project.', + u'Jamie Matthews and Simon Holywell', 'Idiorm', 'One line description of project.', 'Miscellaneous'), ] -- cgit v1.2.3