From b22e74c0e9684f9a532d1e60c42270cd240d5dce Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 5 Feb 2014 08:32:19 +0100 Subject: [PATCH] Closed #72 --- src/Bootstrap.php | 3 +++ src/Controllers/LogController.php | 2 +- src/Controllers/PostController.php | 2 +- src/Models/AbstractCrudModel.php | 2 +- src/Models/PostModel.php | 4 ++-- src/Models/TagModel.php | 2 +- src/Models/TokenModel.php | 4 ++-- src/Models/UserModel.php | 4 ++-- src/SimpleNotFoundException.php | 4 ++++ 9 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 src/SimpleNotFoundException.php diff --git a/src/Bootstrap.php b/src/Bootstrap.php index ece46820..6fa7854f 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -42,6 +42,7 @@ class Bootstrap if (empty($this->context->route)) { + http_response_code(404); $this->context->viewName = 'error-404'; $this->render(); return; @@ -59,6 +60,8 @@ class Bootstrap } catch (SimpleException $e) { + if ($e instanceof SimpleNotFoundException) + http_response_code(404); StatusHelper::failure(rtrim($e->getMessage(), '.') . '.'); if (!$this->context->handleExceptions) $this->context->viewName = 'message'; diff --git a/src/Controllers/LogController.php b/src/Controllers/LogController.php index 90452102..7cc4cec4 100644 --- a/src/Controllers/LogController.php +++ b/src/Controllers/LogController.php @@ -55,7 +55,7 @@ class LogController $name = str_replace(['/', '\\'], '', $name); //paranoia mode $path = TextHelper::absolutePath($this->config->main->logsPath . DS . $name); if (!file_exists($path)) - throw new SimpleException('Specified log doesn\'t exist'); + throw new SimpleNotFoundException('Specified log doesn\'t exist'); //load lines $lines = file_get_contents($path); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 47b0cf33..f56b3b25 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -497,7 +497,7 @@ class PostController $path = TextHelper::absolutePath($this->config->main->filesPath . DS . $post->name); if (!file_exists($path)) - throw new SimpleException('Post file does not exist'); + throw new SimpleNotFoundException('Post file does not exist'); if (!is_readable($path)) throw new SimpleException('Post file is not readable'); diff --git a/src/Models/AbstractCrudModel.php b/src/Models/AbstractCrudModel.php index b7868070..39ac4603 100644 --- a/src/Models/AbstractCrudModel.php +++ b/src/Models/AbstractCrudModel.php @@ -31,7 +31,7 @@ abstract class AbstractCrudModel implements IModel return self::convertRow($row); if ($throw) - throw new SimpleException('Invalid ' . static::getTableName() . ' ID "' . $key . '"'); + throw new SimpleNotFoundException('Invalid ' . static::getTableName() . ' ID "' . $key . '"'); return null; } diff --git a/src/Models/PostModel.php b/src/Models/PostModel.php index b64ee846..f18f739e 100644 --- a/src/Models/PostModel.php +++ b/src/Models/PostModel.php @@ -146,7 +146,7 @@ class PostModel extends AbstractCrudModel return self::convertRow($row); if ($throw) - throw new SimpleException('Invalid post name "' . $key . '"'); + throw new SimpleNotFoundException('Invalid post name "' . $key . '"'); return null; } @@ -171,7 +171,7 @@ class PostModel extends AbstractCrudModel return self::convertRow($row); if ($throw) - throw new SimpleException('Invalid post hash "' . $hash . '"'); + throw new SimpleNotFoundException('Invalid post hash "' . $hash . '"'); return null; } diff --git a/src/Models/TagModel.php b/src/Models/TagModel.php index 94fb191e..8cf0b47f 100644 --- a/src/Models/TagModel.php +++ b/src/Models/TagModel.php @@ -126,7 +126,7 @@ class TagModel extends AbstractCrudModel return self::convertRow($row); if ($throw) - throw new SimpleException('Invalid tag name "' . $key . '"'); + throw new SimpleNotFoundException('Invalid tag name "' . $key . '"'); return null; } diff --git a/src/Models/TokenModel.php b/src/Models/TokenModel.php index e3acec12..c6c59770 100644 --- a/src/Models/TokenModel.php +++ b/src/Models/TokenModel.php @@ -35,7 +35,7 @@ implements IModel public static function findByToken($key, $throw = true) { if (empty($key)) - throw new SimpleException('Invalid security token'); + throw new SimpleNotFoundException('Invalid security token'); $query = (new SqlQuery) ->select('*') @@ -47,7 +47,7 @@ implements IModel return self::convertRow($row); if ($throw) - throw new SimpleException('No user with such security token'); + throw new SimpleNotFoundException('No user with such security token'); return null; } diff --git a/src/Models/UserModel.php b/src/Models/UserModel.php index c7b6ced7..a4c3fd9e 100644 --- a/src/Models/UserModel.php +++ b/src/Models/UserModel.php @@ -95,7 +95,7 @@ class UserModel extends AbstractCrudModel return self::convertRow($row); if ($throw) - throw new SimpleException('Invalid user name "' . $key . '"'); + throw new SimpleNotFoundException('Invalid user name "' . $key . '"'); return null; } @@ -112,7 +112,7 @@ class UserModel extends AbstractCrudModel return self::convertRow($row); if ($throw) - throw new SimpleException('Invalid user name "' . $key . '"'); + throw new SimpleNotFoundException('Invalid user name "' . $key . '"'); return null; } diff --git a/src/SimpleNotFoundException.php b/src/SimpleNotFoundException.php new file mode 100644 index 00000000..28412081 --- /dev/null +++ b/src/SimpleNotFoundException.php @@ -0,0 +1,4 @@ +