-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
1.目前contstans 的用法
`
/**
* @Message("服务器错误")
*/
const SERVER_ERROR = 500;
echo Code::getMessage(Code::SERVER_ERROR);
`
感觉写法有点繁琐。。。想达到的效果是能直接
Code::SERVER_ERROR() = Code::getMessage(Code::SERVER_ERROR) => "服务器错误"
而且这个消息模板有时候可能有些东西不是完全死 可能还想要动态扩展下
Describe the solution you'd like
A clear and concise description of what you want to happen.
`
/**
* @Message("服务器错误%s")
* @Text("%s 错误代号%s")
*/
const SERVER_ERROR = 500;
Code::SERVER_ERROR('text',测试','007'); => '测试错误代号007'
Code::SERVER_ERROR(); => '服务器错误%s'
Code::SERVER_ERROR('message','测试'); => '服务器错误测试'
`
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
重写了AbstractConstants类
`
abstract class AbstractConstants
{
protected static $defaultAnnontion = 'message';
/**
* @param $name
* @param $arguments
* @return string
* @throws ReflectionException
*/
public static function __callStatic($name, $arguments)
{
$class = get_called_class();
$key = count($arguments) >= 1 ? $arguments[0] : static::$defaultAnnontion;
$key = is_string($key) ? $key : static::$defaultAnnontion;
$code = (new ReflectionClass($class))->getConstant($name);
$value = ConstantsCollector::getValue($class, $code, strtolower($key));
array_shift($arguments);
return count($arguments) < 2 ? $value : sprintf($value, ...$arguments);
}
}
`
Additional context
Add any other context or screenshots about the feature request here.
这个有点太个人的想法了 只是提下看看 哈哈哈
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request