protected function validateContainerName($container)
 {
     if (isNull($this->helper)) {
         $this->helper = new ContainerHelper();
     }
     return $this->helper->containerExists($container);
 }
 /**
  * (#inheritdoc)
  */
 protected function build($name, InputInterface $input, OutputInterface $output)
 {
     $helper = new ContainerHelper();
     $containers = $helper->getAllContainers();
     $container_path = $containers[$name];
     $docker = $this->getDocker();
     $context = new Context($container_path);
     $output->writeln("-------------------- Start build script --------------------");
     $response = $docker->build($context, $name, function ($result, $type) {
         fputs($type === 1 ? STDOUT : STDERR, $result['stream']);
     });
     //$response = $docker->build($context, $name, function ($result) use (&$content) {
     //  if (isset($result['stream'])) {
     //    $content .= $result['stream'];
     //  }
     //});
     //$output->writeln($content);
     $output->writeln("--------------------- End build script ---------------------");
     $response->getBody()->getContents();
     $output->writeln((string) $response);
     // TODO: Capture return value and determine whether build was successful or not, throwing an error if it isn't.
     // (This may already automatically throw an exception within docker-php)
     /* LEGACY CODE - original notification
        if ($return_var === 0) {
          $output->writeln("<comment>Container <options=bold>$name</options=bold> build complete.</comment>");
          $output->writeln("<comment>The $name container image should now be available.</comment>");
        }
        else {
          $output->writeln("<error>Build script exited with a non-zero error code: <options=bold>$return_var</options=bold></error>");
          $output->writeln("<comment>Please review the output above to determine the root cause.</comment>");
        }
        */
 }
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln("<info>Executing init:web</info>");
     # Generate array of general arguments to pass downstream
     $options = array();
     $options['--quiet'] = $input->getOption('quiet');
     $options['--verbose'] = $input->getOption('verbose');
     $options['--ansi'] = $input->getOption('ansi');
     $options['--no-ansi'] = $input->getOption('no-ansi');
     $options['--no-interaction'] = $input->getOption('no-interaction');
     $helper = new ContainerHelper();
     $containers = $helper->getWebContainers();
     $container_names = array_keys($containers);
     $names = array();
     if ($names = $input->getArgument('container_name')) {
         // We've been passed a container name, validate it
         foreach ($names as $key => $name) {
             if (!in_array($name, $container_names)) {
                 // Not a valid web container.  Remove it and warn the user
                 unset($names[$key]);
                 $output->writeln("<error>Received an invalid web container name. Skipping build of the {$name} container.");
             }
         }
     } else {
         if ($options['--no-interaction']) {
             // Non-interactive mode.  Default to PHP 5.4
             $names = array('web-5.4');
         } else {
             $names = $this->getWebContainerNames($container_names, $input, $output);
             if (in_array('all', $names)) {
                 $names = $container_names;
             }
         }
     }
     if (empty($names)) {
         $output->writeln("<error>No valid web container names provided. Aborting.");
         return;
     } else {
         $cmd = $this->getApplication()->find('build');
         $arguments = array('command' => 'build', 'container_name' => $names);
         $cmdinput = new ArrayInput($arguments + $options);
         $returnCode = $cmd->run($cmdinput, $output);
         // TODO: Error handling
     }
     $output->writeln('');
 }