/** * @param array $params config params * @return null */ public function execute(array $params = null) { $mapFile = 'app/domains.php'; $err = 'OrmStartupTask failed: '; if (isset($params['orm-domain-map'])) { $mapFile = $params['orm-domain-map']; if (!is_string($mapFile) || empty($mapFile)) { $err .= '-(orm-domain-map) must be a non empty string'; throw new InvalidArgumentException($err); } } if (false !== strpos($mapFile, '../')) { $err .= "file path is invalid"; throw new LogicException($err); } $file = AF_BASE_PATH . "/{$mapFile}"; if (!file_exists($file)) { $err .= "could not find -({$file})"; throw new RunTimeException($err); } $map = (require $file); if (!is_array($map)) { $err = "domain must is not an array"; throw new LogicException($err); } OrmManager::setRegisteredDomains($map); return "registered " . count($map) . " domains"; }
/** * @throws RunTimeException * @param string $key * @return DbMapInterface */ public static function getDbMap($key) { $db = OrmManager::getDbMap($key); if (false === $db) { $err = "db map could not be found for -({$key})"; throw new RunTimeException($err); } return $db; }
/** * @param string $key * @return OrmRepositoryInterface */ public function getRepository($key, $source = 'db') { return OrmManager::getRepository($key, $source); }