diff options
author | mattab <matthieu.aubry@gmail.com> | 2015-09-14 10:04:10 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2015-09-14 10:04:10 +0300 |
commit | 82c9c580076f89767f83309a4f3bdd3e5673760f (patch) | |
tree | cf60be0ee406108869ac5fd4eea8326961f3d881 /plugins/MobileMessaging | |
parent | b1820ed293e70f0738796a862052dbb68d314d8b (diff) |
Display a clear error message when the SMS provider doesn't extend the abstract class
Diffstat (limited to 'plugins/MobileMessaging')
-rw-r--r-- | plugins/MobileMessaging/SMSProvider.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/plugins/MobileMessaging/SMSProvider.php b/plugins/MobileMessaging/SMSProvider.php index 1711bfafed..1c73009197 100644 --- a/plugins/MobileMessaging/SMSProvider.php +++ b/plugins/MobileMessaging/SMSProvider.php @@ -39,6 +39,25 @@ abstract class SMSProvider extends BaseFactory ', ); + /** + * Creates a new instance of a class using a string ID. + * + * @param string $classId The ID of the class. + * @return BaseFactory + * @throws Exception if $classId is invalid. + */ + public static function factory($classId) + { + $className = static::getClassNameFromClassId($classId); + + if(class_exists($className) && + !is_subclass_of($className, __NAMESPACE__ . '\\SMSProvider')) { + throw new Exception("SMS Provider $classId must inherit SMSProvider class."); + } + + return parent::factory($classId); + } + protected static function getClassNameFromClassId($id) { return __NAMESPACE__ . '\\SMSProvider\\' . $id; |