/** * Returns an instance of CakeManager * * @param \Phinx\Config\ConfigInterface|null $config ConfigInterface the Manager needs to run * @return \Migrations\CakeManager Instance of CakeManager */ public function getManager($config = null) { if (!$this->manager instanceof CakeManager) { if (!$config instanceof ConfigInterface) { throw new \RuntimeException('You need to pass a ConfigInterface object for your first getManager() call'); } $this->manager = new CakeManager($config, $this->output); } elseif ($config !== null) { $defaultEnvironment = $config->getEnvironment('default'); try { $environment = $this->manager->getEnvironment('default'); $oldConfig = $environment->getOptions(); unset($oldConfig['connection']); if ($oldConfig == $defaultEnvironment) { $defaultEnvironment['connection'] = $environment->getAdapter()->getConnection(); } } catch (\InvalidArgumentException $e) { } $config['environments'] = ['default' => $defaultEnvironment]; $this->manager->setEnvironments([]); $this->manager->setConfig($config); } $this->setAdapter(); return $this->manager; }