diff --git a/libraries/joomla/table/nested.php b/libraries/joomla/table/nested.php index bb3c2901e45e4..7cabda81b56cc 100644 --- a/libraries/joomla/table/nested.php +++ b/libraries/joomla/table/nested.php @@ -61,10 +61,9 @@ class JTableNested extends JTable /** * Object property to hold the location type to use when storing the row. * - * Possible values are: ['before', 'after', 'first-child', 'last-child']. - * * @var string * @since 11.1 + * @see JTableNested::$_validLocations */ protected $_location; @@ -102,6 +101,14 @@ class JTableNested extends JTable */ protected static $root_id = 0; + /** + * Array declaring the valid location values for moving a node + * + * @var array + * @since __DEPLOY_VERSION__ + */ + private $_validLocations = array('before', 'after', 'first-child', 'last-child'); + /** * Sets the debug level on or off * @@ -208,20 +215,23 @@ public function isLeaf($pk = null) * that when the node is stored it will be stored in the new location. * * @param integer $referenceId The primary key of the node to reference new location by. - * @param string $position Location type string. ['before', 'after', 'first-child', 'last-child'] + * @param string $position Location type string. * * @return void * * @note Since 12.1 this method returns void and throws an InvalidArgumentException when an invalid position is passed. + * @see JTableNested::$_validLocations * @since 11.1 * @throws InvalidArgumentException */ public function setLocation($referenceId, $position = 'after') { // Make sure the location is valid. - if (($position != 'before') && ($position != 'after') && ($position != 'first-child') && ($position != 'last-child')) + if (!in_array($position, $this->_validLocations)) { - throw new InvalidArgumentException(sprintf('%s::setLocation(%d, *%s*)', get_class($this), $referenceId, $position)); + throw new InvalidArgumentException( + sprintf('Invalid location "%1$s" given, valid values are %2$s', $position, implode(', ', $this->_validLocations)) + ); } // Set the location properties. @@ -331,10 +341,11 @@ public function moveByReference($referenceId, $position = 'after', $pk = null) // Cannot move the node to be a child of itself. if (in_array($referenceId, $children)) { - $e = new UnexpectedValueException( - sprintf('%s::moveByReference(%d, %s, %d) parenting to child.', get_class($this), $referenceId, $position, $pk) + $this->setError( + new UnexpectedValueException( + sprintf('%1%ss::moveByReference() is trying to make record ID %2$d a child of itself.', get_class($this), $pk) + ) ); - $this->setError($e); return false; } @@ -670,7 +681,7 @@ public function check() // Check that the parent_id field is valid. if ($this->parent_id == 0) { - throw new UnexpectedValueException(sprintf('Invalid `parent_id` [%d] in %s', $this->parent_id, get_class($this))); + throw new UnexpectedValueException(sprintf('Invalid `parent_id` [%1$d] in %2$s::check()', $this->parent_id, get_class($this))); } $query = $this->_db->getQuery(true) @@ -680,7 +691,7 @@ public function check() if (!$this->_db->setQuery($query)->loadResult()) { - throw new UnexpectedValueException(sprintf('Invalid `parent_id` [%d] in %s', $this->parent_id, get_class($this))); + throw new UnexpectedValueException(sprintf('Invalid `parent_id` [%1$d] in %2$s::check()', $this->parent_id, get_class($this))); } } catch (UnexpectedValueException $e) diff --git a/libraries/joomla/table/table.php b/libraries/joomla/table/table.php index 712ec65cadfeb..a5cb8c8d6b985 100644 --- a/libraries/joomla/table/table.php +++ b/libraries/joomla/table/table.php @@ -606,7 +606,13 @@ public function bind($src, $ignore = array()) // Check if the source value is an array or object if (!is_object($src) && !is_array($src)) { - throw new InvalidArgumentException(sprintf('%s::bind(*%s*)', get_class($this), gettype($src))); + throw new InvalidArgumentException( + sprintf( + 'Could not bind the data source in %1$s::bind(), the source must be an array or object but a "%2$s" was given.', + get_class($this), + gettype($src) + ) + ); } // If the source value is an object, get its accessible properties.