mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
Allow adding error message and sprintf() variables using setError()
xpressengine/xe-core#2181 적용시 에러 반환 문법을 단순화하기 위한 조치 기존 방식: return new Object(-1, '에러메시지'); XE 제안 방식: return class_exists('BaseObject') ? new BaseObject(-1, '에러메시지') : new Object('에러메시지'); 라이믹스 방식: return $this->setError('에러메시지'); 기존의 setError() 메소드가 에러 코드만 받을 수 있어서 호환성 보장에 도움이 안 되므로 에러 코드와 에러 메시지를 동시에 넣을 수 있도록 개선하고, 에러 코드를 넣지 않고 에러 메시지만 지정해도 자동으로 -1 에러 코드가 들어가도록 하였음. (첫 번째 인자가 정수인지 아닌지에 따라 판단함.) setError(), setMessage(), setMessageType() 등 기존에 무의미한 반환값을 가지던 메소스들 모두 $this를 반환하도록 함으로써 액션이나 트리거 등의 반환값으로 유효하도록 하고, 원할 경우 method chaining까지 사용할 수 있음. 또한 에러메시지에 변수를 넣어야 할 경우 return new Object(-1, sprintf(Context::getLang('error_msg'), $var1, $var2)); 이렇게 복잡해지는 문제도 해결하기 위해 setError()에 추가로 넣은 인자는 모두 자동으로 sprintf() 처리를 거치도록 함. 예: return $this->setError('error_msg', $var1, $var2); 즉, 아래와 같은 호출 형태가 모두 유효함. - $this->setError(-1); - $this->setError(-1, 'error_msg'); - $this->setError(-1, 'error_msg', $var1, $var2); - $this->setError('error_msg'); - $this->setError('error_msg', $var1, $var2); 단, 이 커밋 이후 신규 작성하는 코어 클래스나 서드파티 자료에서만 사용할 수 있음. 기존 버전과의 호환성을 유지하기를 원하는 서드파티 자료는 XE에서 제안한 삼항식을 사용해야 함.
This commit is contained in:
parent
bf6ccfcb44
commit
9a83e71bff
2 changed files with 65 additions and 56 deletions
|
|
@ -90,43 +90,6 @@ class ModuleObject extends Object
|
|||
return $this->get('redirect_url');
|
||||
}
|
||||
|
||||
/**
|
||||
* set message
|
||||
* @param string $message a message string
|
||||
* @param string $type type of message (error, info, update)
|
||||
* @return void
|
||||
* */
|
||||
function setMessage($message = 'success', $type = NULL)
|
||||
{
|
||||
parent::setMessage($message);
|
||||
$this->setMessageType($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* set type of message
|
||||
* @param string $type type of message (error, info, update)
|
||||
* @return void
|
||||
* */
|
||||
function setMessageType($type)
|
||||
{
|
||||
$this->add('message_type', $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* get type of message
|
||||
* @return string $type
|
||||
* */
|
||||
function getMessageType()
|
||||
{
|
||||
$type = $this->get('message_type');
|
||||
$typeList = array('error' => 1, 'info' => 1, 'update' => 1);
|
||||
if(!isset($typeList[$type]))
|
||||
{
|
||||
$type = $this->getError() ? 'error' : 'info';
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the template path for refresh.html
|
||||
* refresh.html is executed as a result of method execution
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue