checks for class existance on dynamic instatiation

This commit is contained in:
Steffen Vogel 2010-06-09 21:53:55 +02:00
parent 673499f4f8
commit d78996c673
3 changed files with 4 additions and 4 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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']);