Example #1
0
 /**
  * @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;
 }