From b4b57bba5441cd20a6a5dfb2d5fc7d42562ca760 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 3 Jan 2016 22:56:48 +0100 Subject: [PATCH] EmptyIdException to make sure we get the right in catch --- classes/Managed_DataObject.php | 2 +- lib/emptyidexception.php | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lib/emptyidexception.php diff --git a/classes/Managed_DataObject.php b/classes/Managed_DataObject.php index fb18e594f9..7492d90978 100644 --- a/classes/Managed_DataObject.php +++ b/classes/Managed_DataObject.php @@ -384,7 +384,7 @@ abstract class Managed_DataObject extends Memcached_DataObject static function getByID($id) { if (empty($id)) { - throw new ServerException('Empty ID on lookup'); + throw new EmptyIdException(get_called_class()); } // getByPK throws exception if id is null // or if the class does not have a single 'id' column as primary key diff --git a/lib/emptyidexception.php b/lib/emptyidexception.php new file mode 100644 index 0000000000..ddf781b067 --- /dev/null +++ b/lib/emptyidexception.php @@ -0,0 +1,38 @@ +. + * + * @category Exception + * @package GNUsocial + * @author Mikael Nordfeldth + * @copyright 2013 Free Software Foundation, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://www.gnu.org/software/social/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class EmptyIdException extends ServerException +{ + public function __construct($called_class) + { + parent::__construct(sprintf(_('Empty ID value was given to query for a "%s" object'), $called_class)); + } +}