Add 3 special exception classes for common situations

This commit is contained in:
Kijin Sung 2018-08-27 00:21:21 +09:00
parent 1863edcbb8
commit fe4e336f2b
11 changed files with 82 additions and 25 deletions

View file

@ -0,0 +1,18 @@
<?php
namespace Rhymix\Framework\Exceptions;
/**
* The "invalid request" exception class.
*/
class InvalidRequest extends \Rhymix\Framework\Exception
{
public function __construct($message = '', $code = 0, $previous = null)
{
if ($message === '')
{
$message = lang('msg_invalid_request');
}
parent::__construct($message, $code, $previous);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Rhymix\Framework\Exceptions;
/**
* The "not permitted" exception class.
*/
class NotPermitted extends \Rhymix\Framework\Exception
{
public function __construct($message = '', $code = 0, $previous = null)
{
if ($message === '')
{
$message = lang('msg_not_permitted');
}
parent::__construct($message, $code, $previous);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Rhymix\Framework\Exceptions;
/**
* The "target not found" exception class.
*/
class TargetNotFound extends \Rhymix\Framework\Exception
{
public function __construct($message = '', $code = 0, $previous = null)
{
if ($message === '')
{
$message = lang('msg_not_founded');
}
parent::__construct($message, $code, $previous);
}
}

View file

@ -35,7 +35,7 @@ class adminAdminController extends admin
$menuSrl = Context::get('menu_srl'); $menuSrl = Context::get('menu_srl');
if(!$menuSrl) if(!$menuSrl)
{ {
return $this->stop('msg_invalid_request'); throw new Rhymix\Framework\Exceptions\InvalidRequest;
} }
$oMenuAdminController = getAdminController('menu'); $oMenuAdminController = getAdminController('menu');

View file

@ -168,7 +168,7 @@ class boardAdminController extends board {
$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl); $module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
if($module_info->mid != $mid) if($module_info->mid != $mid)
{ {
throw new Rhymix\Framework\Exception('msg_invalid_request'); throw new Rhymix\Framework\Exceptions\InvalidRequest;
} }
$module_info->hide_category = Context::get('hide_category') == 'Y' ? 'Y' : 'N'; $module_info->hide_category = Context::get('hide_category') == 'Y' ? 'Y' : 'N';

View file

@ -24,7 +24,7 @@ class boardController extends board
// check grant // check grant
if(!$this->grant->write_document) if(!$this->grant->write_document)
{ {
throw new Rhymix\Framework\Exception('msg_not_permitted'); throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
// setup variables // setup variables
@ -107,7 +107,7 @@ class boardController extends board
{ {
if(!$oDocument->isGranted()) if(!$oDocument->isGranted())
{ {
throw new Rhymix\Framework\Exception('msg_not_permitted'); throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
// Protect admin document // Protect admin document
@ -356,7 +356,7 @@ class boardController extends board
// check grant // check grant
if(!$this->grant->write_comment) if(!$this->grant->write_comment)
{ {
throw new Rhymix\Framework\Exception('msg_not_permitted'); throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
$logged_info = Context::get('logged_info'); $logged_info = Context::get('logged_info');
@ -398,7 +398,7 @@ class boardController extends board
$oDocument = $oDocumentModel->getDocument($obj->document_srl); $oDocument = $oDocumentModel->getDocument($obj->document_srl);
if(!$oDocument->isExists()) if(!$oDocument->isExists())
{ {
throw new Rhymix\Framework\Exception('msg_not_founded'); throw new Rhymix\Framework\Exceptions\TargetNotFound;
} }
// For anonymous use, remove writer's information and notifying information // For anonymous use, remove writer's information and notifying information
@ -461,7 +461,7 @@ class boardController extends board
$parent_comment = $oCommentModel->getComment($obj->parent_srl); $parent_comment = $oCommentModel->getComment($obj->parent_srl);
if(!$parent_comment->comment_srl) if(!$parent_comment->comment_srl)
{ {
throw new Rhymix\Framework\Exception('msg_invalid_request'); throw new Rhymix\Framework\Exceptions\InvalidRequest;
} }
if($parent_comment->isSecret() && $this->module_info->secret === 'Y') if($parent_comment->isSecret() && $this->module_info->secret === 'Y')
{ {
@ -496,7 +496,7 @@ class boardController extends board
// check the grant // check the grant
if(!$comment->isGranted()) if(!$comment->isGranted())
{ {
throw new Rhymix\Framework\Exception('msg_not_permitted'); throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
$obj->parent_srl = $comment->parent_srl; $obj->parent_srl = $comment->parent_srl;
$output = $oCommentController->updateComment($obj, $this->grant->manager); $output = $oCommentController->updateComment($obj, $this->grant->manager);
@ -530,7 +530,7 @@ class boardController extends board
if(!$comment_srl) if(!$comment_srl)
{ {
throw new Rhymix\Framework\Exception('msg_invalid_request'); throw new Rhymix\Framework\Exceptions\InvalidRequest;
} }
$oCommentModel = getModel('comment'); $oCommentModel = getModel('comment');
@ -662,7 +662,7 @@ class boardController extends board
$oComment = $oCommentModel->getComment($comment_srl); $oComment = $oCommentModel->getComment($comment_srl);
if(!$oComment->isExists()) if(!$oComment->isExists())
{ {
throw new Rhymix\Framework\Exception('msg_invalid_request'); throw new Rhymix\Framework\Exceptions\InvalidRequest;
} }
// compare the comment password and the user input password // compare the comment password and the user input password
@ -678,7 +678,7 @@ class boardController extends board
$oDocument = $oDocumentModel->getDocument($document_srl); $oDocument = $oDocumentModel->getDocument($document_srl);
if(!$oDocument->isExists()) if(!$oDocument->isExists())
{ {
throw new Rhymix\Framework\Exception('msg_invalid_request'); throw new Rhymix\Framework\Exceptions\InvalidRequest;
} }
// compare the document password and the user input password // compare the document password and the user input password

View file

@ -998,7 +998,7 @@ class boardView extends board
// if the parent comment is not existed // if the parent comment is not existed
if(!$parent_srl) if(!$parent_srl)
{ {
throw new Rhymix\Framework\Exception('msg_invalid_request'); throw new Rhymix\Framework\Exceptions\InvalidRequest;
} }
// get the comment // get the comment
@ -1060,7 +1060,7 @@ class boardView extends board
// if the comment is not existed // if the comment is not existed
if(!$comment_srl) if(!$comment_srl)
{ {
throw new Rhymix\Framework\Exception('msg_invalid_request'); throw new Rhymix\Framework\Exceptions\InvalidRequest;
} }
// get comment information // get comment information
@ -1233,7 +1233,7 @@ class boardView extends board
if($this->grant->update_view !== true) if($this->grant->update_view !== true)
{ {
throw new Rhymix\Framework\Exception('msg_not_permitted'); throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
$updatelog = $oDocumentModel->getDocumentUpdateLog($document_srl); $updatelog = $oDocumentModel->getDocumentUpdateLog($document_srl);
@ -1253,7 +1253,7 @@ class boardView extends board
if($this->grant->update_view !== true) if($this->grant->update_view !== true)
{ {
throw new Rhymix\Framework\Exception('msg_not_permitted'); throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
$update_log = $oDocumentModel->getUpdateLog($update_id); $update_log = $oDocumentModel->getUpdateLog($update_id);
@ -1289,7 +1289,7 @@ class boardView extends board
{ {
iF($this->grant->vote_log_view !== true) iF($this->grant->vote_log_view !== true)
{ {
throw new Rhymix\Framework\Exception('msg_not_permitted'); throw new Rhymix\Framework\Exceptions\NotPermitted;
} }
$oMemberModel = getModel('member'); $oMemberModel = getModel('member');

View file

@ -297,7 +297,7 @@ class importerAdminController extends importer
switch($type) switch($type)
{ {
case 'ttxml' : case 'ttxml' :
if(!$target_module) throw new Rhymix\Framework\Exception('msg_invalid_request'); if(!$target_module) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$oModuleModel = getModel('module'); $oModuleModel = getModel('module');
$columnList = array('module_srl', 'module'); $columnList = array('module_srl', 'module');
@ -317,7 +317,7 @@ class importerAdminController extends importer
break; break;
case 'module' : case 'module' :
// Check if the target module exists // Check if the target module exists
if(!$target_module) throw new Rhymix\Framework\Exception('msg_invalid_request'); if(!$target_module) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$cur = $this->importModule($key, $cur, $index_file, $target_module); $cur = $this->importModule($key, $cur, $index_file, $target_module);
break; break;
} }

View file

@ -20,7 +20,7 @@ class installAdminController extends install
function procInstallAdminInstall() function procInstallAdminInstall()
{ {
$module_name = Context::get('module_name'); $module_name = Context::get('module_name');
if(!$module_name) throw new Rhymix\Framework\Exception('invalid_request'); if(!$module_name) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$oInstallController = getController('install'); $oInstallController = getController('install');
$oInstallController->installModule($module_name, './modules/'.$module_name); $oInstallController->installModule($module_name, './modules/'.$module_name);
@ -35,10 +35,10 @@ class installAdminController extends install
{ {
@set_time_limit(0); @set_time_limit(0);
$module_name = Context::get('module_name'); $module_name = Context::get('module_name');
if(!$module_name) throw new Rhymix\Framework\Exception('invalid_request'); if(!$module_name) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$oModule = getModule($module_name, 'class'); $oModule = getModule($module_name, 'class');
if(!$oModule) throw new Rhymix\Framework\Exception('invalid_request'); if(!$oModule) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$output = $oModule->moduleUpdate(); $output = $oModule->moduleUpdate();
if($output instanceof BaseObject && !$output->toBool()) if($output instanceof BaseObject && !$output->toBool())

View file

@ -49,7 +49,10 @@ class integration_searchView extends integration_search
} }
// Check permissions // Check permissions
if(!$this->grant->access) throw new Rhymix\Framework\Exception('msg_not_permitted'); if(!$this->grant->access)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$config = $oModuleModel->getModuleConfig('integration_search'); $config = $oModuleModel->getModuleConfig('integration_search');
if(!$config) $config = new stdClass; if(!$config) $config = new stdClass;

View file

@ -198,7 +198,7 @@ class pointAdminController extends point
function procPointAdminInsertPointModuleConfig() function procPointAdminInsertPointModuleConfig()
{ {
$module_srl = Context::get('target_module_srl'); $module_srl = Context::get('target_module_srl');
if(!$module_srl) throw new Rhymix\Framework\Exception('msg_invalid_request'); if(!$module_srl) throw new Rhymix\Framework\Exceptions\InvalidRequest;
// In case of batch configuration of several modules // In case of batch configuration of several modules
if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl); if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl);
else $module_srl = array($module_srl); else $module_srl = array($module_srl);
@ -375,7 +375,7 @@ class pointAdminController extends point
$position = (int)Context::get('position'); $position = (int)Context::get('position');
$total = (int)Context::get('total'); $total = (int)Context::get('total');
if(!file_exists('./files/cache/pointRecal.txt')) throw new Rhymix\Framework\Exception('msg_invalid_request'); if(!file_exists('./files/cache/pointRecal.txt')) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$idx = 0; $idx = 0;
$f = fopen("./files/cache/pointRecal.txt","r"); $f = fopen("./files/cache/pointRecal.txt","r");
@ -418,7 +418,7 @@ class pointAdminController extends point
function procPointAdminReset() function procPointAdminReset()
{ {
$module_srl = Context::get('module_srls'); $module_srl = Context::get('module_srls');
if(!$module_srl) throw new Rhymix\Framework\Exception('msg_invalid_request'); if(!$module_srl) throw new Rhymix\Framework\Exceptions\InvalidRequest;
// In case of batch configuration of several modules // In case of batch configuration of several modules
if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl); if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl);
else $module_srl = array($module_srl); else $module_srl = array($module_srl);