api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ReflectedDatabase.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Tqdev\PhpCrudApi\Column\Reflection;
  3. use Tqdev\PhpCrudApi\Database\GenericReflection;
  4. class ReflectedDatabase implements \JsonSerializable
  5. {
  6. private $tableTypes;
  7. public function __construct(array $tableTypes)
  8. {
  9. $this->tableTypes = $tableTypes;
  10. }
  11. public static function fromReflection(GenericReflection $reflection): ReflectedDatabase
  12. {
  13. $tableTypes = [];
  14. foreach ($reflection->getTables() as $table) {
  15. $tableName = $table['TABLE_NAME'];
  16. $tableType = $table['TABLE_TYPE'];
  17. if (in_array($tableName, $reflection->getIgnoredTables())) {
  18. continue;
  19. }
  20. $tableTypes[$tableName] = $tableType;
  21. }
  22. return new ReflectedDatabase($tableTypes);
  23. }
  24. public static function fromJson(/* object */$json): ReflectedDatabase
  25. {
  26. $tableTypes = (array) $json->tables;
  27. return new ReflectedDatabase($tableTypes);
  28. }
  29. public function hasTable(string $tableName): bool
  30. {
  31. return isset($this->tableTypes[$tableName]);
  32. }
  33. public function getType(string $tableName): string
  34. {
  35. return isset($this->tableTypes[$tableName]) ? $this->tableTypes[$tableName] : '';
  36. }
  37. public function getTableNames(): array
  38. {
  39. return array_keys($this->tableTypes);
  40. }
  41. public function removeTable(string $tableName): bool
  42. {
  43. if (!isset($this->tableTypes[$tableName])) {
  44. return false;
  45. }
  46. unset($this->tableTypes[$tableName]);
  47. return true;
  48. }
  49. public function serialize()
  50. {
  51. return [
  52. 'tables' => $this->tableTypes,
  53. ];
  54. }
  55. public function jsonSerialize()
  56. {
  57. return $this->serialize();
  58. }
  59. }