22
33namespace App \ApiJson \Entity ;
44
5- use App \ApiJson \Interface \QueryInterface ;
6-
75class TableEntity
86{
97 /** @var ConditionEntity $ConditionEntity */
@@ -12,71 +10,51 @@ class TableEntity
1210 /** @var string $realTableName 真实表名 */
1311 protected string $ realTableName ;
1412
15- /** @var array $condition */
16- protected array $ condition ;
17-
18- /** @var QueryInterface $query */
19- protected QueryInterface $ query ;
13+ /** @var array $content 表名对应的数据 */
14+ protected array $ content ;
2015
2116 /**
2217 * @param string $tableName 表名
23- * @param array $jsonContent json数据
18+ * @param array $jsonContent json源数据
2419 */
2520 public function __construct (protected string $ tableName , protected array $ jsonContent )
2621 {
27- $ this ->realTableName = $ tableName ;
28- $ this ->condition = $ this ->getConditionByContent ();
29- }
30-
31- public function getResult (): array
32- {
33- $ this ->buildQuery ();
22+ $ sanitizeTableName = str_replace (['[] ' ], '' , $ this ->tableName );
23+ $ this ->realTableName = $ sanitizeTableName ;
24+ $ this ->content = $ this ->getContentByTableName ();
3425 $ this ->parseConditionEntity ();
35- return $ this ->formatResult ($ this ->query ->all ());
3626 }
3727
38- public function getCount (): int
28+ public function getTableName (): string
3929 {
40- $ this ->buildQuery ();
41- $ this ->parseConditionEntity ();
42- return $ this ->query ->count ();
30+ return $ this ->tableName ;
4331 }
4432
45- public function insert ()
33+ public function getRealTableName (): string
4634 {
47-
35+ return $ this -> realTableName ;
4836 }
4937
50- public function update ()
38+ public function getContent (): array
5139 {
52-
40+ return $ this -> content ;
5341 }
5442
55- protected function formatResult ( array $ result ): array
43+ public function getConditionEntity ( ): ConditionEntity
5644 {
57- return $ result ;
45+ return $ this -> conditionEntity ;
5846 }
5947
60- protected function buildQuery ()
48+ protected function getContentByTableName (): array
6149 {
62- $ this -> query = new ( config ( join ( ' . ' , [
63- ' dependencies ' , QueryInterface::class
64- ])))( $ this -> realTableName ) ;
50+ $ content = $ this -> jsonContent [ $ this -> tableName ];
51+ if ( isset ( $ content [ $ this -> realTableName ])) $ content = $ content [ $ this -> realTableName ];
52+ return $ content ;
6553 }
6654
6755 protected function parseConditionEntity ()
6856 {
69- $ entity = new ConditionEntity ($ this ->condition );
57+ $ entity = new ConditionEntity ($ this ->content );
7058 $ this ->conditionEntity = $ entity ;
7159 }
72-
73- protected function getConditionByContent (): array
74- {
75- $ sanitizeTableName = str_replace (['[] ' ], '' , $ this ->tableName );
76- if (isset ($ this ->jsonContent [$ sanitizeTableName ])) {
77- $ this ->realTableName = $ sanitizeTableName ;
78- return $ this ->jsonContent [$ sanitizeTableName ];
79- }
80- return $ this ->jsonContent [$ this ->tableName ];
81- }
8260}
0 commit comments