public function handleProfileInit(ProfileInitEvent $e) { $profile = $e->getProfile(); $input = $e->getInput(); $output = $e->getOutput(); $noInteraction = $input->getOption('no-interaction'); $transport = $input->getOption('transport'); $profileName = $input->getOption('profile'); // if both transport and profile specified, then user wants // to create or update an existing profile if ($profileName && $transport) { $profile->setName($profileName); $overwrite = false; if (file_exists($this->profileLoader->getProfilePath($profileName))) { $res = true; if (false === $noInteraction) { $res = $this->questionHelper->askConfirmation($output, sprintf('Update existing profile "%s"?', $profileName)); } $overwrite = true; } else { $res = true; if (false === $noInteraction) { $res = $this->questionHelper->askConfirmation($output, sprintf('Create new profile "%s"?', $profileName)); } } if ($res) { $this->profileLoader->saveProfile($profile, $overwrite); } } }
public function handleProfileInit(ProfileInitEvent $e) { $profile = $e->getProfile(); $input = $e->getInput(); $output = $e->getOutput(); $transport = $input->getOption('transport'); $profileName = $input->getOption('profile'); if ($profileName && null === $transport) { $profile->setName($profileName); $this->profileLoader->loadProfile($profile); $this->showProfile($output, $profile); } if (null === $profileName && null === $transport) { $profileNames = $this->profileLoader->getProfileNames(); if (count($profileNames) === 0) { $output->writeln('<info>No transport specified, and no profiles available.</info>'); $output->writeln(<<<EOT You must specify the connection parameters, for example: \$ phpcrsh --transport=jackrabbit Or: \$ phpcrsh --transport=doctrine-dbal --db-name=mydb You can create profiles by using the <info>--profile</info> option: } \$ phpcrsh --profile=mywebsite --transport=doctrine-dbal --db-name=mywebsite Profiles can then be used later on: \$ phpcrsh --profile=mywebsite EOT ); exit(1); } $output->writeln('<info>No connection parameters, given. Select an existing profile:</info>'); $output->writeln(''); foreach ($profileNames as $i => $profileName) { $output->writeln(sprintf(' (%d) <comment>%s</comment>', $i, $profileName)); } $output->writeln(''); $selectedName = null; while (null === $selectedName) { $number = $this->dialogHelper->ask($output, '<info>Enter profile number</info>: '); if (!isset($profileNames[$number])) { $output->writeln('<error>Invalid selection!</error>'); continue; } $selectedName = $profileNames[$number]; } $profile->setName($selectedName); $this->profileLoader->loadProfile($profile); $this->showProfile($output, $profile); } }
public function handleProfileInit(ProfileInitEvent $e) { $profile = $e->getProfile(); $input = $e->getInput(); $transportOptions = ['transport' => 'name', 'db-username' => 'db_username', 'db-name' => 'db_name', 'db-password' => 'db_password', 'db-host' => 'db_host', 'db-path' => 'db_path', 'db-driver' => 'db_driver', 'repo-url' => 'repo_url', 'repo-path' => 'repo_path']; $phpcrOptions = ['phpcr-username' => 'username', 'phpcr-password' => 'password']; foreach ($transportOptions as $optionName => $configName) { $value = $input->getOption($optionName); if (!$value) { continue; } if (null !== $value) { // sanitize some input values switch ($optionName) { case 'db-path': if (!file_exists($value)) { throw new \InvalidArgumentException(sprintf('DB file "%s" does not exist.', $value)); } $value = realpath(dirname($value)) . DIRECTORY_SEPARATOR . basename($value); break; default: // all good } } $profile->set('transport', $configName, (string) $value); } $workspace = $input->getArgument('workspace'); if ($workspace) { $profile->set('phpcr', 'workspace', $workspace); } foreach ($phpcrOptions as $optionName => $configName) { if (!$input->getOption($optionName)) { continue; } $profile->set('phpcr', $configName, $input->getOption($optionName)); } }