コード例 #1
0
 /**
  * @param FormInterface   $form
  * @param HelperSet       $helperSet
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws CanNotInteractWithForm If the input isn't interactive or a compound form.
  *
  * @return array
  */
 public function interactWith(FormInterface $form, HelperSet $helperSet, InputInterface $input, OutputInterface $output)
 {
     if (!$input->isInteractive()) {
         throw new CanNotInteractWithForm('This interactor only works with interactive input');
     }
     if (!FormUtil::isCompound($form)) {
         throw new CanNotInteractWithForm('Expected a compound form');
     }
     $submittedData = [];
     foreach ($form->all() as $name => $field) {
         try {
             $submittedData[$name] = $this->formInteractor->interactWith($field, $helperSet, $input, $output);
         } catch (NoNeedToInteractWithForm $exception) {
             continue;
         }
     }
     return $submittedData;
 }
コード例 #2
0
 /**
  * @param FormInterface   $form
  * @param HelperSet       $helperSet
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws CanNotInteractWithForm     If the input isn't interactive.
  * @throws FormNotReadyForInteraction If the "collection" form hasn't the option "allow_add".
  *
  * @return array
  */
 public function interactWith(FormInterface $form, HelperSet $helperSet, InputInterface $input, OutputInterface $output)
 {
     if (!$input->isInteractive()) {
         throw new CanNotInteractWithForm('This interactor only works with interactive input');
     }
     if (!FormUtil::isTypeInAncestry($form, 'collection')) {
         throw new CanNotInteractWithForm('Expected a "collection" form');
     }
     if (!$form->getConfig()->getOption('allow_add')) {
         throw new FormNotReadyForInteraction('The "collection" form should have the option "allow_add"');
     }
     $this->printHeader($form, $output);
     $submittedData = [];
     $prototype = $form->getConfig()->getAttribute('prototype');
     while ($this->askIfContinueToAdd($helperSet, $input, $output)) {
         $submittedData[] = $this->formInteractor->interactWith($prototype, $helperSet, $input, $output);
     }
     return $submittedData;
 }