mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
The code of constants only support int
and string
. (#2031)
Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
29bf7fa58e
commit
12fda742ff
@ -13,6 +13,10 @@
|
||||
|
||||
- [#2049](https://github.com/hyperf/hyperf/pull/2049) Optimized stdout when server restart for `hyperf/watcher`.
|
||||
|
||||
## Changed
|
||||
|
||||
- [#2301](https://github.com/hyperf/hyperf/pull/2031) The code of constants only support `int` and `string`.
|
||||
|
||||
# v2.0.1 - 2020-07-02
|
||||
|
||||
## Added
|
||||
|
@ -23,7 +23,8 @@ class AnnotationReader
|
||||
foreach ($classConstants as $classConstant) {
|
||||
$code = $classConstant->getValue();
|
||||
$docComment = $classConstant->getDocComment();
|
||||
if ($docComment) {
|
||||
// Not support float and bool, because it will be convert to int.
|
||||
if ($docComment && (is_int($code) || is_string($code))) {
|
||||
$result[$code] = $this->parse($docComment, $result[$code] ?? []);
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,15 @@ class AnnotationReaderTest extends TestCase
|
||||
$this->assertSame('Type disabled', ErrorCodeStub::getType(ErrorCodeStub::TYPE_DISABLE));
|
||||
}
|
||||
|
||||
public function testSupportTypes()
|
||||
{
|
||||
$container = $this->getContainer(true);
|
||||
$this->assertSame('Type1001', ErrorCodeStub::getMessage(ErrorCodeStub::TYPE_INT));
|
||||
$this->assertSame('', ErrorCodeStub::getMessage(ErrorCodeStub::TYPE_FLOAT));
|
||||
$this->assertSame('Type1003.1', ErrorCodeStub::getMessage(ErrorCodeStub::TYPE_FLOAT_STRING));
|
||||
$this->assertSame('TypeString', ErrorCodeStub::getMessage(ErrorCodeStub::TYPE_STRING));
|
||||
}
|
||||
|
||||
protected function getContainer($has = false)
|
||||
{
|
||||
$container = Mockery::mock(ContainerInterface::class);
|
||||
|
@ -62,4 +62,24 @@ class ErrorCodeStub extends AbstractConstants
|
||||
* @Type("Type disabled")
|
||||
*/
|
||||
const TYPE_DISABLE = 0;
|
||||
|
||||
/**
|
||||
* @Message("Type1001")
|
||||
*/
|
||||
const TYPE_INT = 1001;
|
||||
|
||||
/**
|
||||
* @Message("Type1002.1")
|
||||
*/
|
||||
const TYPE_FLOAT = 1002.1;
|
||||
|
||||
/**
|
||||
* @Message("Type1003.1")
|
||||
*/
|
||||
const TYPE_FLOAT_STRING = '1003.1';
|
||||
|
||||
/**
|
||||
* @Message("TypeString")
|
||||
*/
|
||||
const TYPE_STRING = 'string';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user