|
|
@@ -88,7 +88,8 @@ class ClassRegistry {
|
|
|
* stored in the registry and returned.
|
|
|
* @param boolean $strict if set to true it will return false if the class was not found instead
|
|
|
* of trying to create an AppModel
|
|
|
- * @return object instance of ClassName
|
|
|
+ * @return object instance of ClassName.
|
|
|
+ * @throws CakeException when you try to construct an interface or abstract class.
|
|
|
*/
|
|
|
public static function init($class, $strict = false) {
|
|
|
$_this = ClassRegistry::getInstance();
|
|
|
@@ -132,8 +133,12 @@ class ClassRegistry {
|
|
|
App::uses($plugin . 'AppModel', $pluginPath . 'Model');
|
|
|
App::uses($class, $pluginPath . 'Model');
|
|
|
|
|
|
- if (class_exists($class)) {
|
|
|
- $instance = new $class($settings);
|
|
|
+ if (class_exists($class) || interface_exists($class)) {
|
|
|
+ $reflection = new ReflectionClass($class);
|
|
|
+ if ($reflection->isAbstract() || $reflection->isInterface()) {
|
|
|
+ throw new CakeException(__d('cake_dev', 'Cannot create instance of %s, as it is abstract or is an interface', $class));
|
|
|
+ }
|
|
|
+ $instance = $reflection->newInstance($settings);
|
|
|
if ($strict) {
|
|
|
$instance = ($instance instanceof Model) ? $instance : null;
|
|
|
}
|