Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $envName = $input->getArgument('env-name');
     $envPath = getenv('HOME') . DIRECTORY_SEPARATOR . '.virtphp';
     $envFolder = $envPath . DIRECTORY_SEPARATOR . 'envs';
     // Pass the output object to the parent
     $this->output = $output;
     // Check to make sure environment name is valid
     if (!Virtphp::isValidName($envName)) {
         $output->writeln('<error>Sorry, but that is not a valid environment name.</error>');
         return false;
     }
     // Make sure the env hasn't been created before
     if ($this->checkForEnv($envName)) {
         $output->writeln('<error>' . 'The environment you specified has already been created.' . '</error>');
         return false;
     }
     $binDir = $input->getOption('php-bin-dir');
     $installPath = $input->getOption('install-path');
     if ($installPath === null) {
         $installPath = $envFolder;
     }
     // Setup environment
     $creator = $this->getWorker('Creator', array($input, $output, $envName, $installPath, $binDir));
     $creator->setCustomPhpIni($input->getOption('php-ini'));
     $creator->setCustomPearConf($input->getOption('pear-conf'));
     if ($creator->execute()) {
         $output->writeln('<bg=green;options=bold>' . "Your virtual php environment ({$envName}) has been created!" . '</bg=green;options=bold>');
         $output->writeln('<info>' . "You can activate your new environment using: ~\$ source {$installPath}/{$envName}/bin/activate" . "</info>\n");
         $this->addEnv($envName, $installPath);
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $envName = $input->getArgument('new-env-name');
     $copyEnv = $input->getArgument('existing-env-path');
     // Pass the output object to the parent
     $this->output = $output;
     if (!Virtphp::isValidName($envName)) {
         $output->writeln('<error>Sorry, but that is not a valid environment name.</error>');
         return false;
     }
     $env = $this->checkForEnv($copyEnv);
     // Validate the provided directory contains what we need
     if (!$this->isValidPath($env, $output)) {
         return false;
     }
     // Logic for cloning directory
     $cloner = $this->getWorker('Cloner', array($env['path'] . DIRECTORY_SEPARATOR . $env['name'], $envName, $output));
     if ($cloner->execute()) {
         $output->writeln('<bg=green;options=bold>' . 'Your new cloned virtual php environment has been created.' . '</bg=green;options=bold>');
         $output->writeln('<info>Cloned from: $rootPath</info>');
         // Add new env to list
         $this->addEnv($envName);
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * @covers Virtphp\Virtphp::isValidName
  */
 public function testIsValidName()
 {
     $names = array('foo-Bar_2013' => true, 'f123bar' => true, 'Afoobar' => true, '5foo' => false, 'foo.bar' => false);
     foreach ($names as $name => $expected) {
         $this->assertEquals($expected, Virtphp::isValidName($name));
     }
 }
Example #4
0
 /**
  * @param string $name Name of the new virtual env
  */
 public function setEnvName($name)
 {
     if (!Virtphp::isValidName($name)) {
         throw new \RuntimeException('Environment name must contain only letters, numbers, dashes, and underscores.' . " {$name} is invalid.");
     }
     $this->envName = $name;
 }