Пример #1
0
 /**
  * @param string $index
  * @param Project $newval
  *
  * @throws \InvalidArgumentException
  */
 public function offsetSet($index, $newval)
 {
     if (false === $newval instanceof Project) {
         throw new \InvalidArgumentException('value must be instance of \\Crane\\Configuration\\Project');
     }
     if ($index != $newval->getName()) {
         throw new \InvalidArgumentException('\\Crane\\Configuration\\Project::getName() must match index name');
     }
     parent::offsetSet($index, $newval);
 }
Пример #2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws \InvalidArgumentException
  * @return Docker
  */
 protected function getDocker(InputInterface $input, OutputInterface $output)
 {
     if ($this->getDefinition()->hasArgument(self::ARGUMENT_TARGET)) {
         $target = $input->getArgument(self::ARGUMENT_TARGET) ?: $this->project->getCurrentTarget();
     } else {
         $target = $this->project->getCurrentTarget();
     }
     $targets = $this->project->getTargets();
     if (false === $targets->offsetExists($target)) {
         throw new \InvalidArgumentException('You must choose a valid target to start the containers. Valid options are:' . "\n - " . implode("\n - ", array_keys($targets->getArrayCopy())));
     }
     $ssh = $targets->offsetGet($target);
     /** @var ExecutorFactory $factory */
     $factory = $this->getApplication()->getService('executor.factory');
     $executor = $factory->createExecutor($output, true, $ssh);
     /** @var Docker $docker */
     $docker = $this->getApplication()->getService('docker');
     $docker->setExecutor($executor);
     return $docker;
 }
Пример #3
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @param Project         $project
  */
 private function overrideSettings(InputInterface $input, OutputInterface $output, Project $project)
 {
     $branch = $input->getOption(self::OPTION_OVERRIDE_BRANCH);
     $name = null;
     if ($branch) {
         $output->writeln(sprintf('Overriding repository branch: <info>%s</info>… ', $branch));
         $project->overrideBranch($branch);
         $name = preg_replace('#(/[^/]+)?$#', '/' . $branch, $project->getName());
     }
     $name = $input->getOption(self::OPTION_OVERRIDE_NAME) ?: $name;
     if ($name) {
         $output->writeln(sprintf('Overriding project name: <info>%s</info>… ', $name));
         $project->overrideName($name);
         $base = sprintf("%u", crc32($name)) % floor(1000 / sizeof($project->getFixedPorts()));
         $project->setFixedPortsBase(48000 + $base);
     }
 }