From d78996c673643e88dc7a5b420248c1fde6db8c4b Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 9 Jun 2010 21:53:55 +0200 Subject: [PATCH] checks for class existance on dynamic instatiation --- backend/lib/controller/frontcontroller.php | 4 ++-- backend/lib/model/channel.php | 2 +- backend/lib/model/database.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/lib/controller/frontcontroller.php b/backend/lib/controller/frontcontroller.php index 507e08a..b6b8059 100644 --- a/backend/lib/controller/frontcontroller.php +++ b/backend/lib/controller/frontcontroller.php @@ -29,14 +29,14 @@ final class FrontController { // create view instance $view = $request->get['format'] . 'View'; - if (!is_subclass_of($view, 'View')) { + if (!class_exists($view) || !is_subclass_of($view, 'View')) { throw new InvalidArgumentException('\'' . $view . '\' is not a valid View'); } $this->view = new $view($request, $response); // create controller instance $controller = $request->get['controller'] . 'Controller'; - if (!is_subclass_of($controller, 'Controller')) { + if (!class_exists($controller) || !is_subclass_of($controller, 'Controller')) { throw new InvalidArgumentException('\'' . $controller . '\' is not a valid controller'); } $this->controller = new $controller($this->view); diff --git a/backend/lib/model/channel.php b/backend/lib/model/channel.php index 84356e1..b207a09 100644 --- a/backend/lib/model/channel.php +++ b/backend/lib/model/channel.php @@ -157,7 +157,7 @@ abstract class Channel extends DatabaseObject implements ChannelInterface { * create new channel instance by given database query result */ final static protected function factory($object) { - if (!is_subclass_of($object['type'], 'Channel')) { + if (!class_exists($object['type']) || !is_subclass_of($object['type'], 'Channel')) { throw new InvalidArgumentException('\'' . $object['type'] . '\' is not a valid channel type'); } return new $object['type']((array) $object); diff --git a/backend/lib/model/database.php b/backend/lib/model/database.php index 8780d94..bcc0b22 100644 --- a/backend/lib/model/database.php +++ b/backend/lib/model/database.php @@ -194,7 +194,7 @@ abstract class Database implements DatabaseInterface { if (is_null(self::$connection)) { $config = Registry::get('config'); - if (!is_subclass_of($config['db']['backend'], 'Database')) { + if (!class_exists($config['db']['backend']) || !is_subclass_of($config['db']['backend'], 'Database')) { throw new InvalidArgumentException('\'' . $config['db']['backend'] . '\' is not a valid database backend'); } self::$connection = new $config['db']['backend']($config['db']);