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');
if(!$menuSrl)
{
return $this->stop('msg_invalid_request');
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$oMenuAdminController = getAdminController('menu');

View file

@ -168,7 +168,7 @@ class boardAdminController extends board {
$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
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';

View file

@ -24,7 +24,7 @@ class boardController extends board
// check grant
if(!$this->grant->write_document)
{
throw new Rhymix\Framework\Exception('msg_not_permitted');
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// setup variables
@ -107,7 +107,7 @@ class boardController extends board
{
if(!$oDocument->isGranted())
{
throw new Rhymix\Framework\Exception('msg_not_permitted');
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// Protect admin document
@ -356,7 +356,7 @@ class boardController extends board
// check grant
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');
@ -398,7 +398,7 @@ class boardController extends board
$oDocument = $oDocumentModel->getDocument($obj->document_srl);
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
@ -461,7 +461,7 @@ class boardController extends board
$parent_comment = $oCommentModel->getComment($obj->parent_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')
{
@ -496,7 +496,7 @@ class boardController extends board
// check the grant
if(!$comment->isGranted())
{
throw new Rhymix\Framework\Exception('msg_not_permitted');
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$obj->parent_srl = $comment->parent_srl;
$output = $oCommentController->updateComment($obj, $this->grant->manager);
@ -530,7 +530,7 @@ class boardController extends board
if(!$comment_srl)
{
throw new Rhymix\Framework\Exception('msg_invalid_request');
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$oCommentModel = getModel('comment');
@ -662,7 +662,7 @@ class boardController extends board
$oComment = $oCommentModel->getComment($comment_srl);
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
@ -678,7 +678,7 @@ class boardController extends board
$oDocument = $oDocumentModel->getDocument($document_srl);
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

View file

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

View file

@ -297,7 +297,7 @@ class importerAdminController extends importer
switch($type)
{
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');
$columnList = array('module_srl', 'module');
@ -317,7 +317,7 @@ class importerAdminController extends importer
break;
case 'module' :
// 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);
break;
}

View file

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

View file

@ -49,7 +49,10 @@ class integration_searchView extends integration_search
}
// 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');
if(!$config) $config = new stdClass;

View file

@ -198,7 +198,7 @@ class pointAdminController extends point
function procPointAdminInsertPointModuleConfig()
{
$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
if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl);
else $module_srl = array($module_srl);
@ -375,7 +375,7 @@ class pointAdminController extends point
$position = (int)Context::get('position');
$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;
$f = fopen("./files/cache/pointRecal.txt","r");
@ -418,7 +418,7 @@ class pointAdminController extends point
function procPointAdminReset()
{
$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
if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl);
else $module_srl = array($module_srl);