/** * @param $table * @return ComboDirectoryManager|UniDirectoryManager|Repository|null * @throws \Exception */ public function getManager($table) { if (!isset($this->tables[$table])) { throw new \UnexpectedValueException("not defined table {$table} in DirFact"); } $tableMeta = (array) $this->tables[$table]; $entityClass = isset($tableMeta["class"]) ? $tableMeta["class"] : null; $cacheId = "managers|{$table}"; if ($manager = $this->getInnerCache($cacheId)) { return $manager; } if (isset($tableMeta["dictList"])) { $dicts = $tableMeta["dictList"]; $manager = new ComboDirectoryManager(); $manager->setTable($table); foreach ($dicts as $field => $table) { $childManager = is_callable($table) ? call_user_func($table) : $this->getManager($table); $manager->addDictManager($field, $childManager); } } else { $manager = new UniDirectoryManager(); $manager->setTable($table); } if (!is_null($entityClass)) { $manager->setEntityClass($entityClass); } if (isset($tableMeta["fields"]) && array($tableMeta["fields"])) { $manager->setFields($tableMeta["fields"]); } $this->setInnerCache($cacheId, $manager); return $manager; }
public function getFields(UniDirectoryManager $manager) { $fields = $manager->getFieldsList($manager->getTable()); $dictFields = array_flip($this->getDictFields($manager)); $newFields = []; foreach ($fields as $field) { $nField = ["name" => $field, "dict" => isset($dictFields[$field])]; $newFields[$field] = $nField; } return $newFields; }
public function reserve(EntityInterface $entity) { $data = parent::reserve($entity); foreach ($data["fields"] as $name => $value) { if ($value instanceof EntityInterface) { $data["fields"][$name] = $value->getId(); } } return $data; }