summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Holywell <[email protected]>2014-01-23 13:08:36 +0000
committerSimon Holywell <[email protected]>2014-01-23 13:08:36 +0000
commit84e4d5e0d707c06cbce50a9f0947fdc20054aa0f (patch)
treed546f0526108168fb710efbf173bf4a672cb36b6
parent3fbafbeb80039facd6c3eea33d5060cf82270463 (diff)
parent472123d14eb8785bc54240a8d7a88addb1424d55 (diff)
Merge branch 'develop' of github.com:j4mie/idiorm into develop
-rw-r--r--.travis.yml3
-rw-r--r--README.markdown8
-rw-r--r--docs/conf.py8
-rw-r--r--idiorm.php47
-rw-r--r--test/ORMTest.php15
5 files changed, 60 insertions, 21 deletions
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"
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.
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'),
]
diff --git a/idiorm.php b/idiorm.php
index 7ac1652..f1ce00c 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -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) {
@@ -279,8 +278,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);
+ }
}
/**
@@ -324,7 +325,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 +348,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 +407,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 +439,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);
@@ -695,7 +696,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;
@@ -1461,7 +1465,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';
@@ -1477,7 +1481,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;
@@ -1738,10 +1742,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();
}
}
}
@@ -1784,7 +1789,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());
}
@@ -1881,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));
+ }
}
/**
@@ -2131,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;
}
@@ -2141,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
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