-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
84 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
// get 64 | ||
|
||
enum Status { | ||
case active; | ||
case deactive; | ||
} | ||
|
||
var_dump(Status::active->name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Azad\Database; | ||
|
||
class Enums extends Database { | ||
public static function ValueToEnum($table,$column,$value) { | ||
$ColumnData = parent::$Tables[parent::$MyHash][$table]['columns'][$column]; | ||
if (isset($ColumnData['enum'])) { | ||
if (isset($ColumnData['enum']::cases()[0]->value)) { | ||
$value = $ColumnData['enum']::tryFrom($value); | ||
} else { | ||
$value = constant("{$ColumnData['enum']}::{$value}"); | ||
} | ||
} | ||
return $value; | ||
} | ||
public static function EnumToValue($table,$column,$enum) { | ||
$ColumnData = parent::$Tables[parent::$MyHash][$table]['columns'][$column]; | ||
if (isset($ColumnData['enum'])) { | ||
if (!$enum instanceof $ColumnData['enum']) { | ||
throw new \Azad\Database\Exception\DataType("The values of the enum class do not match the database data."); | ||
} | ||
if (isset($ColumnData['enum']::cases()[0]->value)) { | ||
$value = $enum->value; | ||
} else { | ||
$value = $enum->name; | ||
} | ||
} | ||
return $value; | ||
} | ||
|
||
} | ||
|
||
/* | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters