1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Migratio\Resource; |
4
|
|
|
|
5
|
|
|
use Migratio\Schema; |
6
|
|
|
use Migratio\Contract\QueryBaseContract; |
7
|
|
|
use Migratio\Contract\ColumnsProcessContract; |
8
|
|
|
use Migratio\Resource\Request\BaseRequestProcess; |
9
|
|
|
|
10
|
|
|
class BaseManager |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var $connection QueryBaseContract |
|
|
|
|
14
|
|
|
*/ |
15
|
|
|
protected $connection; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var $schema Schema |
|
|
|
|
19
|
|
|
*/ |
20
|
|
|
protected $schema; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var $config |
|
|
|
|
24
|
|
|
*/ |
25
|
|
|
protected $config; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var null|object |
29
|
|
|
*/ |
30
|
|
|
protected $queryBuilder; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Pulling constructor. |
34
|
|
|
* @param $schema Schema |
35
|
|
|
*/ |
36
|
|
|
public function __construct($schema) |
37
|
|
|
{ |
38
|
|
|
$this->schema = $schema; |
39
|
|
|
$this->config = $this->schema->getConfig(); |
40
|
|
|
$this->connection = $this->schema->getConnection(); |
41
|
|
|
|
42
|
|
|
$this->queryBuilder = $this->schema->getGrammarPath().'\QueryBuilder'; |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* get all files |
47
|
|
|
* |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function getAllFiles() |
51
|
|
|
{ |
52
|
|
|
BaseRequestProcess::$paths = $this->config['paths']; |
53
|
|
|
|
54
|
|
|
return BaseRequestProcess::getAllFiles(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $file |
59
|
|
|
* @return mixed|string |
60
|
|
|
*/ |
61
|
|
|
protected function getClassName($file) |
62
|
|
|
{ |
63
|
|
|
$className = str_replace(".php","",BaseRequestProcess::getFileName($file)); |
64
|
|
|
|
65
|
|
|
return $className; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return ColumnsProcessContract |
70
|
|
|
*/ |
71
|
|
|
public function getColumns() |
72
|
|
|
{ |
73
|
|
|
$tables = $this->schema->params['tables']; |
74
|
|
|
|
75
|
|
|
return $this->connection->getColumns($tables); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* get stub path |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getStubPath() |
84
|
|
|
{ |
85
|
|
|
return __DIR__.''.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Stub'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return mixed |
90
|
|
|
*/ |
91
|
|
|
public function getTables() |
92
|
|
|
{ |
93
|
|
|
return $this->connection->getTables(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* get query builder |
98
|
|
|
* |
99
|
|
|
* @param null|string $table |
100
|
|
|
* @param null|string $data |
101
|
|
|
* @return mixed |
102
|
|
|
*/ |
103
|
|
|
public function queryBuilder($table=null,$data=null) |
104
|
|
|
{ |
105
|
|
|
$queryBuilder = $this->queryBuilder; |
106
|
|
|
|
107
|
|
|
return new $queryBuilder($this->schema,$table,$data); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* get table filters |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function tableFilters() |
116
|
|
|
{ |
117
|
|
|
$tables = $this->schema->params['tables']; |
118
|
|
|
|
119
|
|
|
$list = []; |
120
|
|
|
|
121
|
|
|
foreach ($this->getAllFiles() as $table=>$allFile) { |
122
|
|
|
|
123
|
|
|
if(count($tables)){ |
124
|
|
|
|
125
|
|
|
if(in_array($table,$tables)){ |
126
|
|
|
$list[$table]=$allFile; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return (count($list)) ? $list : $this->getAllFiles(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param null|string $path |
136
|
|
|
* @param array $params |
137
|
|
|
* @return mixed |
138
|
|
|
*/ |
139
|
|
|
public function getContentFile($path,$params=array()) |
140
|
|
|
{ |
141
|
|
|
$dt = fopen($path, "r"); |
142
|
|
|
$content = fread($dt, filesize($path)); |
|
|
|
|
143
|
|
|
fclose($dt); |
|
|
|
|
144
|
|
|
|
145
|
|
|
foreach ($params as $key=>$value){ |
146
|
|
|
|
147
|
|
|
$content=str_replace("__".$key."__",$value,$content); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
return $content; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
} |
154
|
|
|
|