Skip to content

Commit

Permalink
Merge pull request #23 from XueSiLf/2.x
Browse files Browse the repository at this point in the history
feat: Adapt to php8.1 version
  • Loading branch information
kiss291323003 authored Mar 15, 2024
2 parents c2a8420 + 513246a commit 3c83060
Show file tree
Hide file tree
Showing 34 changed files with 864 additions and 669 deletions.
60 changes: 32 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
{
"name": "easyswoole/ddl",
"type": "library",
"description": "An efficient swoole framework",
"keywords": [
"swoole",
"framework",
"async",
"easyswoole"
],
"homepage": "https://www.easyswoole.com/",
"license": "Apache-2.0",
"authors": [
{
"name": "YF",
"email": "291323003@qq.com"
"name": "easyswoole/ddl",
"type": "library",
"description": "An efficient swoole framework",
"keywords": [
"swoole",
"framework",
"async",
"easyswoole"
],
"homepage": "https://www.easyswoole.com/",
"license": "Apache-2.0",
"authors": [
{
"name": "YF",
"email": "291323003@qq.com"
}
],
"autoload": {
"psr-4": {
"EasySwoole\\DDL\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"EasySwoole\\DDL\\Test\\": "test/"
}
},
"require": {
"easyswoole/spl": "^2.0"
},
"require-dev": {
"easyswoole/phpunit": "^1.0"
}
],
"autoload": {
"psr-4": {
"EasySwoole\\DDL\\": "src/",
"EasySwoole\\DDL\\Test\\": "test/"
}
},
"require": {
"easyswoole/spl": "^1.2"
},
"require-dev": {
"easyswoole/phpunit": "^1.0"
}
}
11 changes: 5 additions & 6 deletions src/Blueprint/AbstractInterface/ColumnAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,24 @@ public function getColumnName()

/**
* 设置字段类型
* @param string $type
* @param DataType $type
* @return ColumnAbstract
*/
public function setColumnType(string $type)
public function setColumnType(DataType $type)
{
$type = trim($type);
if (!DataType::isValidValue($type)) {
throw new InvalidArgumentException('The column type ' . $type . ' is invalid');
throw new InvalidArgumentException('The column type ' . $type->value . ' is invalid');
}
$this->columnType = $type;
return $this;
}

/**
* @return mixed
* @return string
*/
public function getColumnType()
{
return $this->columnType;
return $this->columnType->value;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Blueprint/AbstractInterface/ColumnInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace EasySwoole\DDL\Blueprint\AbstractInterface;

use EasySwoole\DDL\Enum\DataType;

/**
* 字段构造器接口类
* Class ColumnInterface
*
* @package EasySwoole\DDL\Blueprint\AbstractInterface
*/
interface ColumnInterface
Expand All @@ -23,10 +26,10 @@ public function getColumnName();

/**
* 设置字段类型
* @param string $type
* @param DataType $type
* @return ColumnInterface
*/
public function setColumnType(string $type);
public function setColumnType(DataType $type);

/**
* @return mixed
Expand Down
13 changes: 9 additions & 4 deletions src/Blueprint/AbstractInterface/IndexAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasySwoole\DDL\Blueprint\AbstractInterface;

use EasySwoole\DDL\Enum\Index;
use EasySwoole\DDL\Enum\Index as IndexType;
use InvalidArgumentException;

Expand Down Expand Up @@ -39,12 +40,11 @@ public function getIndexName()

/**
* 设置索引类型
* @param string $type
* @param IndexType $type
* @return IndexAbstract
*/
public function setIndexType(string $type)
public function setIndexType(IndexType $type)
{
$type = trim($type);
if (!IndexType::isValidValue($type)) {
throw new InvalidArgumentException('The index type ' . $type . ' is invalid');
}
Expand All @@ -57,7 +57,7 @@ public function setIndexType(string $type)
*/
public function getIndexType()
{
return $this->indexType;
return $this->indexType->value;
}

/**
Expand Down Expand Up @@ -112,4 +112,9 @@ public function __toString()
{
return $this->__createDDL();
}

public static function isValidValue()
{

}
}
7 changes: 5 additions & 2 deletions src/Blueprint/AbstractInterface/IndexInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace EasySwoole\DDL\Blueprint\AbstractInterface;

use EasySwoole\DDL\Enum\Index as IndexType;

/**
* 索引构造器接口类
* Class IndexInterface
*
* @package EasySwoole\DDL\Blueprint\AbstractInterface
*/
interface IndexInterface
Expand All @@ -23,10 +26,10 @@ public function getIndexName();

/**
* 设置索引类型
* @param string $type
* @param IndexType $type
* @return IndexInterface
*/
public function setIndexType(string $type);
public function setIndexType(IndexType $type);

/**
* @return mixed
Expand Down
4 changes: 2 additions & 2 deletions src/Blueprint/Alter/ColumnAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private function parseColumnLimit()
private function parseDataType()
{
$columnLimit = $this->parseColumnLimit();
$columnType = $this->columnType;
$columnType = $this->columnType->value;
if ($columnLimit) {
$columnType .= $columnLimit;
}
Expand All @@ -362,7 +362,7 @@ public function __createDDL(): string
return implode(' ',
array_filter(
[
Alter::ADD,
Alter::ADD->name,
'`' . $this->columnName . '`',
(string)$this->parseDataType(),
$this->isBinary ? 'BINARY' : null,
Expand Down
4 changes: 2 additions & 2 deletions src/Blueprint/Alter/ColumnChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private function parseColumnLimit()
private function parseDataType()
{
$columnLimit = $this->parseColumnLimit();
$columnType = $this->columnType;
$columnType = $this->columnType->value;
if ($columnLimit) {
$columnType .= $columnLimit;
}
Expand All @@ -385,7 +385,7 @@ public function __createDDL(): string
return implode(' ',
array_filter(
[
Alter::CHANGE,
Alter::CHANGE->name,
'`' . $this->oldColumnName . '`',
'`' . $this->columnName . '`',
(string)$this->parseDataType(),
Expand Down
2 changes: 1 addition & 1 deletion src/Blueprint/Alter/ColumnDrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __createDDL(): string
return implode(' ',
array_filter(
[
Alter::DROP,
Alter::DROP->name,
'`' . $this->getColumnName() . '`',
]
)
Expand Down
4 changes: 2 additions & 2 deletions src/Blueprint/Alter/ColumnModify.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private function parseColumnLimit()
private function parseDataType()
{
$columnLimit = $this->parseColumnLimit();
$columnType = $this->getColumnType();
$columnType = $this->getColumnType() ;
if ($columnLimit) {
$columnType .= $columnLimit;
}
Expand All @@ -362,7 +362,7 @@ public function __createDDL(): string
return implode(' ',
array_filter(
[
Alter::MODIFY,
Alter::MODIFY->name,
'`' . $this->getColumnName() . '`',
(string)$this->parseDataType(),
$this->getIsBinary() ? 'BINARY' : null,
Expand Down
4 changes: 2 additions & 2 deletions src/Blueprint/Alter/ForeignAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function __createDDL()
return implode(' ',
array_filter(
[
Alter::ADD,
Alter::ADD->name,
$this->getForeignName() ? "CONSTRAINT `{$this->getForeignName()}`" : null,
"FOREIGN KEY",
$this->parseLocalColumns(),
Expand All @@ -243,4 +243,4 @@ public function __toString()
{
return $this->__createDDL();
}
}
}
4 changes: 2 additions & 2 deletions src/Blueprint/Alter/ForeignDrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __createDDL()
return implode(' ',
array_filter(
[
Alter::DROP . ' FOREIGN KEY',
Alter::DROP->name . ' FOREIGN KEY',
'`' . $this->getForeignName() . '`',
]
)
Expand All @@ -72,4 +72,4 @@ public function __toString()
{
return $this->__createDDL();
}
}
}
12 changes: 6 additions & 6 deletions src/Blueprint/Alter/IndexAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ private function parseIndexColumns()
public function __createDDL()
{
$indexPrefix = [
IndexType::NORMAL => 'INDEX',
IndexType::UNIQUE => 'UNIQUE INDEX',
IndexType::PRIMARY => 'PRIMARY KEY',
IndexType::FULLTEXT => 'FULLTEXT INDEX',
IndexType::NORMAL->value => 'INDEX',
IndexType::UNIQUE->value => 'UNIQUE INDEX',
IndexType::PRIMARY->value => 'PRIMARY KEY',
IndexType::FULLTEXT->value => 'FULLTEXT INDEX',
];
return implode(' ',
array_filter(
[
Alter::ADD,
Alter::ADD->name,
$indexPrefix[$this->getIndexType()],
$this->getIndexName() !== null ? '`' . $this->getIndexName() . '`' : null,
$this->parseIndexColumns(),
Expand All @@ -114,4 +114,4 @@ public function __createDDL()
)
);
}
}
}
4 changes: 2 additions & 2 deletions src/Blueprint/Alter/IndexDrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __createDDL()
return implode(' ',
array_filter(
[
Alter::DROP . ' INDEX',
Alter::DROP->name . ' INDEX',
'`' . $this->getIndexName() . '`',
]
)
Expand All @@ -72,4 +72,4 @@ public function __toString()
{
return $this->__createDDL();
}
}
}
Loading

0 comments on commit 3c83060

Please sign in to comment.