public static function createFromStructure($name, Structure $structure) { $config = $structure->getConfig(); if (!array_key_exists($name, $config['tables'])) { throw new \Exception("结构配置文件中没有 {$name} 这个表。"); } $table = new static(); $table->setName($name); $table->setStructure($structure); foreach ($table->getConfig()['fields'] as $name => $field) { $table->addField(FieldFactory::create($name, $table)); } return $table; }
public static function createFromConfig($name, Config $config) { $form = new static(); $form->setName($name); $form->setConfig($config); foreach ($form->getConfig()['form'] as $name => $field) { $newField = Forms::createField($field['type']); $newField->setName($name); $options = []; $options['label'] = isset($field['label']) ? $field['label'] : $name; if (isset($field['options'])) { $options = array_merge($options, $field['options']); } $newField->setOptions($options); $form->addField($newField); } return $form; }