setName('domain:add') ->setDescription('Add a domain') ->addOption('name', null, InputOption::VALUE_REQUIRED, '') ->addOption('type', null, InputOption::VALUE_REQUIRED, '') ->addOption('master', null, InputOption::VALUE_REQUIRED, '') ->setHelp("The %command.name% "); } protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $name = $this->getInput()->getOption('name'); while (null === $name || trim($name) === '') { $name = $this->getHelper('dialog')->ask($this->getOutput(), 'Name: ', null); } $master = $this->getInput()->getOption('master'); if ($master === 'null') { $master = null; } elseif (null === $master || trim($master) === '') { $response = $this->getHelper('dialog')->ask($this->getOutput(), 'MASTER [null]: ', null); $master = empty($response) ? null : $response; } $type = $this->getInput()->getOption('type'); if ($type === 'null') { $type = null; } elseif (null === $type) { $response = $this->getHelper('dialog')->ask($this->getOutput(), 'Type [NATIVE]: ', null); $type = empty($response) ? 'NATIVE' : $response; } if (!$this->getHelper('validator')->isDomainMaster($master)) { $this->getOutput()->writeln('Invalid master.'); return; } if (!$this->getHelper('validator')->isDomainName($name)) { $this->getOutput()->writeln('Invalid name.'); return; } if (!$this->getHelper('validator')->isDomainType($type)) { $this->getOutput()->writeln('Invalid type.'); return; } if (DomainQuery::create()->findOneByName($name)) { $this->getOutput()->writeln('The domain already exists.'); return; } $domain = (new Domain()) ->setName($name) ->setMaster($master) ->setType($type); $domain->save(); $this->getOutput()->writeln('Domain added.'); } }