/**
  * {@inheritDoc}
  */
 public function validateValue($targetPath)
 {
     if (!file_exists($targetPath) && $this->questionAsker->ask(new ConfirmationQuestion("<question>The target directory does not exist, would you like to create it?</>\nType [<fg=yellow>y</>]es (<fg=yellow>default</>) or [n]o: "))) {
         $this->filesystem->mkdir($targetPath);
     }
     $dir = new Directory($targetPath);
     if (!$dir->isEmpty() && !$this->questionAsker->ask(new ConfirmationQuestion("<question>The target directory is not empty, proceed anyway?</>\nType [y]es or [<fg=yellow>n</>]o (<fg=yellow>default</>): ", false))) {
         throw new DirectoryNotEmptyException((string) $dir);
     }
     return $dir;
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 public function getData(array $data = []) : array
 {
     foreach ([['package_name', 'Package name', null], ['package_description', 'Package description', null], ['package_type', 'Package type', 'library'], ['license_name', 'License', 'MIT'], ['author_name', 'Author\'s name', null], ['author_email', 'Author\'s e-mail address', null], ['author_homepage', 'Author\'s homepage', null], ['main_namespace', "Main namespace (<fg=cyan>please use double backslashes</>)", null]] as $questionData) {
         list($key, $label, $default) = $questionData;
         $data[$key] = $this->questionAsker->ask(new Question(sprintf("<fg=yellow>*</> {$label}%s: ", $default ? " (<fg=yellow>{$default}</>)" : ''), $default));
     }
     $services = array_keys(self::HOSTING_SERVICE_DEFAULTS);
     $service = $this->questionAsker->ask(new ChoiceQuestion("<fg=yellow>*</> Hosting service:", array_merge(["Other (<fg=yellow>default</>)"], $services), 0));
     if (in_array($service, $services, true)) {
         foreach (self::HOSTING_SERVICE_DEFAULTS[$service] as $key => $value) {
             if (preg_match('/\\{{2} *([\\w\\.]+) *\\}{2}/', $value, $matches)) {
                 $data[$key] = str_replace($matches[0], $data[$matches[1]], $value);
             }
         }
     }
     return $data;
 }