table = $data['table_name'] ?? ''; $this->tableComment = (new Basics())->getTableComment($this->table); $this->pageName = $data['page_name'] ?: $this->tableComment; $this->make = $data['make'] ?? []; $this->tableInfo = array_column((new Basics())->getTableInfo($this->table), null, 'column_name'); unset($data['page_name'], $data['table_name'], $data['make']); $this->primaryKey = strtr(ConfigHelper::get('primary_key'), ['{table}' => $this->table]); $this->makeData = $this->dataJoinHandle($data); } /** * @return bool|int * @throws \ReflectionException */ public function make() { $error = ''; foreach (ConfigHelper::get('make_class') as $class => $value) { if (!isset($value['tag']) || !in_array($value['tag'], $this->make)) { continue; } $classInstance = Sc::reflex()->getInstance($class, ['make' => $this]); if (!$classInstance instanceof MakeItemInterface) { $error .= "{$class} 调用出错,请引用接口:" . MakeItemInterface::class . PHP_EOL; } $classInstance->make() or $error .= $class . ' 创建失败!' . PHP_EOL; } return $error; } /** * @param $url * @param $content * @return bool|int */ public function makeFile($url, $content) { if (!is_dir(dirname($url))) { mkdir(dirname($url), 0777, true); chmod(dirname($url), 0777); } //兼容linux return file_put_contents($url, $content); } /** * @param $data * @return mixed */ private function dataJoinHandle($data) { foreach ($data as &$datum) { if (empty($datum['join']) || !json_decode($datum['join'])) continue; $join = []; foreach (json_decode($datum['join']) as $item) { list($key, $value) = explode('=', $item); $join[trim($key)] = trim($value); } $datum['join'] = $join; } return $data; } }