示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->output = $output;
     $this->loader = str_split('|/-\\|/-\\');
     $this->client = $this->getApplication()->getErpkClient();
     $this->managementModule = new ManagementModule($this->client);
     $this->marketModule = new MarketModule($this->client);
     $this->priceLimit = filter_var($input->getArgument('price'), FILTER_VALIDATE_FLOAT);
     if (!$this->priceLimit) {
         throw new Exception('Price is not a valid number.');
     }
     $this->scanInterval = filter_var($input->getOption('interval'), FILTER_VALIDATE_FLOAT);
     if (!$this->scanInterval) {
         throw new Exception('Interval is not a valid number.');
     }
     $this->amountToRefill = filter_var($input->getArgument('amount'), FILTER_VALIDATE_INT);
     if (!$this->amountToRefill) {
         throw new Exception('Amount is not a valid number.');
     }
     $em = EntityManager::getInstance();
     $countries = $em->getRepository('Erpk\\Common\\Entity\\Country');
     $industries = $em->getRepository('Erpk\\Common\\Entity\\Industry');
     $this->country = $countries->findOneByCode($input->getArgument('country'));
     if (!$this->country) {
         throw new Exception('Country code is invalid.');
     }
     $this->industry = $industries->findOneByCode($input->getArgument('industry'));
     if (!$this->industry) {
         throw new Exception('Industry is invalid. Available options: food, weapons, wrm, frm.');
     }
     $this->quality = filter_var($input->getArgument('quality'), FILTER_VALIDATE_INT);
     if (!$this->quality) {
         throw new Exception('Quality is not a valid number.');
     }
     $isRawMaterial = $this->industry->getCode() === 'wrm' || $this->industry->getCode() === 'frm';
     if ($isRawMaterial) {
         if ($this->quality !== 1) {
             throw new Exception('Quality for raw materials must be 1.');
         }
     } else {
         if ($this->quality < 1 || $this->quality > 7) {
             throw new Exception('Quality must be between 1 and 7.');
         }
     }
     $this->minimumAmount = (int) $input->getOption('minimum');
     $this->hunter();
 }
 /**
  * {@inheritDoc}
  */
 public function getCode()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCode', array());
     return parent::getCode();
 }