Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:j4mie/idiorm into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
treffynnon committed Jan 23, 2014
2 parents 3fbafbe + 472123d commit 84e4d5e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ php:
- 5.2
- 5.3
- 5.4
script: "phpunit --colors --coverage-text"
- hhvm
script: "phpunit --colors --coverage-text"
8 changes: 8 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# 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
Expand Down Expand Up @@ -184,7 +184,7 @@
# (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
Expand Down Expand Up @@ -214,7 +214,7 @@
# (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.
Expand All @@ -228,7 +228,7 @@
# 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'),
]

Expand Down
47 changes: 31 additions & 16 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ public static function reset_config() {
* @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);
}

Expand All @@ -259,7 +258,7 @@ protected static function _setup_db($connection_name = self::DEFAULT_CONNECTION)
}

/**
* 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) {
Expand All @@ -279,8 +278,10 @@ protected static function _setup_db_config($connection_name) {
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);
}
}

/**
Expand Down Expand Up @@ -324,7 +325,7 @@ public static function _setup_limit_clause_style($connection_name) {
* @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':
Expand All @@ -347,7 +348,7 @@ protected static function _detect_identifier_quote_character($connection_name) {
* @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':
Expand Down Expand Up @@ -406,7 +407,7 @@ public static function get_last_statement() {
*/
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;

Expand Down Expand Up @@ -438,7 +439,7 @@ protected static function _log_query($query, $parameters, $connection_name) {

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);
Expand Down Expand Up @@ -695,7 +696,10 @@ protected function _call_aggregate_db_function($sql_function, $column) {

$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;
Expand Down Expand Up @@ -1461,7 +1465,7 @@ protected function _build_limit() {
$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';
Expand All @@ -1477,7 +1481,7 @@ protected function _build_limit() {
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;
Expand Down Expand Up @@ -1738,10 +1742,11 @@ public function save() {
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();
}
}
}
Expand Down Expand Up @@ -1784,7 +1789,7 @@ protected function _build_insert() {
$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());
}

Expand Down Expand Up @@ -1881,7 +1886,11 @@ 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);
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));
}
}

/**
Expand Down Expand Up @@ -2131,7 +2140,11 @@ public function unserialize($serialized) {
*/
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;
}
Expand All @@ -2141,3 +2154,5 @@ public function __call($method, $params = array()) {
* A placeholder for exceptions eminating from the IdiormString class
*/
class IdiormStringException extends Exception {}

class IdiormMethodMissingException extends Exception {}
15 changes: 15 additions & 0 deletions test/ORMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,19 @@ public function testGetLastPdoStatement() {
$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();
}
}

0 comments on commit 84e4d5e

Please sign in to comment.