diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index b5cc0fa04f..a4596ab9c0 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -25,12 +25,12 @@ 'concat_space' => [ 'spacing' => 'one', ], - 'fopen_flags' => false, - 'protected_to_private' => false, - 'native_function_invocation' => true, - 'native_constant_invocation' => true, - 'combine_nested_dirname' => true, - 'single_quote' => true, + 'fopen_flags' => false, + 'protected_to_private' => false, + 'native_function_invocation' => true, + 'native_constant_invocation' => true, + 'combine_nested_dirname' => true, + 'single_quote' => true, 'single_space_around_construct' => [ 'constructs_followed_by_a_single_space' => [ 'abstract', @@ -121,10 +121,9 @@ 'control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end', ], 'nullable_type_declaration_for_default_null_value' => false, - 'no_superfluous_phpdoc_tags' => [ - 'allow_mixed' => true, + 'no_superfluous_phpdoc_tags' => [ + 'allow_mixed' => true, 'allow_unused_params' => false, - 'remove_inheritdoc' => false, ], 'no_null_property_initialization' => false, ]) diff --git a/src/Bean/Util/AttributeUtil.php b/src/Bean/Util/AttributeUtil.php new file mode 100644 index 0000000000..46c2a7c9b6 --- /dev/null +++ b/src/Bean/Util/AttributeUtil.php @@ -0,0 +1,103 @@ +getAttributes(\Attribute::class)) + { + throw new \InvalidArgumentException(sprintf('Class %s does not an Attribute', $ref->name)); + } + $constructor = $ref->getConstructor(); + $props = []; + foreach ($attribute as $key => $value) + { + if ($ref->hasProperty($key)) + { + $prop = $ref->getProperty($key); + if ($prop->hasDefaultValue()) + { + if ($prop->getDefaultValue() === $value) + { + continue; + } + } + } + // 构造方法属性提升,无法获取到属性默认值,所以需要获取构造方法参数处理 + if ($constructor) + { + foreach ($constructor->getParameters() as $param) + { + if ($param->name === $key) + { + if ($param->isDefaultValueAvailable() && $param->getDefaultValue() === $value) + { + continue 2; + } + break; + } + } + } + if (\is_object($value)) + { + $value = self::generateAttributesCode([$value], $level + 1); + } + elseif (\is_array($value)) + { + $newValue = []; + foreach ($value as $itemKey => $itemValue) + { + if (\is_object($itemValue)) + { + $newValue[$itemKey] = self::generateAttributesCode($itemValue, $level + 1); + } + else + { + $newValue[$itemKey] = $tab2 . var_export($itemValue, true); + } + } + $value = '[' . \PHP_EOL . implode(',' . \PHP_EOL, $newValue) . \PHP_EOL . $tab1 . ']'; + } + else + { + $value = var_export($value, true); + } + $props[] = $key . ': ' . $value; + } + $attributeCodes[] = $tab1 . ($level ? 'new ' : '') . '\\' . $ref->name . '(' . implode(', ', $props) . ')'; + } + + $result = implode(',' . \PHP_EOL, $attributeCodes); + if (\is_object($attributes)) + { + if (0 === $level) + { + $result = '#[' . \PHP_EOL . $result . \PHP_EOL . str_repeat(' ', $level) . ']'; + } + } + else + { + $result = '[' . \PHP_EOL . $result . \PHP_EOL . str_repeat(' ', $level) . ']'; + if (0 === $level) + { + $result = '#' . $result; + } + } + + return $result; + } +} diff --git a/src/Components/jwt/src/Facade/JWT.php b/src/Components/jwt/src/Facade/JWT.php index 7a88c4db00..c50aef6e74 100644 --- a/src/Components/jwt/src/Facade/JWT.php +++ b/src/Components/jwt/src/Facade/JWT.php @@ -4,12 +4,9 @@ namespace Imi\JWT\Facade; -use Imi\Facade\Annotation\Facade; use Imi\Facade\BaseFacade; /** - * @Facade(class="JWT", request=false, args={}) - * * @method static void __init() * @method static \Imi\JWT\Model\JWTConfig[] getList() * @method static string|null getDefault() @@ -21,6 +18,9 @@ * @method static void validate(?string $name, \Lcobucci\JWT\Token $token) * @method static int getJwtPackageVersion() */ +#[ + \Imi\Facade\Annotation\Facade(class: 'JWT') +] class JWT extends BaseFacade { } diff --git a/src/Components/pgsql/src/Model/Cli/Model/ModelGenerate.php b/src/Components/pgsql/src/Model/Cli/Model/ModelGenerate.php index d8b7b2c24a..ccdd08965d 100644 --- a/src/Components/pgsql/src/Model/Cli/Model/ModelGenerate.php +++ b/src/Components/pgsql/src/Model/Cli/Model/ModelGenerate.php @@ -225,6 +225,11 @@ public function generate(string $namespace, string $baseClass, ?string $database } $this->parseFields($poolName, $fields, $data, 'v' === $item['relkind'], $table, $typeDefinitions); + $data['classAttributeCode'] = \Imi\Bean\Util\AttributeUtil::generateAttributesCode([ + new \Imi\Model\Annotation\Entity(camel: $data['entity'], bean: $data['bean'], incrUpdate: $data['incrUpdate']), + new \Imi\Model\Annotation\Table(name: $data['table']['name'], usePrefix: $data['table']['usePrefix'], id: $data['table']['id'], dbPoolName: $data['poolName']), + ]); + $baseFileName = File::path($basePath, $className . 'Base.php'); if (!is_file($baseFileName) || true === $override || 'base' === $override) { @@ -304,7 +309,7 @@ private function parseFields(?string $poolName, array $fields, ?array &$data, bo $isPk = $field['ordinal_position'] > 0; [$phpType, $phpDefinitionType, $typeConvert] = $this->dbFieldTypeToPhp($field); - $data['fields'][] = [ + $fieldData = [ 'name' => $field['attname'], 'varName' => Text::toCamelName($field['attname']), 'type' => $type = ('_' === $field['typname'][0] ? substr((string) $field['typname'], 1) : $field['typname']), @@ -325,6 +330,10 @@ private function parseFields(?string $poolName, array $fields, ?array &$data, bo 'ref' => \in_array($type, ['json', 'jsonb']), 'virtual' => 's' === $field['attgenerated'], ]; + $fieldData['attributesCode'] = \Imi\Bean\Util\AttributeUtil::generateAttributesCode([ + new \Imi\Model\Annotation\Column(name: $fieldData['name'], type: $fieldData['type'], length: $fieldData['length'], accuracy: $fieldData['accuracy'], nullable: $fieldData['nullable'], default: $fieldData['default'], isPrimaryKey: $fieldData['isPrimaryKey'], primaryKeyIndex: $fieldData['primaryKeyIndex'], isAutoIncrement: $fieldData['isAutoIncrement'], ndims: $fieldData['ndims'], virtual: $fieldData['virtual']), + ]); + $data['fields'][] = $fieldData; if ($isPk) { $data['table']['id'][$primaryKeyIndex] = $field['attname']; diff --git a/src/Components/pgsql/src/Model/Cli/Model/base-template.tpl b/src/Components/pgsql/src/Model/Cli/Model/base-template.tpl index 6051d1dc34..09e19709d8 100644 --- a/src/Components/pgsql/src/Model/Cli/Model/base-template.tpl +++ b/src/Components/pgsql/src/Model/Cli/Model/base-template.tpl @@ -6,22 +6,12 @@ declare(strict_types=1); namespace \Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use as Model; /** * 基类. * - * @Entity(camel=, bean=, incrUpdate=) - * @Table(name="", usePrefix=, id={}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * @@ -29,6 +19,8 @@ use as Model; */ + + abstract class Base extends Model { /** @@ -56,10 +48,11 @@ else * - * @Column(name="", type="", length=, accuracy=, nullable=, default="", isPrimaryKey=, primaryKeyIndex=, isAutoIncrement=, ndims=, virtual=) * @var */ + + protected $ = ; @@ -84,7 +77,7 @@ else * @return static */ - public function set($) + public function set(mixed $): self { $field['length'], diff --git a/src/Components/pgsql/src/Model/Cli/Model/template.tpl b/src/Components/pgsql/src/Model/Cli/Model/template.tpl index 851e781922..c79682cdb4 100644 --- a/src/Components/pgsql/src/Model/Cli/Model/template.tpl +++ b/src/Components/pgsql/src/Model/Cli/Model/template.tpl @@ -11,9 +11,8 @@ use \Base\Base; /** * . - * - * @Inherit */ +#[Inherit] class extends Base { diff --git a/src/Components/pgsql/tests/Model/Base/ArrayTestBase.php b/src/Components/pgsql/tests/Model/Base/ArrayTestBase.php index 9dd8a49fc6..30703e7679 100644 --- a/src/Components/pgsql/tests/Model/Base/ArrayTestBase.php +++ b/src/Components/pgsql/tests/Model/Base/ArrayTestBase.php @@ -4,22 +4,23 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_array_test 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_array_test", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property array|null $arr1 * @property array>|null $arr2 */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_array_test', id: [ + 'id', + ]) +] abstract class ArrayTestBase extends Model { /** @@ -34,9 +35,10 @@ abstract class ArrayTestBase extends Model /** * id. - * - * @Column(name="id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -54,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -64,10 +66,11 @@ public function setId($id) /** * arr1. * - * @Column(name="arr1", type="int8", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=1, virtual=false) - * * @var array|null */ + #[ + \Imi\Model\Annotation\Column(name: 'arr1', type: 'int8', nullable: false, ndims: 1) + ] protected ?array $arr1 = null; /** @@ -87,7 +90,7 @@ public function getArr1(): ?array * * @return static */ - public function setArr1($arr1) + public function setArr1(mixed $arr1): self { $this->arr1 = null === $arr1 ? null : $arr1; @@ -97,10 +100,11 @@ public function setArr1($arr1) /** * arr2. * - * @Column(name="arr2", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=2, virtual=false) - * * @var array>|null */ + #[ + \Imi\Model\Annotation\Column(name: 'arr2', type: 'varchar', length: 255, nullable: false, ndims: 2) + ] protected ?array $arr2 = null; /** @@ -120,7 +124,7 @@ public function getArr2(): ?array * * @return static */ - public function setArr2($arr2) + public function setArr2(mixed $arr2): self { $this->arr2 = null === $arr2 ? null : $arr2; diff --git a/src/Components/pgsql/tests/Model/Base/ArticleBase.php b/src/Components/pgsql/tests/Model/Base/ArticleBase.php index b4a3fab562..c8cf24aab6 100644 --- a/src/Components/pgsql/tests/Model/Base/ArticleBase.php +++ b/src/Components/pgsql/tests/Model/Base/ArticleBase.php @@ -4,23 +4,24 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_article 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_article", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $title * @property string|null $content * @property string|null $time */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_article', id: [ + 'id', + ]) +] abstract class ArticleBase extends Model { /** @@ -35,9 +36,10 @@ abstract class ArticleBase extends Model /** * id. - * - * @Column(name="id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -55,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -64,9 +66,10 @@ public function setId($id) /** * title. - * - * @Column(name="title", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'title', type: 'varchar', length: 255, nullable: false) + ] protected ?string $title = null; /** @@ -84,7 +87,7 @@ public function getTitle(): ?string * * @return static */ - public function setTitle($title) + public function setTitle(mixed $title): self { if (\is_string($title) && mb_strlen($title) > 255) { @@ -97,9 +100,10 @@ public function setTitle($title) /** * content. - * - * @Column(name="content", type="text", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'content', type: 'text', nullable: false) + ] protected ?string $content = null; /** @@ -117,7 +121,7 @@ public function getContent(): ?string * * @return static */ - public function setContent($content) + public function setContent(mixed $content): self { $this->content = null === $content ? null : $content; @@ -126,9 +130,10 @@ public function setContent($content) /** * time. - * - * @Column(name="time", type="timestamp", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'time', type: 'timestamp', length: 6, nullable: false) + ] protected ?string $time = null; /** @@ -146,7 +151,7 @@ public function getTime(): ?string * * @return static */ - public function setTime($time) + public function setTime(mixed $time): self { $this->time = null === $time ? null : $time; diff --git a/src/Components/pgsql/tests/Model/Base/MemberBase.php b/src/Components/pgsql/tests/Model/Base/MemberBase.php index 3e63b671f6..a86f3b13e6 100644 --- a/src/Components/pgsql/tests/Model/Base/MemberBase.php +++ b/src/Components/pgsql/tests/Model/Base/MemberBase.php @@ -4,22 +4,23 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_member 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_member", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $username 用户名 * @property string|null $password 密码 */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_member', id: [ + 'id', + ]) +] abstract class MemberBase extends Model { /** @@ -34,9 +35,10 @@ abstract class MemberBase extends Model /** * id. - * - * @Column(name="id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -54,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -64,9 +66,10 @@ public function setId($id) /** * 用户名. * username. - * - * @Column(name="username", type="varchar", length=32, accuracy=0, nullable=false, default="''::character varying", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'username', type: 'varchar', length: 32, nullable: false, default: '\'\'::character varying') + ] protected ?string $username = ''; /** @@ -84,7 +87,7 @@ public function getUsername(): ?string * * @return static */ - public function setUsername($username) + public function setUsername(mixed $username): self { if (\is_string($username) && mb_strlen($username) > 32) { @@ -98,9 +101,10 @@ public function setUsername($username) /** * 密码. * password. - * - * @Column(name="password", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'password', type: 'varchar', length: 255, nullable: false) + ] protected ?string $password = null; /** @@ -118,7 +122,7 @@ public function getPassword(): ?string * * @return static */ - public function setPassword($password) + public function setPassword(mixed $password): self { if (\is_string($password) && mb_strlen($password) > 255) { diff --git a/src/Components/pgsql/tests/Model/Base/NoIncPkBase.php b/src/Components/pgsql/tests/Model/Base/NoIncPkBase.php index d4beca37d9..2dfcfc6e5f 100644 --- a/src/Components/pgsql/tests/Model/Base/NoIncPkBase.php +++ b/src/Components/pgsql/tests/Model/Base/NoIncPkBase.php @@ -4,22 +4,24 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_no_inc_pk 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_no_inc_pk", usePrefix=false, id={"a_id", "b_id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $aId * @property int|null $bId * @property string|null $value */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_no_inc_pk', id: [ + 'a_id', + 'b_id', + ]) +] abstract class NoIncPkBase extends Model { /** @@ -34,9 +36,10 @@ abstract class NoIncPkBase extends Model /** * a_id. - * - * @Column(name="a_id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'a_id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0) + ] protected ?int $aId = null; /** @@ -54,7 +57,7 @@ public function getAId(): ?int * * @return static */ - public function setAId($aId) + public function setAId(mixed $aId): self { $this->aId = null === $aId ? null : (int) $aId; @@ -63,9 +66,10 @@ public function setAId($aId) /** * b_id. - * - * @Column(name="b_id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'b_id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 1) + ] protected ?int $bId = null; /** @@ -83,7 +87,7 @@ public function getBId(): ?int * * @return static */ - public function setBId($bId) + public function setBId(mixed $bId): self { $this->bId = null === $bId ? null : (int) $bId; @@ -92,9 +96,10 @@ public function setBId($bId) /** * value. - * - * @Column(name="value", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'value', type: 'varchar', length: 255, nullable: false) + ] protected ?string $value = null; /** @@ -112,7 +117,7 @@ public function getValue(): ?string * * @return static */ - public function setValue($value) + public function setValue(mixed $value): self { if (\is_string($value) && mb_strlen($value) > 255) { diff --git a/src/Components/pgsql/tests/Model/Base/PerformanceBase.php b/src/Components/pgsql/tests/Model/Base/PerformanceBase.php index c475e04153..c88d8d889d 100644 --- a/src/Components/pgsql/tests/Model/Base/PerformanceBase.php +++ b/src/Components/pgsql/tests/Model/Base/PerformanceBase.php @@ -4,21 +4,22 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_performance 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_performance", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $value */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_performance', id: [ + 'id', + ]) +] abstract class PerformanceBase extends Model { /** @@ -33,9 +34,10 @@ abstract class PerformanceBase extends Model /** * id. - * - * @Column(name="id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -53,7 +55,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -62,9 +64,10 @@ public function setId($id) /** * value. - * - * @Column(name="value", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'value', type: 'varchar', length: 255, nullable: false) + ] protected ?string $value = null; /** @@ -82,7 +85,7 @@ public function getValue(): ?string * * @return static */ - public function setValue($value) + public function setValue(mixed $value): self { if (\is_string($value) && mb_strlen($value) > 255) { diff --git a/src/Components/pgsql/tests/Model/Base/TestJsonBase.php b/src/Components/pgsql/tests/Model/Base/TestJsonBase.php index 2d640bc630..9ed4cc7c3b 100644 --- a/src/Components/pgsql/tests/Model/Base/TestJsonBase.php +++ b/src/Components/pgsql/tests/Model/Base/TestJsonBase.php @@ -4,21 +4,22 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * test 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_json", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property \Imi\Util\LazyArrayObject|array|null $jsonData json数据 */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_json', id: [ + 'id', + ]) +] abstract class TestJsonBase extends Model { /** @@ -33,9 +34,10 @@ abstract class TestJsonBase extends Model /** * id. - * - * @Column(name="id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -53,7 +55,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -64,10 +66,11 @@ public function setId($id) * json数据. * json_data. * - * @Column(name="json_data", type="json", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) - * * @var \Imi\Util\LazyArrayObject|array|null */ + #[ + \Imi\Model\Annotation\Column(name: 'json_data', type: 'json', nullable: false) + ] protected $jsonData = null; /** @@ -87,7 +90,7 @@ public function &getJsonData() * * @return static */ - public function setJsonData($jsonData) + public function setJsonData(mixed $jsonData): self { $this->jsonData = null === $jsonData ? null : $jsonData; diff --git a/src/Components/pgsql/tests/Model/Base/TestSoftDeleteBase.php b/src/Components/pgsql/tests/Model/Base/TestSoftDeleteBase.php index 6d7064c951..978b0ab8a2 100644 --- a/src/Components/pgsql/tests/Model/Base/TestSoftDeleteBase.php +++ b/src/Components/pgsql/tests/Model/Base/TestSoftDeleteBase.php @@ -4,22 +4,23 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_test_soft_delete 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_soft_delete", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $title * @property int|null $deleteTime */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_soft_delete', id: [ + 'id', + ]) +] abstract class TestSoftDeleteBase extends Model { /** @@ -34,9 +35,10 @@ abstract class TestSoftDeleteBase extends Model /** * id. - * - * @Column(name="id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -54,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -63,9 +65,10 @@ public function setId($id) /** * title. - * - * @Column(name="title", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'title', type: 'varchar', length: 255, nullable: false) + ] protected ?string $title = null; /** @@ -83,7 +86,7 @@ public function getTitle(): ?string * * @return static */ - public function setTitle($title) + public function setTitle(mixed $title): self { if (\is_string($title) && mb_strlen($title) > 255) { @@ -96,9 +99,10 @@ public function setTitle($title) /** * delete_time. - * - * @Column(name="delete_time", type="int4", length=-1, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'delete_time', type: 'int4', nullable: false, default: '0') + ] protected ?int $deleteTime = 0; /** @@ -116,7 +120,7 @@ public function getDeleteTime(): ?int * * @return static */ - public function setDeleteTime($deleteTime) + public function setDeleteTime(mixed $deleteTime): self { $this->deleteTime = null === $deleteTime ? null : (int) $deleteTime; diff --git a/src/Components/pgsql/tests/Model/Base/TreeBase.php b/src/Components/pgsql/tests/Model/Base/TreeBase.php index 5679e7ee88..863c79df0f 100644 --- a/src/Components/pgsql/tests/Model/Base/TreeBase.php +++ b/src/Components/pgsql/tests/Model/Base/TreeBase.php @@ -4,22 +4,23 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_tree 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_tree", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $parentId * @property string|null $name */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_tree', id: [ + 'id', + ]) +] abstract class TreeBase extends Model { /** @@ -34,9 +35,10 @@ abstract class TreeBase extends Model /** * id. - * - * @Column(name="id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -54,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -63,9 +65,10 @@ public function setId($id) /** * parent_id. - * - * @Column(name="parent_id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'parent_id', type: 'int4', nullable: false) + ] protected ?int $parentId = null; /** @@ -83,7 +86,7 @@ public function getParentId(): ?int * * @return static */ - public function setParentId($parentId) + public function setParentId(mixed $parentId): self { $this->parentId = null === $parentId ? null : (int) $parentId; @@ -92,9 +95,10 @@ public function setParentId($parentId) /** * name. - * - * @Column(name="name", type="varchar", length=32, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'name', type: 'varchar', length: 32, nullable: false) + ] protected ?string $name = null; /** @@ -112,7 +116,7 @@ public function getName(): ?string * * @return static */ - public function setName($name) + public function setName(mixed $name): self { if (\is_string($name) && mb_strlen($name) > 32) { diff --git a/src/Components/pgsql/tests/Model/Base/UpdateTimeBase.php b/src/Components/pgsql/tests/Model/Base/UpdateTimeBase.php index 7b5e63c1fa..85d1ac5df8 100644 --- a/src/Components/pgsql/tests/Model/Base/UpdateTimeBase.php +++ b/src/Components/pgsql/tests/Model/Base/UpdateTimeBase.php @@ -4,17 +4,12 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_update_time 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_update_time", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $date @@ -29,6 +24,12 @@ * @property int|null $int * @property int|null $bigint */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_update_time', id: [ + 'id', + ]) +] abstract class UpdateTimeBase extends Model { /** @@ -43,9 +44,10 @@ abstract class UpdateTimeBase extends Model /** * id. - * - * @Column(name="id", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int4', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -63,7 +65,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -72,9 +74,10 @@ public function setId($id) /** * date. - * - * @Column(name="date", type="date", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'date', type: 'date', nullable: false) + ] protected ?string $date = null; /** @@ -92,7 +95,7 @@ public function getDate(): ?string * * @return static */ - public function setDate($date) + public function setDate(mixed $date): self { $this->date = null === $date ? null : $date; @@ -101,9 +104,10 @@ public function setDate($date) /** * time. - * - * @Column(name="time", type="time", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'time', type: 'time', length: 6, nullable: false) + ] protected ?string $time = null; /** @@ -121,7 +125,7 @@ public function getTime(): ?string * * @return static */ - public function setTime($time) + public function setTime(mixed $time): self { $this->time = null === $time ? null : $time; @@ -130,9 +134,10 @@ public function setTime($time) /** * timetz. - * - * @Column(name="timetz", type="timetz", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'timetz', type: 'timetz', length: 6, nullable: false) + ] protected ?string $timetz = null; /** @@ -150,7 +155,7 @@ public function getTimetz(): ?string * * @return static */ - public function setTimetz($timetz) + public function setTimetz(mixed $timetz): self { $this->timetz = null === $timetz ? null : $timetz; @@ -159,9 +164,10 @@ public function setTimetz($timetz) /** * time2. - * - * @Column(name="time2", type="time", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'time2', type: 'time', length: 6, nullable: false) + ] protected ?string $time2 = null; /** @@ -179,7 +185,7 @@ public function getTime2(): ?string * * @return static */ - public function setTime2($time2) + public function setTime2(mixed $time2): self { $this->time2 = null === $time2 ? null : $time2; @@ -188,9 +194,10 @@ public function setTime2($time2) /** * timetz2. - * - * @Column(name="timetz2", type="timetz", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'timetz2', type: 'timetz', length: 6, nullable: false) + ] protected ?string $timetz2 = null; /** @@ -208,7 +215,7 @@ public function getTimetz2(): ?string * * @return static */ - public function setTimetz2($timetz2) + public function setTimetz2(mixed $timetz2): self { $this->timetz2 = null === $timetz2 ? null : $timetz2; @@ -217,9 +224,10 @@ public function setTimetz2($timetz2) /** * timestamp. - * - * @Column(name="timestamp", type="timestamp", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'timestamp', type: 'timestamp', length: 6, nullable: false) + ] protected ?string $timestamp = null; /** @@ -237,7 +245,7 @@ public function getTimestamp(): ?string * * @return static */ - public function setTimestamp($timestamp) + public function setTimestamp(mixed $timestamp): self { $this->timestamp = null === $timestamp ? null : $timestamp; @@ -246,9 +254,10 @@ public function setTimestamp($timestamp) /** * timestamptz. - * - * @Column(name="timestamptz", type="timestamptz", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'timestamptz', type: 'timestamptz', length: 6, nullable: false) + ] protected ?string $timestamptz = null; /** @@ -266,7 +275,7 @@ public function getTimestamptz(): ?string * * @return static */ - public function setTimestamptz($timestamptz) + public function setTimestamptz(mixed $timestamptz): self { $this->timestamptz = null === $timestamptz ? null : $timestamptz; @@ -275,9 +284,10 @@ public function setTimestamptz($timestamptz) /** * timestamp2. - * - * @Column(name="timestamp2", type="timestamp", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'timestamp2', type: 'timestamp', length: 6, nullable: false) + ] protected ?string $timestamp2 = null; /** @@ -295,7 +305,7 @@ public function getTimestamp2(): ?string * * @return static */ - public function setTimestamp2($timestamp2) + public function setTimestamp2(mixed $timestamp2): self { $this->timestamp2 = null === $timestamp2 ? null : $timestamp2; @@ -304,9 +314,10 @@ public function setTimestamp2($timestamp2) /** * timestamptz2. - * - * @Column(name="timestamptz2", type="timestamptz", length=6, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'timestamptz2', type: 'timestamptz', length: 6, nullable: false) + ] protected ?string $timestamptz2 = null; /** @@ -324,7 +335,7 @@ public function getTimestamptz2(): ?string * * @return static */ - public function setTimestamptz2($timestamptz2) + public function setTimestamptz2(mixed $timestamptz2): self { $this->timestamptz2 = null === $timestamptz2 ? null : $timestamptz2; @@ -333,9 +344,10 @@ public function setTimestamptz2($timestamptz2) /** * int. - * - * @Column(name="int", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'int', type: 'int4', nullable: false) + ] protected ?int $int = null; /** @@ -353,7 +365,7 @@ public function getInt(): ?int * * @return static */ - public function setInt($int) + public function setInt(mixed $int): self { $this->int = null === $int ? null : (int) $int; @@ -362,9 +374,10 @@ public function setInt($int) /** * bigint. - * - * @Column(name="bigint", type="int8", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'bigint', type: 'int8', nullable: false) + ] protected ?int $bigint = null; /** @@ -382,7 +395,7 @@ public function getBigint(): ?int * * @return static */ - public function setBigint($bigint) + public function setBigint(mixed $bigint): self { $this->bigint = null === $bigint ? null : (int) $bigint; diff --git a/src/Components/pgsql/tests/Model/Base/VirtualColumnBase.php b/src/Components/pgsql/tests/Model/Base/VirtualColumnBase.php index d8a43b137b..707999a300 100644 --- a/src/Components/pgsql/tests/Model/Base/VirtualColumnBase.php +++ b/src/Components/pgsql/tests/Model/Base/VirtualColumnBase.php @@ -4,22 +4,23 @@ namespace Imi\Pgsql\Test\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Pgsql\Model\PgModel as Model; /** * tb_virtual_column 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_virtual_column", usePrefix=false, id={"id"}, dbPoolName=null) + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $amount * @property string|float|int|null $virtualAmount */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_virtual_column', id: [ + 'id', + ]) +] abstract class VirtualColumnBase extends Model { /** @@ -34,9 +35,10 @@ abstract class VirtualColumnBase extends Model /** * id. - * - * @Column(name="id", type="int8", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int8', nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true) + ] protected ?int $id = null; /** @@ -54,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -63,9 +65,10 @@ public function setId($id) /** * amount. - * - * @Column(name="amount", type="int4", length=-1, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'amount', type: 'int4', nullable: false) + ] protected ?int $amount = null; /** @@ -83,7 +86,7 @@ public function getAmount(): ?int * * @return static */ - public function setAmount($amount) + public function setAmount(mixed $amount): self { $this->amount = null === $amount ? null : (int) $amount; @@ -92,9 +95,10 @@ public function setAmount($amount) /** * virtual_amount. - * - * @Column(name="virtual_amount", type="numeric", length=10, accuracy=2, nullable=false, default="((amount)::numeric / (100)::numeric)", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, ndims=0, virtual=true) */ + #[ + \Imi\Model\Annotation\Column(name: 'virtual_amount', type: 'numeric', length: 10, nullable: false, accuracy: 2, default: '((amount)::numeric / (100)::numeric)', virtual: true) + ] protected string|float|int|null $virtualAmount = null; /** @@ -112,7 +116,7 @@ public function getVirtualAmount(): string|float|int|null * * @return static */ - public function setVirtualAmount($virtualAmount) + public function setVirtualAmount(mixed $virtualAmount): self { $this->virtualAmount = null === $virtualAmount ? null : $virtualAmount; diff --git a/src/Components/queue/src/Facade/Queue.php b/src/Components/queue/src/Facade/Queue.php index 6148004c41..08f6a19d2c 100644 --- a/src/Components/queue/src/Facade/Queue.php +++ b/src/Components/queue/src/Facade/Queue.php @@ -4,17 +4,17 @@ namespace Imi\Queue\Facade; -use Imi\Facade\Annotation\Facade; use Imi\Facade\BaseFacade; /** - * @Facade(class="imiQueue", request=false, args={}) - * * @method static array getList() * @method static \Imi\Queue\Service\QueueService setList(array $list) * @method static \Imi\Queue\Model\QueueConfig getQueueConfig(?string $name = NULL) * @method static \Imi\Queue\Driver\IQueueDriver getQueue(?string $name = NULL) */ +#[ + \Imi\Facade\Annotation\Facade(class: 'imiQueue') +] class Queue extends BaseFacade { } diff --git a/src/Components/swoole/src/Util/Co/ChannelContainer.php b/src/Components/swoole/src/Util/Co/ChannelContainer.php index ba2652e869..61c9c08cc0 100644 --- a/src/Components/swoole/src/Util/Co/ChannelContainer.php +++ b/src/Components/swoole/src/Util/Co/ChannelContainer.php @@ -4,12 +4,9 @@ namespace Imi\Swoole\Util\Co; -use Imi\Facade\Annotation\Facade; use Imi\Facade\BaseFacade; /** - * @Facade(class="Yurun\Swoole\CoPool\ChannelContainer", request=false, args={}) - * * @method static bool push(string $id, $data, float $timeout = -1.0) * @method static mixed pop(string $id, float $timeout = -1.0) * @method static mixed finallyPop(string $id, float $timeout = -1.0) @@ -22,6 +19,9 @@ * @method static bool hasChannel(string $id) * @method static void removeChannel(string $id) */ +#[ + \Imi\Facade\Annotation\Facade(class: \Yurun\Swoole\CoPool\ChannelContainer::class) +] class ChannelContainer extends BaseFacade { } diff --git a/src/Facade/Cli/FacadeGenerate.php b/src/Facade/Cli/FacadeGenerate.php index 6d29da8d7a..ca38a2fd16 100644 --- a/src/Facade/Cli/FacadeGenerate.php +++ b/src/Facade/Cli/FacadeGenerate.php @@ -4,9 +4,9 @@ namespace Imi\Facade\Cli; -use Imi\Bean\Annotation; use Imi\Bean\BeanManager; use Imi\Bean\ReflectionUtil; +use Imi\Bean\Util\AttributeUtil; use Imi\Cli\Annotation\Argument; use Imi\Cli\Annotation\Command; use Imi\Cli\Annotation\CommandAction; @@ -58,7 +58,7 @@ public function generate(string $facadeClass, string $class, bool $request): voi throw new \RuntimeException(sprintf('Get namespace %s path failed', $namespace)); } $fileName = File::path($fileName, $shortClassName . '.php'); - $facadeAnnotation = Annotation::toComments(new Facade([ + $facadeAttribute = AttributeUtil::generateAttributesCode(new Facade([ 'class' => $class, 'request' => $request, ])); @@ -144,7 +144,7 @@ public function generate(string $facadeClass, string $class, bool $request): voi $methods[] = '@method static ' . $returnType . ' ' . $methodName . '(' . $params . ')'; } // @phpstan-ignore-next-line - $content = (static function () use ($namespace, $facadeAnnotation, $methods, $shortClassName): string { + $content = (static function () use ($namespace, $facadeAttribute, $methods, $shortClassName): string { ob_start(); include __DIR__ . '/template.tpl'; diff --git a/src/Facade/Cli/template.tpl b/src/Facade/Cli/template.tpl index bada36416c..e848613bd1 100644 --- a/src/Facade/Cli/template.tpl +++ b/src/Facade/Cli/template.tpl @@ -1,21 +1,23 @@ - + declare(strict_types=1); -namespace ; +namespace ; use Imi\Facade\BaseFacade; -use Imi\Facade\Annotation\Facade; /** - * - + - * - + * + */ -class extends BaseFacade + + +class extends BaseFacade { } diff --git a/src/Model/Cli/Model/ModelGenerate.php b/src/Model/Cli/Model/ModelGenerate.php index 7b093739e1..0ef54ab311 100644 --- a/src/Model/Cli/Model/ModelGenerate.php +++ b/src/Model/Cli/Model/ModelGenerate.php @@ -241,16 +241,16 @@ public function generate(string $namespace, string $baseClass, ?string $database 'id' => [], 'usePrefix' => $usePrefix, ], - 'fields' => [], - 'camel' => $entity, - 'bean' => $tableConfig['bean'] ?? $bean, - 'incrUpdate' => $tableConfig['incrUpdate'] ?? $incrUpdate, - 'poolName' => $poolName, - 'ddl' => $ddl, - 'rawDDL' => $rawDDL, - 'ddlDecode' => $ddlDecodeTmp ?? ('' === $ddlDecode ? null : $ddlDecode), - 'tableComment' => $tableComment, - 'lengthCheck' => $lengthCheck, + 'fields' => [], + 'camel' => $entity, + 'bean' => $tableConfig['bean'] ?? $bean, + 'incrUpdate' => $tableConfig['incrUpdate'] ?? $incrUpdate, + 'poolName' => $poolName, + 'ddl' => $ddl, + 'rawDDL' => $rawDDL, + 'ddlDecode' => $ddlDecodeTmp ?? ('' === $ddlDecode ? null : $ddlDecode), + 'tableComment' => $tableComment, + 'lengthCheck' => $lengthCheck, ]; $fields = $query->execute(sprintf('show full columns from `%s`.`%s`', $database, $table))->getArray(); $typeDefinitions = []; @@ -263,6 +263,12 @@ public function generate(string $namespace, string $baseClass, ?string $database $this->parseFields($fields, $pks, $data, $typeDefinitions); + $data['classAttributeCode'] = \Imi\Bean\Util\AttributeUtil::generateAttributesCode([ + new \Imi\Model\Annotation\Entity(camel: $data['camel'], bean: $data['bean'], incrUpdate: $data['incrUpdate']), + new \Imi\Model\Annotation\Table(name: $data['table']['name'], usePrefix: $data['table']['usePrefix'], id: $data['table']['id'], dbPoolName: $data['poolName']), + new \Imi\Model\Annotation\DDL(sql: $data['ddl']), + ]); + $baseFileName = File::path($basePath, $className . 'Base.php'); Event::trigger(BeforeGenerateModel::class, $data, $this, BeforeGenerateModel::class); @@ -327,7 +333,7 @@ private function parseFields(array $fields, array $pks, ?array &$data, array $ty $this->parseFieldType($field['Type'], $typeName, $length, $accuracy, $unsigned); $isPk = isset($pks[$field['Field']]); [$phpType, $phpDefinitionType, $typeConvert] = $this->dbFieldTypeToPhp($typeName); - $data['fields'][] = [ + $fieldData = [ 'name' => $field['Field'], 'varName' => Text::toCamelName($field['Field']), 'type' => $typeName, @@ -348,6 +354,10 @@ private function parseFields(array $fields, array $pks, ?array &$data, array $ty 'unsigned' => $unsigned, 'virtual' => str_contains((string) $field['Extra'], 'VIRTUAL GENERATED'), ]; + $fieldData['attributesCode'] = \Imi\Bean\Util\AttributeUtil::generateAttributesCode([ + new \Imi\Model\Annotation\Column(name: $fieldData['name'], type: $fieldData['type'], length: $fieldData['length'], accuracy: $fieldData['accuracy'], nullable: $fieldData['nullable'], default: $fieldData['default'], isPrimaryKey: $fieldData['isPrimaryKey'], primaryKeyIndex: $fieldData['primaryKeyIndex'], isAutoIncrement: $fieldData['isAutoIncrement'], unsigned: $fieldData['unsigned'], virtual: $fieldData['virtual']), + ]); + $data['fields'][] = $fieldData; if ($isPk) { $data['table']['id'][$primaryKeyIndex] = $field['Field']; diff --git a/src/Model/Cli/Model/base-template.tpl b/src/Model/Cli/Model/base-template.tpl index 540e4122db..8f13ca742a 100644 --- a/src/Model/Cli/Model/base-template.tpl +++ b/src/Model/Cli/Model/base-template.tpl @@ -6,25 +6,12 @@ declare(strict_types=1); namespace \Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use as Model; /** * 基类. * - * @Entity(camel=, bean=, incrUpdate=) - * @Table(name="", usePrefix=, id={}, dbPoolName=null) - * @DDL(sql="", decode="") + * 此文件是自动生成,请勿手动修改此文件! * @@ -32,6 +19,8 @@ use as Model; */ + + abstract class Base extends Model { /** @@ -59,10 +48,11 @@ else * - * @Column(name="", type="", length=, accuracy=, nullable=, default="", isPrimaryKey=, primaryKeyIndex=, isAutoIncrement=, unsigned=, virtual=) * @var */ + + protected $ = ; @@ -82,11 +72,12 @@ else /** * 赋值 . + * * @param $ * @return static */ - public function set($) + public function set(mixed $): self { $field['length'], diff --git a/src/Model/Cli/Model/template.tpl b/src/Model/Cli/Model/template.tpl index 851e781922..c79682cdb4 100644 --- a/src/Model/Cli/Model/template.tpl +++ b/src/Model/Cli/Model/template.tpl @@ -11,9 +11,8 @@ use \Base\Base; /** * . - * - * @Inherit */ +#[Inherit] class extends Base { diff --git a/src/RequestContextProxy/Cli/RequestContextProxyGenerate.php b/src/RequestContextProxy/Cli/RequestContextProxyGenerate.php index f12ebd49e4..a2f9685065 100644 --- a/src/RequestContextProxy/Cli/RequestContextProxyGenerate.php +++ b/src/RequestContextProxy/Cli/RequestContextProxyGenerate.php @@ -4,11 +4,11 @@ namespace Imi\RequestContextProxy\Cli; -use Imi\Bean\Annotation; use Imi\Bean\Annotation\Bean; use Imi\Bean\BeanFactory; use Imi\Bean\BeanManager; use Imi\Bean\ReflectionUtil; +use Imi\Bean\Util\AttributeUtil; use Imi\Cli\Annotation\Command; use Imi\Cli\Annotation\CommandAction; use Imi\Cli\Annotation\Option; @@ -60,21 +60,19 @@ public function generate(string $target, string $class, string $name, ?string $b throw new \RuntimeException(sprintf('Get namespace %s path failed', $namespace)); } $fileName = File::path($fileName, $shortClassName . '.php'); - $requestContextProxyAnnotation = Annotation::toComments(new RequestContextProxy([ + $attributes = []; + $attributes[] = new RequestContextProxy([ 'class' => $class, 'name' => $name, - ])); - if (null === $bean) + ]); + if (null !== $bean) { - $beanAnnotation = null; - } - else - { - $beanAnnotation = Annotation::toComments(new Bean([ + $attributes[] = new Bean([ 'name' => $bean, 'recursion' => $recursion, - ])); + ]); } + $classAttributesCode = AttributeUtil::generateAttributesCode($attributes); $refClass = new \ReflectionClass($fromClass); $methods = []; foreach ($refClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) @@ -208,7 +206,7 @@ public function generate(string $target, string $class, string $name, ?string $b } } // @phpstan-ignore-next-line - $content = (static function () use ($namespace, $requestContextProxyAnnotation, $methods, $shortClassName, $beanAnnotation, $interface, $methodCodes): string { + $content = (static function () use ($namespace, $classAttributesCode, $methods, $shortClassName, $interface, $methodCodes): string { ob_start(); include __DIR__ . '/template.tpl'; diff --git a/src/RequestContextProxy/Cli/template.tpl b/src/RequestContextProxy/Cli/template.tpl index c3b9d33d39..307a7265ac 100644 --- a/src/RequestContextProxy/Cli/template.tpl +++ b/src/RequestContextProxy/Cli/template.tpl @@ -1,25 +1,21 @@ - + namespace ; -use Imi\Bean\Annotation\Bean; use Imi\RequestContextProxy\BaseRequestContextProxy; -use Imi\RequestContextProxy\Annotation\RequestContextProxy; /** - - * - - - * - - * - + * */ -class extends BaseRequestContextProxy implements \ + + +class extends BaseRequestContextProxy implements \ { diff --git a/src/Server/Http/Cli/ControllerGenerate.php b/src/Server/Http/Cli/ControllerGenerate.php index 2c82b797c6..7d2f54aaad 100644 --- a/src/Server/Http/Cli/ControllerGenerate.php +++ b/src/Server/Http/Cli/ControllerGenerate.php @@ -4,12 +4,15 @@ namespace Imi\Server\Http\Cli; +use Imi\Bean\Util\AttributeUtil; use Imi\Cli\Annotation\Argument; use Imi\Cli\Annotation\Command; use Imi\Cli\Annotation\CommandAction; use Imi\Cli\Annotation\Option; use Imi\Cli\ArgType; use Imi\Cli\Contract\BaseCommand; +use Imi\Server\Http\Route\Annotation\Controller; +use Imi\Server\View\Annotation\View; use Imi\Util\File; use Imi\Util\Imi; @@ -37,7 +40,11 @@ public function generate(string $name, string $namespace, ?string $prefix, ?stri { $prefix = '/' . $name . '/'; } - $data = compact('name', 'namespace', 'prefix', 'render', 'override'); + $classAttributesCode = AttributeUtil::generateAttributesCode([ + new Controller(prefix: $prefix), + new View(renderType: $render), + ]); + $data = compact('name', 'namespace', 'prefix', 'render', 'override', 'classAttributesCode'); if ($rest) { $content = $this->renderTemplate($data, 'restTemplate'); diff --git a/src/Server/Http/Cli/restTemplate.tpl b/src/Server/Http/Cli/restTemplate.tpl index 4fed1992e4..d3211eb635 100644 --- a/src/Server/Http/Cli/restTemplate.tpl +++ b/src/Server/Http/Cli/restTemplate.tpl @@ -1,43 +1,40 @@ - + declare(strict_types=1); -namespace ; +namespace ; -use Imi\Controller\HttpController; +use Imi\Server\Http\Controller\HttpController; use Imi\Server\View\Annotation\View; use Imi\Server\Http\Route\Annotation\Route; use Imi\Server\Http\Route\Annotation\Action; use Imi\Server\Http\Route\Annotation\Controller; -/** - * @Controller("") - * @View(renderType="") - */ -class extends HttpController + + +class extends HttpController { /** * query - * - * @Action - * @Route(url="", method={"GET"}) - * @return void */ - public function query() + #[ + Action, + Route(url: '', method=['GET']) + ] + public function query(): array { return [1, 2, 3]; } /** * find - * - * @Action - * @Route(url="./{id}", method={"GET"}) - * - * @param int $id - * @return void */ - public function find($id) + #[ + Action, + Route(url: './{id}', method=['GET']) + ] + public function find(int $id): array { return [ 'id' => $id, @@ -46,12 +43,12 @@ class extends HttpController /** * create - * - * @Action - * @Route(url="", method={"POST"}) - * @return void */ - public function create() + #[ + Action, + Route(url: '', method=['POST']) + ] + public function create(): array { return [ 'operation' => 'create', @@ -62,14 +59,12 @@ class extends HttpController /** * update - * - * @Action - * @Route(url="./{id}", method={"PUT"}) - * - * @param int $id - * @return void */ - public function update($id) + #[ + Action, + Route(url: './{id}', method=['PUT']) + ] + public function update(int $id): array { return [ 'id' => $id, @@ -80,14 +75,12 @@ class extends HttpController /** * delete - * - * @Action - * @Route(url="./{id}", method={"DELETE"}) - * - * @param int $id - * @return void */ - public function delete($id) + #[ + Action, + Route(url: './{id}', method=['DELETE']) + ] + public function delete(int $id): array { return [ 'id' => $id, diff --git a/src/Server/Http/Cli/template.tpl b/src/Server/Http/Cli/template.tpl index e65d8f4138..da516c7718 100644 --- a/src/Server/Http/Cli/template.tpl +++ b/src/Server/Http/Cli/template.tpl @@ -1,27 +1,24 @@ - + declare(strict_types=1); -namespace ; +namespace ; -use Imi\Controller\HttpController; +use Imi\Server\Http\Controller\HttpController; use Imi\Server\View\Annotation\View; use Imi\Server\Http\Route\Annotation\Action; use Imi\Server\Http\Route\Annotation\Controller; -/** - * @Controller("") - * @View(renderType="") - */ -class extends HttpController + + +class extends HttpController { /** * index - * - * @Action - * @return void */ - public function index() + #[Action] + public function index(): array { return ['success'=>true]; } diff --git a/src/Server/Http/Message/Proxy/RequestProxy.php b/src/Server/Http/Message/Proxy/RequestProxy.php index 3e9ad34e4a..75143d0771 100644 --- a/src/Server/Http/Message/Proxy/RequestProxy.php +++ b/src/Server/Http/Message/Proxy/RequestProxy.php @@ -4,12 +4,9 @@ namespace Imi\Server\Http\Message\Proxy; -use Imi\RequestContextProxy\Annotation\RequestContextProxy; use Imi\RequestContextProxy\BaseRequestContextProxy; /** - * @RequestContextProxy(class="Imi\Server\Http\Message\Contract\IHttpRequest", name="request") - * * @method \Imi\Util\Socket\IPEndPoint getClientAddress() * @method static \Imi\Util\Socket\IPEndPoint getClientAddress() * @method mixed getServerParam(string $name, mixed $default = NULL) @@ -121,6 +118,9 @@ * @method \Psr\Http\Message\UriInterface getAppUri(?string $serverName = NULL) * @method static \Psr\Http\Message\UriInterface getAppUri(?string $serverName = NULL) */ +#[ + \Imi\RequestContextProxy\Annotation\RequestContextProxy(class: \Imi\Server\Http\Message\Contract\IHttpRequest::class, name: 'request') +] class RequestProxy extends BaseRequestContextProxy { } diff --git a/src/Server/Http/Message/Proxy/RequestProxyObject.php b/src/Server/Http/Message/Proxy/RequestProxyObject.php index 44cb7bc6c8..b5a293a8ed 100644 --- a/src/Server/Http/Message/Proxy/RequestProxyObject.php +++ b/src/Server/Http/Message/Proxy/RequestProxyObject.php @@ -4,15 +4,9 @@ namespace Imi\Server\Http\Message\Proxy; -use Imi\Bean\Annotation\Bean; -use Imi\RequestContextProxy\Annotation\RequestContextProxy; use Imi\RequestContextProxy\BaseRequestContextProxy; /** - * @Bean(name="HttpRequestProxy", recursion=false, instanceType="singleton") - * - * @RequestContextProxy(class="Imi\Server\Http\Message\Contract\IHttpRequest", name="request") - * * @method \Imi\Util\Socket\IPEndPoint getClientAddress() * @method static \Imi\Util\Socket\IPEndPoint getClientAddress() * @method mixed getServerParam(string $name, mixed $default = NULL) @@ -124,6 +118,10 @@ * @method \Psr\Http\Message\UriInterface getAppUri(?string $serverName = NULL) * @method static \Psr\Http\Message\UriInterface getAppUri(?string $serverName = NULL) */ +#[ + \Imi\RequestContextProxy\Annotation\RequestContextProxy(class: \Imi\Server\Http\Message\Contract\IHttpRequest::class, name: 'request'), + \Imi\Bean\Annotation\Bean(name: 'HttpRequestProxy', recursion: false) +] class RequestProxyObject extends BaseRequestContextProxy implements \Imi\Server\Http\Message\Contract\IHttpRequest { /** diff --git a/src/Server/Http/Message/Proxy/ResponseProxy.php b/src/Server/Http/Message/Proxy/ResponseProxy.php index b707e4f964..d06765b0a6 100644 --- a/src/Server/Http/Message/Proxy/ResponseProxy.php +++ b/src/Server/Http/Message/Proxy/ResponseProxy.php @@ -4,12 +4,9 @@ namespace Imi\Server\Http\Message\Proxy; -use Imi\RequestContextProxy\Annotation\RequestContextProxy; use Imi\RequestContextProxy\BaseRequestContextProxy; /** - * @RequestContextProxy(class="Imi\Server\Http\Message\Contract\IHttpResponse", name="response") - * * @method \Imi\Server\Http\Message\Contract\IHttpResponse redirect(string $url, int $status = 302) * @method static \Imi\Server\Http\Message\Contract\IHttpResponse redirect(string $url, int $status = 302) * @method \Imi\Server\Http\Message\Contract\IHttpResponse send() @@ -85,6 +82,9 @@ * @method \Imi\Util\Http\Contract\IMessage setBody(\Psr\Http\Message\StreamInterface $body) * @method static \Imi\Util\Http\Contract\IMessage setBody(\Psr\Http\Message\StreamInterface $body) */ +#[ + \Imi\RequestContextProxy\Annotation\RequestContextProxy(class: \Imi\Server\Http\Message\Contract\IHttpResponse::class, name: 'response') +] class ResponseProxy extends BaseRequestContextProxy { } diff --git a/src/Server/Http/Message/Proxy/ResponseProxyObject.php b/src/Server/Http/Message/Proxy/ResponseProxyObject.php index 335287b0af..444b26cbae 100644 --- a/src/Server/Http/Message/Proxy/ResponseProxyObject.php +++ b/src/Server/Http/Message/Proxy/ResponseProxyObject.php @@ -4,15 +4,9 @@ namespace Imi\Server\Http\Message\Proxy; -use Imi\Bean\Annotation\Bean; -use Imi\RequestContextProxy\Annotation\RequestContextProxy; use Imi\RequestContextProxy\BaseRequestContextProxy; /** - * @Bean(name="HttpResponseProxy", recursion=false, instanceType="singleton") - * - * @RequestContextProxy(class="Imi\Server\Http\Message\Contract\IHttpResponse", name="response") - * * @method \Imi\Server\Http\Message\Contract\IHttpResponse redirect(string $url, int $status = 302) * @method static \Imi\Server\Http\Message\Contract\IHttpResponse redirect(string $url, int $status = 302) * @method \Imi\Server\Http\Message\Contract\IHttpResponse send() @@ -88,6 +82,10 @@ * @method \Imi\Util\Http\Contract\IMessage setBody(\Psr\Http\Message\StreamInterface $body) * @method static \Imi\Util\Http\Contract\IMessage setBody(\Psr\Http\Message\StreamInterface $body) */ +#[ + \Imi\RequestContextProxy\Annotation\RequestContextProxy(class: \Imi\Server\Http\Message\Contract\IHttpResponse::class, name: 'response'), + \Imi\Bean\Annotation\Bean(name: 'HttpResponseProxy', recursion: false) +] class ResponseProxyObject extends BaseRequestContextProxy implements \Imi\Server\Http\Message\Contract\IHttpResponse { /** diff --git a/src/Server/Session/Session.php b/src/Server/Session/Session.php index 2ee37a221f..ae6c3ad88a 100644 --- a/src/Server/Session/Session.php +++ b/src/Server/Session/Session.php @@ -4,12 +4,9 @@ namespace Imi\Server\Session; -use Imi\Facade\Annotation\Facade; use Imi\Facade\BaseFacade; /** - * @Facade(class="SessionManager", request=true, args={}) - * * @method static void start(?string $sessionId = NULL) * @method static void close() * @method static void destroy() @@ -31,6 +28,9 @@ * @method static bool isChanged() * @method static bool isNewSession() */ +#[ + \Imi\Facade\Annotation\Facade(class: 'SessionManager', request: true) +] class Session extends BaseFacade { } diff --git a/src/Server/TcpServer/Message/Proxy/ReceiveDataProxy.php b/src/Server/TcpServer/Message/Proxy/ReceiveDataProxy.php index 5fd66304f5..05198957dd 100644 --- a/src/Server/TcpServer/Message/Proxy/ReceiveDataProxy.php +++ b/src/Server/TcpServer/Message/Proxy/ReceiveDataProxy.php @@ -4,15 +4,9 @@ namespace Imi\Server\TcpServer\Message\Proxy; -use Imi\Bean\Annotation\Bean; -use Imi\RequestContextProxy\Annotation\RequestContextProxy; use Imi\RequestContextProxy\BaseRequestContextProxy; /** - * @Bean(name="TcpReceiveDataProxy", recursion=false, instanceType="singleton") - * - * @RequestContextProxy(class="Imi\Server\TcpServer\Message\IReceiveData", name="receiveData") - * * @method int|string getClientId() * @method static int|string getClientId() * @method string getData() @@ -22,6 +16,10 @@ * @method \Imi\Util\Socket\IPEndPoint getClientAddress() * @method static \Imi\Util\Socket\IPEndPoint getClientAddress() */ +#[ + \Imi\RequestContextProxy\Annotation\RequestContextProxy(class: \Imi\Server\TcpServer\Message\IReceiveData::class, name: 'receiveData'), + \Imi\Bean\Annotation\Bean(name: 'TcpReceiveDataProxy', recursion: false) +] class ReceiveDataProxy extends BaseRequestContextProxy implements \Imi\Server\TcpServer\Message\IReceiveData { /** diff --git a/src/Server/UdpServer/Message/Proxy/PacketDataProxy.php b/src/Server/UdpServer/Message/Proxy/PacketDataProxy.php index 659de185bb..18097fc771 100644 --- a/src/Server/UdpServer/Message/Proxy/PacketDataProxy.php +++ b/src/Server/UdpServer/Message/Proxy/PacketDataProxy.php @@ -4,15 +4,9 @@ namespace Imi\Server\UdpServer\Message\Proxy; -use Imi\Bean\Annotation\Bean; -use Imi\RequestContextProxy\Annotation\RequestContextProxy; use Imi\RequestContextProxy\BaseRequestContextProxy; /** - * @Bean(name="UdpPacketDataProxy", recursion=false, instanceType="singleton") - * - * @RequestContextProxy(class="Imi\Server\UdpServer\Message\IPacketData", name="packetData") - * * @method string getData() * @method static string getData() * @method mixed getFormatData() @@ -20,6 +14,10 @@ * @method \Imi\Util\Socket\IPEndPoint getClientAddress() * @method static \Imi\Util\Socket\IPEndPoint getClientAddress() */ +#[ + \Imi\RequestContextProxy\Annotation\RequestContextProxy(class: \Imi\Server\UdpServer\Message\IPacketData::class, name: 'packetData'), + \Imi\Bean\Annotation\Bean(name: 'UdpPacketDataProxy', recursion: false) +] class PacketDataProxy extends BaseRequestContextProxy implements \Imi\Server\UdpServer\Message\IPacketData { /** diff --git a/src/Server/WebSocket/Message/Proxy/FrameProxy.php b/src/Server/WebSocket/Message/Proxy/FrameProxy.php index b4f80ffb92..2db3b62a06 100644 --- a/src/Server/WebSocket/Message/Proxy/FrameProxy.php +++ b/src/Server/WebSocket/Message/Proxy/FrameProxy.php @@ -4,15 +4,9 @@ namespace Imi\Server\WebSocket\Message\Proxy; -use Imi\Bean\Annotation\Bean; -use Imi\RequestContextProxy\Annotation\RequestContextProxy; use Imi\RequestContextProxy\BaseRequestContextProxy; /** - * @Bean(name="WebSocketFrameProxy", recursion=false, instanceType="singleton") - * - * @RequestContextProxy(class="Imi\Server\WebSocket\Message\IFrame", name="frame") - * * @method int|string getClientId() * @method static int|string getClientId() * @method string getData() @@ -26,6 +20,10 @@ * @method \Imi\Util\Socket\IPEndPoint getClientAddress() * @method static \Imi\Util\Socket\IPEndPoint getClientAddress() */ +#[ + \Imi\RequestContextProxy\Annotation\RequestContextProxy(class: \Imi\Server\WebSocket\Message\IFrame::class, name: 'frame'), + \Imi\Bean\Annotation\Bean(name: 'WebSocketFrameProxy', recursion: false) +] class FrameProxy extends BaseRequestContextProxy implements \Imi\Server\WebSocket\Message\IFrame { /** diff --git a/tests/unit/Component/Model/Base/Article2Base.php b/tests/unit/Component/Model/Base/Article2Base.php index ca23eedd6b..3371ac998c 100644 --- a/tests/unit/Component/Model/Base/Article2Base.php +++ b/tests/unit/Component/Model/Base/Article2Base.php @@ -4,20 +4,12 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_article2 基类. * - * @Entity(camel=true, bean=false, incrUpdate=true) - * - * @Table(name="tb_article2", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_article2` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `member_id` int(10) unsigned NOT NULL DEFAULT '0', `title` varchar(255) NOT NULL, `content` mediumtext NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) USING BTREE, KEY `member_id` (`member_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $memberId @@ -25,6 +17,13 @@ * @property string|null $content * @property string|null $time */ +#[ + \Imi\Model\Annotation\Entity(bean: false, incrUpdate: true), + \Imi\Model\Annotation\Table(name: 'tb_article2', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_article2` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `member_id` int(10) unsigned NOT NULL DEFAULT \'0\', `title` varchar(255) NOT NULL, `content` mediumtext NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) USING BTREE, KEY `member_id` (`member_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT') +] abstract class Article2Base extends Model { /** @@ -39,9 +38,10 @@ abstract class Article2Base extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -59,7 +59,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -68,9 +68,10 @@ public function setId($id) /** * member_id. - * - * @Column(name="member_id", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'member_id', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $memberId = 0; /** @@ -88,7 +89,7 @@ public function getMemberId(): ?int * * @return static */ - public function setMemberId($memberId) + public function setMemberId(mixed $memberId): self { $this->memberId = null === $memberId ? null : (int) $memberId; @@ -97,9 +98,10 @@ public function setMemberId($memberId) /** * title. - * - * @Column(name="title", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'title', type: 'varchar', length: 255, nullable: false) + ] protected ?string $title = null; /** @@ -117,7 +119,7 @@ public function getTitle(): ?string * * @return static */ - public function setTitle($title) + public function setTitle(mixed $title): self { if (\is_string($title) && mb_strlen($title) > 255) { @@ -130,9 +132,10 @@ public function setTitle($title) /** * content. - * - * @Column(name="content", type="mediumtext", length=0, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'content', type: 'mediumtext', length: 0, nullable: false) + ] protected ?string $content = null; /** @@ -150,7 +153,7 @@ public function getContent(): ?string * * @return static */ - public function setContent($content) + public function setContent(mixed $content): self { if (\is_string($content) && mb_strlen($content) > 16777215) { @@ -163,9 +166,10 @@ public function setContent($content) /** * time. - * - * @Column(name="time", type="timestamp", length=0, accuracy=0, nullable=false, default="CURRENT_TIMESTAMP", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'time', type: 'timestamp', length: 0, nullable: false, default: 'CURRENT_TIMESTAMP') + ] protected ?string $time = null; /** @@ -183,7 +187,7 @@ public function getTime(): ?string * * @return static */ - public function setTime($time) + public function setTime(mixed $time): self { $this->time = null === $time ? null : (string) $time; diff --git a/tests/unit/Component/Model/Base/ArticleBase.php b/tests/unit/Component/Model/Base/ArticleBase.php index 8c44bc9d26..4b06828fb3 100644 --- a/tests/unit/Component/Model/Base/ArticleBase.php +++ b/tests/unit/Component/Model/Base/ArticleBase.php @@ -4,20 +4,12 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_article 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_article", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_article` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `member_id` int(10) unsigned NOT NULL DEFAULT '0', `title` varchar(255) NOT NULL, `content` mediumtext NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) USING BTREE, KEY `member_id` (`member_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $memberId @@ -25,6 +17,13 @@ * @property string|null $content * @property string|null $time */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_article', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_article` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `member_id` int(10) unsigned NOT NULL DEFAULT \'0\', `title` varchar(255) NOT NULL, `content` mediumtext NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) USING BTREE, KEY `member_id` (`member_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT') +] abstract class ArticleBase extends Model { /** @@ -39,9 +38,10 @@ abstract class ArticleBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -59,7 +59,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -68,9 +68,10 @@ public function setId($id) /** * member_id. - * - * @Column(name="member_id", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'member_id', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $memberId = 0; /** @@ -88,7 +89,7 @@ public function getMemberId(): ?int * * @return static */ - public function setMemberId($memberId) + public function setMemberId(mixed $memberId): self { $this->memberId = null === $memberId ? null : (int) $memberId; @@ -97,9 +98,10 @@ public function setMemberId($memberId) /** * title. - * - * @Column(name="title", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'title', type: 'varchar', length: 255, nullable: false) + ] protected ?string $title = null; /** @@ -117,7 +119,7 @@ public function getTitle(): ?string * * @return static */ - public function setTitle($title) + public function setTitle(mixed $title): self { if (\is_string($title) && mb_strlen($title) > 255) { @@ -130,9 +132,10 @@ public function setTitle($title) /** * content. - * - * @Column(name="content", type="mediumtext", length=0, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'content', type: 'mediumtext', length: 0, nullable: false) + ] protected ?string $content = null; /** @@ -150,7 +153,7 @@ public function getContent(): ?string * * @return static */ - public function setContent($content) + public function setContent(mixed $content): self { if (\is_string($content) && mb_strlen($content) > 16777215) { @@ -163,9 +166,10 @@ public function setContent($content) /** * time. - * - * @Column(name="time", type="timestamp", length=0, accuracy=0, nullable=false, default="CURRENT_TIMESTAMP", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'time', type: 'timestamp', length: 0, nullable: false, default: 'CURRENT_TIMESTAMP') + ] protected ?string $time = null; /** @@ -183,7 +187,7 @@ public function getTime(): ?string * * @return static */ - public function setTime($time) + public function setTime(mixed $time): self { $this->time = null === $time ? null : (string) $time; diff --git a/tests/unit/Component/Model/Base/ArticleExBase.php b/tests/unit/Component/Model/Base/ArticleExBase.php index 2d9524bf5d..dcdb237b0f 100644 --- a/tests/unit/Component/Model/Base/ArticleExBase.php +++ b/tests/unit/Component/Model/Base/ArticleExBase.php @@ -4,24 +4,23 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_article_ex 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_article_ex", usePrefix=false, id={"article_id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_article_ex` ( `article_id` int(10) unsigned NOT NULL, `data` json DEFAULT NULL, PRIMARY KEY (`article_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $articleId * @property \Imi\Util\LazyArrayObject|object|array|null $data */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_article_ex', id: [ + 'article_id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_article_ex` ( `article_id` int(10) unsigned NOT NULL, `data` json DEFAULT NULL, PRIMARY KEY (`article_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8') +] abstract class ArticleExBase extends Model { /** @@ -36,9 +35,10 @@ abstract class ArticleExBase extends Model /** * article_id. - * - * @Column(name="article_id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'article_id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, unsigned: true) + ] protected ?int $articleId = null; /** @@ -56,7 +56,7 @@ public function getArticleId(): ?int * * @return static */ - public function setArticleId($articleId) + public function setArticleId(mixed $articleId): self { $this->articleId = null === $articleId ? null : (int) $articleId; @@ -66,10 +66,11 @@ public function setArticleId($articleId) /** * data. * - * @Column(name="data", type="json", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) - * * @var \Imi\Util\LazyArrayObject|object|array|null */ + #[ + \Imi\Model\Annotation\Column(name: 'data', type: 'json', length: 0) + ] protected $data = null; /** @@ -89,7 +90,7 @@ public function &getData() * * @return static */ - public function setData($data) + public function setData(mixed $data): self { $this->data = null === $data ? null : $data; diff --git a/tests/unit/Component/Model/Base/CreateTimeBase.php b/tests/unit/Component/Model/Base/CreateTimeBase.php index 789f3f4a63..c37432fc44 100644 --- a/tests/unit/Component/Model/Base/CreateTimeBase.php +++ b/tests/unit/Component/Model/Base/CreateTimeBase.php @@ -4,20 +4,12 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_create_time 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_create_time", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_create_time` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date` date DEFAULT NULL, `time` time DEFAULT NULL, `datetime` datetime DEFAULT NULL, `timestamp` timestamp NULL DEFAULT NULL, `int` int(11) DEFAULT NULL, `bigint` bigint(20) DEFAULT NULL, `bigint_second` bigint(20) DEFAULT NULL, `year` year(4) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $date @@ -29,6 +21,13 @@ * @property int|null $bigintSecond * @property int|null $year */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_create_time', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_create_time` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date` date DEFAULT NULL, `time` time DEFAULT NULL, `datetime` datetime DEFAULT NULL, `timestamp` timestamp NULL DEFAULT NULL, `int` int(11) DEFAULT NULL, `bigint` bigint(20) DEFAULT NULL, `bigint_second` bigint(20) DEFAULT NULL, `year` year(4) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT') +] abstract class CreateTimeBase extends Model { /** @@ -43,9 +42,10 @@ abstract class CreateTimeBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -63,7 +63,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -72,9 +72,10 @@ public function setId($id) /** * date. - * - * @Column(name="date", type="date", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'date', type: 'date', length: 0) + ] protected ?string $date = null; /** @@ -92,7 +93,7 @@ public function getDate(): ?string * * @return static */ - public function setDate($date) + public function setDate(mixed $date): self { $this->date = null === $date ? null : (string) $date; @@ -101,9 +102,10 @@ public function setDate($date) /** * time. - * - * @Column(name="time", type="time", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'time', type: 'time', length: 0) + ] protected ?string $time = null; /** @@ -121,7 +123,7 @@ public function getTime(): ?string * * @return static */ - public function setTime($time) + public function setTime(mixed $time): self { $this->time = null === $time ? null : (string) $time; @@ -130,9 +132,10 @@ public function setTime($time) /** * datetime. - * - * @Column(name="datetime", type="datetime", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'datetime', type: 'datetime', length: 0) + ] protected ?string $datetime = null; /** @@ -150,7 +153,7 @@ public function getDatetime(): ?string * * @return static */ - public function setDatetime($datetime) + public function setDatetime(mixed $datetime): self { $this->datetime = null === $datetime ? null : (string) $datetime; @@ -159,9 +162,10 @@ public function setDatetime($datetime) /** * timestamp. - * - * @Column(name="timestamp", type="timestamp", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'timestamp', type: 'timestamp', length: 0) + ] protected ?string $timestamp = null; /** @@ -179,7 +183,7 @@ public function getTimestamp(): ?string * * @return static */ - public function setTimestamp($timestamp) + public function setTimestamp(mixed $timestamp): self { $this->timestamp = null === $timestamp ? null : (string) $timestamp; @@ -188,9 +192,10 @@ public function setTimestamp($timestamp) /** * int. - * - * @Column(name="int", type="int", length=11, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'int', type: 'int', length: 11) + ] protected ?int $int = null; /** @@ -208,7 +213,7 @@ public function getInt(): ?int * * @return static */ - public function setInt($int) + public function setInt(mixed $int): self { $this->int = null === $int ? null : (int) $int; @@ -217,9 +222,10 @@ public function setInt($int) /** * bigint. - * - * @Column(name="bigint", type="bigint", length=20, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'bigint', type: 'bigint', length: 20) + ] protected ?int $bigint = null; /** @@ -237,7 +243,7 @@ public function getBigint(): ?int * * @return static */ - public function setBigint($bigint) + public function setBigint(mixed $bigint): self { $this->bigint = null === $bigint ? null : (int) $bigint; @@ -246,9 +252,10 @@ public function setBigint($bigint) /** * bigint_second. - * - * @Column(name="bigint_second", type="bigint", length=20, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'bigint_second', type: 'bigint', length: 20) + ] protected ?int $bigintSecond = null; /** @@ -266,7 +273,7 @@ public function getBigintSecond(): ?int * * @return static */ - public function setBigintSecond($bigintSecond) + public function setBigintSecond(mixed $bigintSecond): self { $this->bigintSecond = null === $bigintSecond ? null : (int) $bigintSecond; @@ -275,9 +282,10 @@ public function setBigintSecond($bigintSecond) /** * year. - * - * @Column(name="year", type="year", length=4, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'year', type: 'year', length: 4) + ] protected ?int $year = null; /** @@ -295,7 +303,7 @@ public function getYear(): ?int * * @return static */ - public function setYear($year) + public function setYear(mixed $year): self { $this->year = null === $year ? null : (int) $year; diff --git a/tests/unit/Component/Model/Base/MemberBase.php b/tests/unit/Component/Model/Base/MemberBase.php index 103b85d108..a3f3b168b1 100644 --- a/tests/unit/Component/Model/Base/MemberBase.php +++ b/tests/unit/Component/Model/Base/MemberBase.php @@ -4,25 +4,24 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_member 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_member", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_member` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(32) NOT NULL COMMENT '用户名', `password` varchar(255) NOT NULL COMMENT '密码', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $username 用户名 * @property string|null $password 密码 */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_member', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_member` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(32) NOT NULL COMMENT \'用户名\', `password` varchar(255) NOT NULL COMMENT \'密码\', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT') +] abstract class MemberBase extends Model { /** @@ -37,9 +36,10 @@ abstract class MemberBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -57,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -67,9 +67,10 @@ public function setId($id) /** * 用户名. * username. - * - * @Column(name="username", type="varchar", length=32, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'username', type: 'varchar', length: 32, nullable: false) + ] protected ?string $username = null; /** @@ -87,7 +88,7 @@ public function getUsername(): ?string * * @return static */ - public function setUsername($username) + public function setUsername(mixed $username): self { if (\is_string($username) && mb_strlen($username) > 32) { @@ -101,9 +102,10 @@ public function setUsername($username) /** * 密码. * password. - * - * @Column(name="password", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'password', type: 'varchar', length: 255, nullable: false) + ] protected ?string $password = null; /** @@ -121,7 +123,7 @@ public function getPassword(): ?string * * @return static */ - public function setPassword($password) + public function setPassword(mixed $password): self { if (\is_string($password) && mb_strlen($password) > 255) { diff --git a/tests/unit/Component/Model/Base/MemberRoleRelationBase.php b/tests/unit/Component/Model/Base/MemberRoleRelationBase.php index 34be4cf9b7..9dc60dae99 100644 --- a/tests/unit/Component/Model/Base/MemberRoleRelationBase.php +++ b/tests/unit/Component/Model/Base/MemberRoleRelationBase.php @@ -4,26 +4,25 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_member_role_relation 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_member_role_relation", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_member_role_relation` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `type` int(10) unsigned NOT NULL DEFAULT '0', `member_id` int(10) unsigned NOT NULL, `role_id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `member_id` (`member_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $type * @property int|null $memberId * @property int|null $roleId */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_member_role_relation', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_member_role_relation` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `type` int(10) unsigned NOT NULL DEFAULT \'0\', `member_id` int(10) unsigned NOT NULL, `role_id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `member_id` (`member_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8') +] abstract class MemberRoleRelationBase extends Model { /** @@ -38,9 +37,10 @@ abstract class MemberRoleRelationBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -58,7 +58,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -67,9 +67,10 @@ public function setId($id) /** * type. - * - * @Column(name="type", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'type', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $type = 0; /** @@ -87,7 +88,7 @@ public function getType(): ?int * * @return static */ - public function setType($type) + public function setType(mixed $type): self { $this->type = null === $type ? null : (int) $type; @@ -96,9 +97,10 @@ public function setType($type) /** * member_id. - * - * @Column(name="member_id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'member_id', type: 'int', length: 10, nullable: false, unsigned: true) + ] protected ?int $memberId = null; /** @@ -116,7 +118,7 @@ public function getMemberId(): ?int * * @return static */ - public function setMemberId($memberId) + public function setMemberId(mixed $memberId): self { $this->memberId = null === $memberId ? null : (int) $memberId; @@ -125,9 +127,10 @@ public function setMemberId($memberId) /** * role_id. - * - * @Column(name="role_id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'role_id', type: 'int', length: 10, nullable: false, unsigned: true) + ] protected ?int $roleId = null; /** @@ -145,7 +148,7 @@ public function getRoleId(): ?int * * @return static */ - public function setRoleId($roleId) + public function setRoleId(mixed $roleId): self { $this->roleId = null === $roleId ? null : (int) $roleId; diff --git a/tests/unit/Component/Model/Base/NoIncPkBase.php b/tests/unit/Component/Model/Base/NoIncPkBase.php index 334be6ba03..97289f84bc 100644 --- a/tests/unit/Component/Model/Base/NoIncPkBase.php +++ b/tests/unit/Component/Model/Base/NoIncPkBase.php @@ -4,25 +4,25 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_no_inc_pk 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_no_inc_pk", usePrefix=false, id={"a_id", "b_id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_no_inc_pk` ( `a_id` int(10) unsigned NOT NULL, `b_id` int(10) unsigned NOT NULL, `value` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`a_id`,`b_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $aId * @property int|null $bId * @property string|null $value */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_no_inc_pk', id: [ + 'a_id', + 'b_id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_no_inc_pk` ( `a_id` int(10) unsigned NOT NULL, `b_id` int(10) unsigned NOT NULL, `value` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`a_id`,`b_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci') +] abstract class NoIncPkBase extends Model { /** @@ -37,9 +37,10 @@ abstract class NoIncPkBase extends Model /** * a_id. - * - * @Column(name="a_id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'a_id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, unsigned: true) + ] protected ?int $aId = null; /** @@ -57,7 +58,7 @@ public function getAId(): ?int * * @return static */ - public function setAId($aId) + public function setAId(mixed $aId): self { $this->aId = null === $aId ? null : (int) $aId; @@ -66,9 +67,10 @@ public function setAId($aId) /** * b_id. - * - * @Column(name="b_id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'b_id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 1, unsigned: true) + ] protected ?int $bId = null; /** @@ -86,7 +88,7 @@ public function getBId(): ?int * * @return static */ - public function setBId($bId) + public function setBId(mixed $bId): self { $this->bId = null === $bId ? null : (int) $bId; @@ -95,9 +97,10 @@ public function setBId($bId) /** * value. - * - * @Column(name="value", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'value', type: 'varchar', length: 255, nullable: false) + ] protected ?string $value = null; /** @@ -115,7 +118,7 @@ public function getValue(): ?string * * @return static */ - public function setValue($value) + public function setValue(mixed $value): self { if (\is_string($value) && mb_strlen($value) > 255) { diff --git a/tests/unit/Component/Model/Base/PerformanceBase.php b/tests/unit/Component/Model/Base/PerformanceBase.php index a68ad9f0db..f90da03fe2 100644 --- a/tests/unit/Component/Model/Base/PerformanceBase.php +++ b/tests/unit/Component/Model/Base/PerformanceBase.php @@ -4,24 +4,23 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_performance 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_performance", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_performance` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `value` varchar(255) NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $value */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_performance', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_performance` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `value` varchar(255) NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT') +] abstract class PerformanceBase extends Model { /** @@ -36,9 +35,10 @@ abstract class PerformanceBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -56,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -65,9 +65,10 @@ public function setId($id) /** * value. - * - * @Column(name="value", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'value', type: 'varchar', length: 255, nullable: false) + ] protected ?string $value = null; /** @@ -85,7 +86,7 @@ public function getValue(): ?string * * @return static */ - public function setValue($value) + public function setValue(mixed $value): self { if (\is_string($value) && mb_strlen($value) > 255) { diff --git a/tests/unit/Component/Model/Base/PolymorphicBase.php b/tests/unit/Component/Model/Base/PolymorphicBase.php index 400dc38195..9024d67c27 100644 --- a/tests/unit/Component/Model/Base/PolymorphicBase.php +++ b/tests/unit/Component/Model/Base/PolymorphicBase.php @@ -4,20 +4,12 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_polymorphic 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_polymorphic", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_polymorphic` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `type` int(10) unsigned NOT NULL, `to_one` int(10) unsigned NOT NULL DEFAULT '0', `to_many` int(10) unsigned NOT NULL DEFAULT '0', `one_to_one` int(10) unsigned NOT NULL DEFAULT '0', `one_to_many` int(10) unsigned NOT NULL DEFAULT '0', `many_to_many` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $type @@ -27,6 +19,13 @@ * @property int|null $oneToMany * @property int|null $manyToMany */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_polymorphic', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_polymorphic` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `type` int(10) unsigned NOT NULL, `to_one` int(10) unsigned NOT NULL DEFAULT \'0\', `to_many` int(10) unsigned NOT NULL DEFAULT \'0\', `one_to_one` int(10) unsigned NOT NULL DEFAULT \'0\', `one_to_many` int(10) unsigned NOT NULL DEFAULT \'0\', `many_to_many` int(10) unsigned NOT NULL DEFAULT \'0\', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8') +] abstract class PolymorphicBase extends Model { /** @@ -41,9 +40,10 @@ abstract class PolymorphicBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -61,7 +61,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -70,9 +70,10 @@ public function setId($id) /** * type. - * - * @Column(name="type", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'type', type: 'int', length: 10, nullable: false, unsigned: true) + ] protected ?int $type = null; /** @@ -90,7 +91,7 @@ public function getType(): ?int * * @return static */ - public function setType($type) + public function setType(mixed $type): self { $this->type = null === $type ? null : (int) $type; @@ -99,9 +100,10 @@ public function setType($type) /** * to_one. - * - * @Column(name="to_one", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'to_one', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $toOne = 0; /** @@ -119,7 +121,7 @@ public function getToOne(): ?int * * @return static */ - public function setToOne($toOne) + public function setToOne(mixed $toOne): self { $this->toOne = null === $toOne ? null : (int) $toOne; @@ -128,9 +130,10 @@ public function setToOne($toOne) /** * to_many. - * - * @Column(name="to_many", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'to_many', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $toMany = 0; /** @@ -148,7 +151,7 @@ public function getToMany(): ?int * * @return static */ - public function setToMany($toMany) + public function setToMany(mixed $toMany): self { $this->toMany = null === $toMany ? null : (int) $toMany; @@ -157,9 +160,10 @@ public function setToMany($toMany) /** * one_to_one. - * - * @Column(name="one_to_one", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'one_to_one', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $oneToOne = 0; /** @@ -177,7 +181,7 @@ public function getOneToOne(): ?int * * @return static */ - public function setOneToOne($oneToOne) + public function setOneToOne(mixed $oneToOne): self { $this->oneToOne = null === $oneToOne ? null : (int) $oneToOne; @@ -186,9 +190,10 @@ public function setOneToOne($oneToOne) /** * one_to_many. - * - * @Column(name="one_to_many", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'one_to_many', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $oneToMany = 0; /** @@ -206,7 +211,7 @@ public function getOneToMany(): ?int * * @return static */ - public function setOneToMany($oneToMany) + public function setOneToMany(mixed $oneToMany): self { $this->oneToMany = null === $oneToMany ? null : (int) $oneToMany; @@ -215,9 +220,10 @@ public function setOneToMany($oneToMany) /** * many_to_many. - * - * @Column(name="many_to_many", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'many_to_many', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $manyToMany = 0; /** @@ -235,7 +241,7 @@ public function getManyToMany(): ?int * * @return static */ - public function setManyToMany($manyToMany) + public function setManyToMany(mixed $manyToMany): self { $this->manyToMany = null === $manyToMany ? null : (int) $manyToMany; diff --git a/tests/unit/Component/Model/Base/PrefixBase.php b/tests/unit/Component/Model/Base/PrefixBase.php index d879573a5f..bd286f168d 100644 --- a/tests/unit/Component/Model/Base/PrefixBase.php +++ b/tests/unit/Component/Model/Base/PrefixBase.php @@ -4,25 +4,24 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * prefix 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="prefix", usePrefix=true, id={"id"}, dbPoolName="dbPrefix") - * - * @DDL(sql="CREATE TABLE `tb_prefix` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `delete_time` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $name * @property int|null $deleteTime */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'prefix', dbPoolName: 'dbPrefix', id: [ + 'id', + ], usePrefix: true), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_prefix` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `delete_time` int(10) unsigned NOT NULL DEFAULT \'0\', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1') +] abstract class PrefixBase extends Model { /** @@ -37,9 +36,10 @@ abstract class PrefixBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -57,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -66,9 +66,10 @@ public function setId($id) /** * name. - * - * @Column(name="name", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'name', type: 'varchar', length: 255, nullable: false) + ] protected ?string $name = null; /** @@ -86,7 +87,7 @@ public function getName(): ?string * * @return static */ - public function setName($name) + public function setName(mixed $name): self { if (\is_string($name) && mb_strlen($name) > 255) { @@ -99,9 +100,10 @@ public function setName($name) /** * delete_time. - * - * @Column(name="delete_time", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'delete_time', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $deleteTime = 0; /** @@ -119,7 +121,7 @@ public function getDeleteTime(): ?int * * @return static */ - public function setDeleteTime($deleteTime) + public function setDeleteTime(mixed $deleteTime): self { $this->deleteTime = null === $deleteTime ? null : (int) $deleteTime; diff --git a/tests/unit/Component/Model/Base/RoleBase.php b/tests/unit/Component/Model/Base/RoleBase.php index fb2f8cb3ef..bda234a7ea 100644 --- a/tests/unit/Component/Model/Base/RoleBase.php +++ b/tests/unit/Component/Model/Base/RoleBase.php @@ -4,24 +4,23 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_role 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_role", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_role` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; insert into `tb_role` values(1,'a'); insert into `tb_role` values(2,'b'); insert into `tb_role` values(3,'c'); insert into `tb_role` values(4,'d'); insert into `tb_role` values(5,'e'); ") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $name */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_role', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_role` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; insert into `tb_role` values(1,\'a\'); insert into `tb_role` values(2,\'b\'); insert into `tb_role` values(3,\'c\'); insert into `tb_role` values(4,\'d\'); insert into `tb_role` values(5,\'e\'); ') +] abstract class RoleBase extends Model { /** @@ -36,9 +35,10 @@ abstract class RoleBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -56,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -65,9 +65,10 @@ public function setId($id) /** * name. - * - * @Column(name="name", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'name', type: 'varchar', length: 255, nullable: false) + ] protected ?string $name = null; /** @@ -85,7 +86,7 @@ public function getName(): ?string * * @return static */ - public function setName($name) + public function setName(mixed $name): self { if (\is_string($name) && mb_strlen($name) > 255) { diff --git a/tests/unit/Component/Model/Base/TestEnumBase.php b/tests/unit/Component/Model/Base/TestEnumBase.php index 4271de7f1f..7843e8eba0 100644 --- a/tests/unit/Component/Model/Base/TestEnumBase.php +++ b/tests/unit/Component/Model/Base/TestEnumBase.php @@ -4,25 +4,24 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_test_enum 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_enum", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_test_enum` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `value1` enum('a','b','c','''test''') NOT NULL DEFAULT '''test''', `value2` enum('1','2','3') NOT NULL DEFAULT '1', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $value1 * @property string|null $value2 */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_enum', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_test_enum` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `value1` enum(\'a\',\'b\',\'c\',\'\'\'test\'\'\') NOT NULL DEFAULT \'\'\'test\'\'\', `value2` enum(\'1\',\'2\',\'3\') NOT NULL DEFAULT \'1\', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8') +] abstract class TestEnumBase extends Model { /** @@ -37,9 +36,10 @@ abstract class TestEnumBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -57,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -66,9 +66,10 @@ public function setId($id) /** * value1. - * - * @Column(name="value1", type="enum", length=0, accuracy=0, nullable=false, default="'test'", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'value1', type: 'enum', length: 0, nullable: false, default: '\'test\'') + ] protected ?string $value1 = '\'test\''; /** @@ -86,7 +87,7 @@ public function getValue1(): ?string * * @return static */ - public function setValue1($value1) + public function setValue1(mixed $value1): self { $this->value1 = null === $value1 ? null : (string) $value1; @@ -95,9 +96,10 @@ public function setValue1($value1) /** * value2. - * - * @Column(name="value2", type="enum", length=0, accuracy=0, nullable=false, default="1", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'value2', type: 'enum', length: 0, nullable: false, default: '1') + ] protected ?string $value2 = '1'; /** @@ -115,7 +117,7 @@ public function getValue2(): ?string * * @return static */ - public function setValue2($value2) + public function setValue2(mixed $value2): self { $this->value2 = null === $value2 ? null : (string) $value2; diff --git a/tests/unit/Component/Model/Base/TestFieldNameBase.php b/tests/unit/Component/Model/Base/TestFieldNameBase.php index 71a3ade22d..130b401c2d 100644 --- a/tests/unit/Component/Model/Base/TestFieldNameBase.php +++ b/tests/unit/Component/Model/Base/TestFieldNameBase.php @@ -4,25 +4,24 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_test_field_name 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_field_name", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_test_field_name` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Abc_Def` varchar(255) NOT NULL, `ABC_XYZ` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $abcDef * @property string|null $aBCXYZ */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_field_name', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_test_field_name` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Abc_Def` varchar(255) NOT NULL, `ABC_XYZ` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1') +] abstract class TestFieldNameBase extends Model { /** @@ -37,9 +36,10 @@ abstract class TestFieldNameBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -57,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -66,9 +66,10 @@ public function setId($id) /** * Abc_Def. - * - * @Column(name="Abc_Def", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'Abc_Def', type: 'varchar', length: 255, nullable: false) + ] protected ?string $abcDef = null; /** @@ -86,7 +87,7 @@ public function getAbcDef(): ?string * * @return static */ - public function setAbcDef($abcDef) + public function setAbcDef(mixed $abcDef): self { if (\is_string($abcDef) && mb_strlen($abcDef) > 255) { @@ -99,9 +100,10 @@ public function setAbcDef($abcDef) /** * ABC_XYZ. - * - * @Column(name="ABC_XYZ", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'ABC_XYZ', type: 'varchar', length: 255, nullable: false) + ] protected ?string $aBCXYZ = null; /** @@ -119,7 +121,7 @@ public function getABCXYZ(): ?string * * @return static */ - public function setABCXYZ($aBCXYZ) + public function setABCXYZ(mixed $aBCXYZ): self { if (\is_string($aBCXYZ) && mb_strlen($aBCXYZ) > 255) { diff --git a/tests/unit/Component/Model/Base/TestJsonBase.php b/tests/unit/Component/Model/Base/TestJsonBase.php index 8cdcb64144..3921208fb2 100644 --- a/tests/unit/Component/Model/Base/TestJsonBase.php +++ b/tests/unit/Component/Model/Base/TestJsonBase.php @@ -4,24 +4,23 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * test 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_json", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_test_json` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `json_data` json NOT NULL COMMENT 'json数据', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='test'") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property \Imi\Util\LazyArrayObject|object|array|null $jsonData json数据 */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_json', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_test_json` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `json_data` json NOT NULL COMMENT \'json数据\', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'test\'') +] abstract class TestJsonBase extends Model { /** @@ -36,9 +35,10 @@ abstract class TestJsonBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -56,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -67,10 +67,11 @@ public function setId($id) * json数据. * json_data. * - * @Column(name="json_data", type="json", length=0, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) - * * @var \Imi\Util\LazyArrayObject|object|array|null */ + #[ + \Imi\Model\Annotation\Column(name: 'json_data', type: 'json', length: 0, nullable: false) + ] protected $jsonData = null; /** @@ -90,7 +91,7 @@ public function &getJsonData() * * @return static */ - public function setJsonData($jsonData) + public function setJsonData(mixed $jsonData): self { $this->jsonData = null === $jsonData ? null : $jsonData; diff --git a/tests/unit/Component/Model/Base/TestListBase.php b/tests/unit/Component/Model/Base/TestListBase.php index 9541283778..9e5b22d3bd 100644 --- a/tests/unit/Component/Model/Base/TestListBase.php +++ b/tests/unit/Component/Model/Base/TestListBase.php @@ -4,24 +4,23 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_test_list 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_list", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_test_list` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `list` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $list */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_list', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_test_list` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `list` varchar(255) NOT NULL DEFAULT \'\', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8') +] abstract class TestListBase extends Model { /** @@ -36,9 +35,10 @@ abstract class TestListBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -56,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -66,10 +66,11 @@ public function setId($id) /** * list. * - * @Column(name="list", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) - * * @var string|null */ + #[ + \Imi\Model\Annotation\Column(name: 'list', type: 'varchar', length: 255, nullable: false, default: '') + ] protected $list = ''; /** @@ -89,7 +90,7 @@ public function getList() * * @return static */ - public function setList($list) + public function setList(mixed $list): self { if (\is_string($list) && mb_strlen($list) > 255) { diff --git a/tests/unit/Component/Model/Base/TestSetBase.php b/tests/unit/Component/Model/Base/TestSetBase.php index a4d74bb03b..b343d0f479 100644 --- a/tests/unit/Component/Model/Base/TestSetBase.php +++ b/tests/unit/Component/Model/Base/TestSetBase.php @@ -4,25 +4,24 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_test_set 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_set", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_test_set` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `value1` set('a','b','c','''test''') NOT NULL DEFAULT '''test''', `value2` set('1','2','3') NOT NULL DEFAULT '1,2', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property array|null $value1 * @property array|null $value2 */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_set', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_test_set` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `value1` set(\'a\',\'b\',\'c\',\'\'\'test\'\'\') NOT NULL DEFAULT \'\'\'test\'\'\', `value2` set(\'1\',\'2\',\'3\') NOT NULL DEFAULT \'1,2\', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8') +] abstract class TestSetBase extends Model { /** @@ -37,9 +36,10 @@ abstract class TestSetBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -57,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -66,9 +66,10 @@ public function setId($id) /** * value1. - * - * @Column(name="value1", type="set", length=0, accuracy=0, nullable=false, default="'test'", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'value1', type: 'set', length: 0, nullable: false, default: '\'test\'') + ] protected ?array $value1 = [ 0 => '\'test\'', ]; @@ -88,7 +89,7 @@ public function getValue1(): ?array * * @return static */ - public function setValue1($value1) + public function setValue1(mixed $value1): self { $this->value1 = null === $value1 ? null : $value1; @@ -97,9 +98,10 @@ public function setValue1($value1) /** * value2. - * - * @Column(name="value2", type="set", length=0, accuracy=0, nullable=false, default="1,2", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'value2', type: 'set', length: 0, nullable: false, default: '1,2') + ] protected ?array $value2 = [ 0 => '1', 1 => '2', @@ -120,7 +122,7 @@ public function getValue2(): ?array * * @return static */ - public function setValue2($value2) + public function setValue2(mixed $value2): self { $this->value2 = null === $value2 ? null : $value2; diff --git a/tests/unit/Component/Model/Base/TestSoftDeleteBase.php b/tests/unit/Component/Model/Base/TestSoftDeleteBase.php index 9449925e7e..e5be24443d 100644 --- a/tests/unit/Component/Model/Base/TestSoftDeleteBase.php +++ b/tests/unit/Component/Model/Base/TestSoftDeleteBase.php @@ -4,25 +4,24 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_test_soft_delete 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_soft_delete", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_test_soft_delete` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `delete_time` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $title * @property int|null $deleteTime */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_soft_delete', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_test_soft_delete` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `delete_time` int(10) unsigned NOT NULL DEFAULT \'0\', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8') +] abstract class TestSoftDeleteBase extends Model { /** @@ -37,9 +36,10 @@ abstract class TestSoftDeleteBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -57,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -66,9 +66,10 @@ public function setId($id) /** * title. - * - * @Column(name="title", type="varchar", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'title', type: 'varchar', length: 255, nullable: false) + ] protected ?string $title = null; /** @@ -86,7 +87,7 @@ public function getTitle(): ?string * * @return static */ - public function setTitle($title) + public function setTitle(mixed $title): self { if (\is_string($title) && mb_strlen($title) > 255) { @@ -99,9 +100,10 @@ public function setTitle($title) /** * delete_time. - * - * @Column(name="delete_time", type="int", length=10, accuracy=0, nullable=false, default="0", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'delete_time', type: 'int', length: 10, nullable: false, default: '0', unsigned: true) + ] protected ?int $deleteTime = 0; /** @@ -119,7 +121,7 @@ public function getDeleteTime(): ?int * * @return static */ - public function setDeleteTime($deleteTime) + public function setDeleteTime(mixed $deleteTime): self { $this->deleteTime = null === $deleteTime ? null : (int) $deleteTime; diff --git a/tests/unit/Component/Model/Base/TestWithMemberBase.php b/tests/unit/Component/Model/Base/TestWithMemberBase.php index f15b049aaf..6c5ae22174 100644 --- a/tests/unit/Component/Model/Base/TestWithMemberBase.php +++ b/tests/unit/Component/Model/Base/TestWithMemberBase.php @@ -4,24 +4,23 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * 测试 with member 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_test_with_member", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_test_with_member` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `member_id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='测试 with member'") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $memberId */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_test_with_member', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_test_with_member` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `member_id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT=\'测试 with member\'') +] abstract class TestWithMemberBase extends Model { /** @@ -36,9 +35,10 @@ abstract class TestWithMemberBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -56,7 +56,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -65,9 +65,10 @@ public function setId($id) /** * member_id. - * - * @Column(name="member_id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'member_id', type: 'int', length: 10, nullable: false, unsigned: true) + ] protected ?int $memberId = null; /** @@ -85,7 +86,7 @@ public function getMemberId(): ?int * * @return static */ - public function setMemberId($memberId) + public function setMemberId(mixed $memberId): self { $this->memberId = null === $memberId ? null : (int) $memberId; diff --git a/tests/unit/Component/Model/Base/TreeBase.php b/tests/unit/Component/Model/Base/TreeBase.php index 91e3375a86..6181b2ca03 100644 --- a/tests/unit/Component/Model/Base/TreeBase.php +++ b/tests/unit/Component/Model/Base/TreeBase.php @@ -4,25 +4,24 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_tree 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_tree", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_tree` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parent_id` int(10) unsigned NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; insert into `tb_tree` values(1,0,'a'); insert into `tb_tree` values(2,0,'b'); insert into `tb_tree` values(3,0,'c'); insert into `tb_tree` values(4,1,'a-1'); insert into `tb_tree` values(5,1,'a-2'); insert into `tb_tree` values(6,4,'a-1-1'); insert into `tb_tree` values(7,4,'a-1-2'); insert into `tb_tree` values(8,2,'b-1'); insert into `tb_tree` values(9,2,'b-2'); ") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $parentId * @property string|null $name */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_tree', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_tree` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parent_id` int(10) unsigned NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; insert into `tb_tree` values(1,0,\'a\'); insert into `tb_tree` values(2,0,\'b\'); insert into `tb_tree` values(3,0,\'c\'); insert into `tb_tree` values(4,1,\'a-1\'); insert into `tb_tree` values(5,1,\'a-2\'); insert into `tb_tree` values(6,4,\'a-1-1\'); insert into `tb_tree` values(7,4,\'a-1-2\'); insert into `tb_tree` values(8,2,\'b-1\'); insert into `tb_tree` values(9,2,\'b-2\'); ') +] abstract class TreeBase extends Model { /** @@ -37,9 +36,10 @@ abstract class TreeBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -57,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -66,9 +66,10 @@ public function setId($id) /** * parent_id. - * - * @Column(name="parent_id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'parent_id', type: 'int', length: 10, nullable: false, unsigned: true) + ] protected ?int $parentId = null; /** @@ -86,7 +87,7 @@ public function getParentId(): ?int * * @return static */ - public function setParentId($parentId) + public function setParentId(mixed $parentId): self { $this->parentId = null === $parentId ? null : (int) $parentId; @@ -95,9 +96,10 @@ public function setParentId($parentId) /** * name. - * - * @Column(name="name", type="varchar", length=32, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'name', type: 'varchar', length: 32, nullable: false) + ] protected ?string $name = null; /** @@ -115,7 +117,7 @@ public function getName(): ?string * * @return static */ - public function setName($name) + public function setName(mixed $name): self { if (\is_string($name) && mb_strlen($name) > 32) { diff --git a/tests/unit/Component/Model/Base/UnusedBase.php b/tests/unit/Component/Model/Base/UnusedBase.php index 8fe28b5b26..0e798e3d55 100644 --- a/tests/unit/Component/Model/Base/UnusedBase.php +++ b/tests/unit/Component/Model/Base/UnusedBase.php @@ -4,23 +4,22 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_unused 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_unused", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_unused` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_unused', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_unused` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8') +] abstract class UnusedBase extends Model { /** @@ -35,9 +34,10 @@ abstract class UnusedBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -55,7 +55,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; diff --git a/tests/unit/Component/Model/Base/UpdateTimeBase.php b/tests/unit/Component/Model/Base/UpdateTimeBase.php index 748dddb864..1916c8211d 100644 --- a/tests/unit/Component/Model/Base/UpdateTimeBase.php +++ b/tests/unit/Component/Model/Base/UpdateTimeBase.php @@ -4,20 +4,12 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_update_time 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_update_time", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_update_time` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date` date DEFAULT NULL, `time` time DEFAULT NULL, `datetime` datetime DEFAULT NULL, `timestamp` timestamp NULL DEFAULT NULL, `int` int(11) DEFAULT NULL, `bigint` bigint(20) DEFAULT NULL, `bigint_second` bigint(20) DEFAULT NULL, `year` year(4) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property string|null $date @@ -29,6 +21,13 @@ * @property int|null $bigintSecond * @property int|null $year */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_update_time', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_update_time` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date` date DEFAULT NULL, `time` time DEFAULT NULL, `datetime` datetime DEFAULT NULL, `timestamp` timestamp NULL DEFAULT NULL, `int` int(11) DEFAULT NULL, `bigint` bigint(20) DEFAULT NULL, `bigint_second` bigint(20) DEFAULT NULL, `year` year(4) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT') +] abstract class UpdateTimeBase extends Model { /** @@ -43,9 +42,10 @@ abstract class UpdateTimeBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -63,7 +63,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -72,9 +72,10 @@ public function setId($id) /** * date. - * - * @Column(name="date", type="date", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'date', type: 'date', length: 0) + ] protected ?string $date = null; /** @@ -92,7 +93,7 @@ public function getDate(): ?string * * @return static */ - public function setDate($date) + public function setDate(mixed $date): self { $this->date = null === $date ? null : (string) $date; @@ -101,9 +102,10 @@ public function setDate($date) /** * time. - * - * @Column(name="time", type="time", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'time', type: 'time', length: 0) + ] protected ?string $time = null; /** @@ -121,7 +123,7 @@ public function getTime(): ?string * * @return static */ - public function setTime($time) + public function setTime(mixed $time): self { $this->time = null === $time ? null : (string) $time; @@ -130,9 +132,10 @@ public function setTime($time) /** * datetime. - * - * @Column(name="datetime", type="datetime", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'datetime', type: 'datetime', length: 0) + ] protected ?string $datetime = null; /** @@ -150,7 +153,7 @@ public function getDatetime(): ?string * * @return static */ - public function setDatetime($datetime) + public function setDatetime(mixed $datetime): self { $this->datetime = null === $datetime ? null : (string) $datetime; @@ -159,9 +162,10 @@ public function setDatetime($datetime) /** * timestamp. - * - * @Column(name="timestamp", type="timestamp", length=0, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'timestamp', type: 'timestamp', length: 0) + ] protected ?string $timestamp = null; /** @@ -179,7 +183,7 @@ public function getTimestamp(): ?string * * @return static */ - public function setTimestamp($timestamp) + public function setTimestamp(mixed $timestamp): self { $this->timestamp = null === $timestamp ? null : (string) $timestamp; @@ -188,9 +192,10 @@ public function setTimestamp($timestamp) /** * int. - * - * @Column(name="int", type="int", length=11, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'int', type: 'int', length: 11) + ] protected ?int $int = null; /** @@ -208,7 +213,7 @@ public function getInt(): ?int * * @return static */ - public function setInt($int) + public function setInt(mixed $int): self { $this->int = null === $int ? null : (int) $int; @@ -217,9 +222,10 @@ public function setInt($int) /** * bigint. - * - * @Column(name="bigint", type="bigint", length=20, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'bigint', type: 'bigint', length: 20) + ] protected ?int $bigint = null; /** @@ -237,7 +243,7 @@ public function getBigint(): ?int * * @return static */ - public function setBigint($bigint) + public function setBigint(mixed $bigint): self { $this->bigint = null === $bigint ? null : (int) $bigint; @@ -246,9 +252,10 @@ public function setBigint($bigint) /** * bigint_second. - * - * @Column(name="bigint_second", type="bigint", length=20, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'bigint_second', type: 'bigint', length: 20) + ] protected ?int $bigintSecond = null; /** @@ -266,7 +273,7 @@ public function getBigintSecond(): ?int * * @return static */ - public function setBigintSecond($bigintSecond) + public function setBigintSecond(mixed $bigintSecond): self { $this->bigintSecond = null === $bigintSecond ? null : (int) $bigintSecond; @@ -275,9 +282,10 @@ public function setBigintSecond($bigintSecond) /** * year. - * - * @Column(name="year", type="year", length=4, accuracy=0, nullable=true, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'year', type: 'year', length: 4) + ] protected ?int $year = null; /** @@ -295,7 +303,7 @@ public function getYear(): ?int * * @return static */ - public function setYear($year) + public function setYear(mixed $year): self { $this->year = null === $year ? null : (int) $year; diff --git a/tests/unit/Component/Model/Base/VirtualColumnBase.php b/tests/unit/Component/Model/Base/VirtualColumnBase.php index 56b8249191..b054b6c9f6 100644 --- a/tests/unit/Component/Model/Base/VirtualColumnBase.php +++ b/tests/unit/Component/Model/Base/VirtualColumnBase.php @@ -4,25 +4,24 @@ namespace Imi\Test\Component\Model\Base; -use Imi\Model\Annotation\Column; -use Imi\Model\Annotation\DDL; -use Imi\Model\Annotation\Entity; -use Imi\Model\Annotation\Table; use Imi\Model\Model; /** * tb_virtual_column 基类. * - * @Entity(camel=true, bean=true, incrUpdate=false) - * - * @Table(name="tb_virtual_column", usePrefix=false, id={"id"}, dbPoolName=null) - * - * @DDL(sql="CREATE TABLE `tb_virtual_column` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `amount` int(11) NOT NULL, `virtual_amount` decimal(10,2) GENERATED ALWAYS AS ((`amount` / 100)) VIRTUAL NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci") + * 此文件是自动生成,请勿手动修改此文件! * * @property int|null $id * @property int|null $amount * @property string|float|int|null $virtualAmount */ +#[ + \Imi\Model\Annotation\Entity(), + \Imi\Model\Annotation\Table(name: 'tb_virtual_column', id: [ + 'id', + ]), + \Imi\Model\Annotation\DDL(sql: 'CREATE TABLE `tb_virtual_column` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `amount` int(11) NOT NULL, `virtual_amount` decimal(10,2) GENERATED ALWAYS AS ((`amount` / 100)) VIRTUAL NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci') +] abstract class VirtualColumnBase extends Model { /** @@ -37,9 +36,10 @@ abstract class VirtualColumnBase extends Model /** * id. - * - * @Column(name="id", type="int", length=10, accuracy=0, nullable=false, default="", isPrimaryKey=true, primaryKeyIndex=0, isAutoIncrement=true, unsigned=true, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'id', type: 'int', length: 10, nullable: false, isPrimaryKey: true, primaryKeyIndex: 0, isAutoIncrement: true, unsigned: true) + ] protected ?int $id = null; /** @@ -57,7 +57,7 @@ public function getId(): ?int * * @return static */ - public function setId($id) + public function setId(mixed $id): self { $this->id = null === $id ? null : (int) $id; @@ -66,9 +66,10 @@ public function setId($id) /** * amount. - * - * @Column(name="amount", type="int", length=11, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=false) */ + #[ + \Imi\Model\Annotation\Column(name: 'amount', type: 'int', length: 11, nullable: false) + ] protected ?int $amount = null; /** @@ -86,7 +87,7 @@ public function getAmount(): ?int * * @return static */ - public function setAmount($amount) + public function setAmount(mixed $amount): self { $this->amount = null === $amount ? null : (int) $amount; @@ -95,9 +96,10 @@ public function setAmount($amount) /** * virtual_amount. - * - * @Column(name="virtual_amount", type="decimal", length=10, accuracy=2, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false, unsigned=false, virtual=true) */ + #[ + \Imi\Model\Annotation\Column(name: 'virtual_amount', type: 'decimal', length: 10, nullable: false, accuracy: 2, virtual: true) + ] protected string|float|int|null $virtualAmount = null; /** @@ -115,7 +117,7 @@ public function getVirtualAmount(): string|float|int|null * * @return static */ - public function setVirtualAmount($virtualAmount) + public function setVirtualAmount(mixed $virtualAmount): self { $this->virtualAmount = null === $virtualAmount ? null : $virtualAmount; diff --git a/tests/unit/Component/Model/TestList.php b/tests/unit/Component/Model/TestList.php index 90d6e36135..34b2d52180 100644 --- a/tests/unit/Component/Model/TestList.php +++ b/tests/unit/Component/Model/TestList.php @@ -47,7 +47,7 @@ public function getList() * * @return static */ - public function setList($list) + public function setList($list): self { $this->list = $list; diff --git a/tests/unit/Component/Tests/Annotation/Attr1.php b/tests/unit/Component/Tests/Annotation/Attr1.php new file mode 100644 index 0000000000..eea982fecc --- /dev/null +++ b/tests/unit/Component/Tests/Annotation/Attr1.php @@ -0,0 +1,13 @@ +attr1 = $attr1; + } +} diff --git a/tests/unit/Component/Tests/Annotation/NotAttr.php b/tests/unit/Component/Tests/Annotation/NotAttr.php new file mode 100644 index 0000000000..6b53b4c09a --- /dev/null +++ b/tests/unit/Component/Tests/Annotation/NotAttr.php @@ -0,0 +1,9 @@ +assertStringEqualsStringIgnoringLineEndings(<<<'CODE' + #[ + \Imi\Test\Component\Tests\Annotation\Attr1(), + \Imi\Test\Component\Tests\Annotation\Attr2(attr1: [ + new \Imi\Test\Component\Tests\Annotation\Attr1(id: 'a\\1', arr: [ + 1, + 2, + 3 + ]) + ], attr1s: [ + new \Imi\Test\Component\Tests\Annotation\Attr1(id: 'b'), + new \Imi\Test\Component\Tests\Annotation\Attr1(id: 'c') + ]), + \Imi\Test\Component\Tests\Annotation\Attr2() + ] + CODE, AttributeUtil::generateAttributesCode($attributes)); + + $this->assertStringEqualsStringIgnoringLineEndings(<<<'CODE' + #[ + \Imi\Test\Component\Tests\Annotation\Attr1() + ] + CODE, AttributeUtil::generateAttributesCode(new Attr1())); + } + + public function testGenerateAttributesCodeNotAttr(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Class Imi\Test\Component\Tests\Annotation\NotAttr does not an Attribute'); + AttributeUtil::generateAttributesCode(new NotAttr()); + } +}