예제 #1
0
 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);
         }
     }
 }
예제 #2
0
    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);
        }
    }