/** * Callback used on add this attribute to an input * * @param InputInterface $input The input in which the attribute will be added * @param mixed $value The value of this attribute * * @return mixed $value The value sanitized */ public static function onAdd($input, $value) { if ($input->attr('multiple') && substr($value, -2) !== '[]') { $value .= '[]'; } return $value; }
protected function execute(InputInterface $input, OutputInterface $output) { $every = $this->validateDuration($input->getOption('every')); $needle = $input->getOption('search'); $timeout = $this->validateDuration($input->getOption('timeout')); $urls = $this->validateURLs($input->getOption('urls')); if (!$needle) { throw new InvalidArgumentException('Needle must be provided'); } $cycle = new MonitorCycle($urls, $timeout, $needle); while (true) { $last = new DateTimeImmutable(); $output->writeln(sprintf('<bg=green>%s</>', $last->format('Y-m-d H:i:s'))); list($success, $failed) = $cycle->run(); if ($output->isVerbose() && count($failed) > 0) { $output->writeln(sprintf('<fg=red>Failed URLs:</> %s', implode("\n ", $failed))); } $output->writeln(sprintf('<fg=green>%d</> successful; <fg=red>%d</> failed', count($success), count($failed))); $output->writeln(''); $next = $last->add(new DateInterval("PT{$every}S")); do { sleep(1); } while (new DateTimeImmutable() < $next); } }
/** * Validates the input value according to this attribute * * @param InputInterface $input The input to validate * * @return string|true True if its valid, string with the error if not */ public static function validate($input) { $value = $input->val(); //File if ($input->attr('type') === 'file') { $value = isset($value['name']) ? $value['name'] : null; } $attr = str_replace('/', '\\/', $input->attr('pattern')); return empty($attr) || empty($value) || filter_var($value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^{$attr}\$/"))) ? true : sprintf(static::$error_message, $attr); }
/** * Callback used on add this attribute to an input * * @param InputInterface $input The input in which the attribute will be added * @param mixed $value The value of this attribute * * @return mixed $value The value sanitized */ public static function onAdd($input, $value) { if (!is_bool($value)) { throw new \InvalidArgumentException('The multiple value must be a boolean'); } if ($value && ($name = $input->attr('name')) && substr($name, -2) !== '[]') { $input->attr('name', $name . '[]'); } return $value; }
/** * Validates the input value according to this attribute * * @param InputInterface $input The input to validate * * @return string|true True if its valid, string with the error if not */ public static function validate($input) { $value = $input->val(); //File if ($input->attr('type') === 'file') { $value = isset($value['name']) && !empty($value['size']) ? $value['name'] : null; } $attr = $input->attr('required'); return empty($attr) || !empty($value) || strlen($value) > 0 ? true : sprintf(static::$error_message, $attr); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->satisUpdater->setOutput($output); // get sync manager $composerJsonFile = $input->getArgument('composerJsonFile'); $apiEndpoint = $input->getArgument('apiEndpoint'); $rewrite = $input->getOption('rewrite'); $this->satisUpdater->setComposerJsonFile($composerJsonFile); $this->satisUpdater->setApiEndpoint($apiEndpoint); $this->satisUpdater->update($rewrite); }
/** * Starts processing. * * @param \Elegant\Cli\Io\InputInterface $input * @param \Elegant\Cli\Io\OutputInterface $output */ public final function process(InputInterface $input, OutputInterface $output) { $commandName = $input->getArgument(1); if (null === $commandName) { return; } $command = $this->getCommandCollection()->get($commandName); if (null === $command) { return; } $this->registerCommand($command); $callback = $command->getCallback(); $this->getContainer()->call($callback, [$input, $output]); }
/** * Execute command * * @param InputInterface $input * @param OutputInterface $output * * @return void */ public function execute(InputInterface $input, OutputInterface $output) { try { $command = $input->getArgument('cmd'); switch ($command) { case 'start': $this->start($output); break; case 'stop': $this->stop($output); break; } } catch (\EngineException $e) { $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); } }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $logger = new ConsoleLogger($output); $questionAsker = new QuestionAsker($this->getHelper('question'), $input, $output); try { $targetDir = call_user_func_array($this->dirValidatorFactory, [$questionAsker, $this->filesystem])->validateValue($input->getArgument('path')); $data = call_user_func_array($this->dataProviderFactory, [$questionAsker])->getData(); $assets = call_user_func_array($this->assetCollectionFactory, [$this->filesystem, $data]); $assets->exportToDir($targetDir); } catch (\Exception $e) { if ($output->isDebug()) { throw $e; } $logger->error($e->getMessage()); return Application::EXIT_CODE_MAPPING[get_class($e)] ?? Application::EXIT_CODE_UNKOWN_ERROR; } }
protected function marshallInput(InputInterface $input) : string { $inputFile = $input->getArgument('file'); if ($inputFile) { Assertion::file($inputFile); $inputBuffer = file_get_contents($inputFile); } else { $inputBuffer = ''; $stdin = fopen('php://stdin', 'r'); stream_set_blocking($stdin, false); while ($line = fgets($stdin)) { $inputBuffer .= $line; } } Assertion::notEmpty($inputBuffer, 'Input must not be empty'); return $inputBuffer; }
/** * Compile partials into procedure. * * @access public * @param \JonnyW\PhantomJs\Procedure\ProcedureInterface $procedure * @param \JonnyW\PhantomJs\Procedure\InputInterface $input * @return void */ public function compile(ProcedureInterface $procedure, InputInterface $input) { $cacheKey = sprintf('phantomjs_%s_%s', $input->getType(), md5($procedure->getTemplate())); if ($this->cacheEnabled && $this->cacheHandler->exists($cacheKey)) { $template = $this->cacheHandler->fetch($cacheKey); } if (empty($template)) { $template = $this->renderer->render($procedure->getTemplate(), array('engine' => $this, 'procedure_type' => $input->getType())); $test = clone $procedure; $test->setTemplate($template); $compiled = $test->compile($input); $this->procedureValidator->validate($compiled); if ($this->cacheEnabled) { $this->cacheHandler->save($cacheKey, $template); } } $procedure->setTemplate($template); }
protected function execute(InputInterface $input, OutputInterface $output) { $date = $input->getArgument("expiredDate"); $checkDate = $date instanceof \DateTime ? $date : new \DateTime($date); $checkDate->setTime(0, 0, 0); $em = $this->getContainer()->get('doctrine')->getEntityManager(); $entities = $em->getRepository('BraemCRMBundle:Lead')->deleteExpiredLeads($checkDate); if ($entities) { $count = count($entities); foreach ($entities as $entity) { $em->remove($entity); $output->writeln('Removed lead #' . $entity->getId()); } $em->flush(); $output->writeln($count . ' leads were successfully removing'); } else { $output->writeln('Nothing to remove'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $time_start = $this->microtime_float(); $output->writeln('<comment>START delete process</comment>'); if ($input->getOption('account')) { $output->writeln('<info>Safe accounts delete using ID</info>'); $ids = explode(",", $input->getOption('account')); foreach ($ids as $accountId) { $helper = new ImportAccountsHelper($this->getContainer()->get('doctrine')->getEntityManager()); $deleteResult = $helper->deleteAccount($accountId); $output->writeln($deleteResult); } } if ($input->getOption('file')) { $output->writeln('<info>Safe accounts delete using file: ' . $input->getOption('file') . '</info>'); $file = $input->getOption('file'); $parser = new AccountParser($file); $helper = new ImportAccountsHelper($this->getContainer()->get('doctrine')->getEntityManager()); while (count($accounts = $parser->getData()) > 0) { foreach ($accounts as $account) { $accountId = $account[1]; $deleteResult = $helper->deleteAccount($accountId); $output->writeln($deleteResult); } } } $time_end = $this->microtime_float(); $time = $time_end - $time_start; $output->writeln('<comment>END import process(' . $time . ' sec)</comment>'); }
public function __construct($name, $default = null, $enabled = null, $auto = true) { if (null !== $default) { if (is_numeric($default)) { $default = (int) $default; } else { $default = $default->Timestamp(); } } parent::__construct($name, $default, $enabled, $auto); get_instance()->main_frame->includeJs('javascript/simple_ajax.js'); get_instance()->main_frame->includeJs('javascript/calendar_termdates.js'); get_instance()->main_frame->includeJs('javascript/css_classes.js'); get_instance()->main_frame->includeJs('javascript/input_selector.js'); get_instance()->main_frame->includeJs('javascript/input_date.js'); get_instance()->main_frame->includeCss('stylesheets/input_selector.css'); get_instance()->main_frame->includeCss('stylesheets/input_date.css'); get_instance()->main_frame->includeCss('stylesheets/input_date-iefix.css', null, null, 'IE'); get_instance()->main_frame->includeCss('stylesheets/calendar.css'); $this->div_classes[] = 'input_date'; }
/** * Helper method to get input option * * @param string $name * @return mixed */ public function opt(string $name) { return $this->input->getOption($name); }
/** * @param InputInterface $input * @param DrupalStyle $io */ protected function registerMigrateDB(InputInterface $input, DrupalStyle $io) { $dbType = $input->getOption('db-type'); $dbHost = $input->getOption('db-host'); $dbName = $input->getOption('db-name'); $dbUser = $input->getOption('db-user'); $dbPass = $input->getOption('db-pass'); $dbPrefix = $input->getOption('db-prefix'); $dbPort = $input->getOption('db-port'); $this->addDBConnection($io, 'upgrade', 'default', $dbType, $dbName, $dbUser, $dbPass, $dbPrefix, $dbPort, $dbHost); }
/** * @return bool */ private function listBrobOption() { return strtolower($this->input->getOption('list-brob')) == 'true'; }
/** * @param \Drupal\Console\Command\Database\InputInterface $input * @param \Drupal\Console\Style\DrupalStyle $output */ protected function registerMigrateDB(InputInterface $input, DrupalStyle $output) { $db_type = $input->getOption('db-type'); $db_host = $input->getOption('db-host'); $db_name = $input->getOption('db-name'); $db_user = $input->getOption('db-user'); $db_pass = $input->getOption('db-pass'); $db_prefix = $input->getOption('db-prefix'); $db_port = $input->getOption('db-port'); $this->addDBConnection($output, 'migrate', 'default', $db_type, $db_name, $db_user, $db_pass, $db_prefix, $db_port, $db_host); // Set static container to static Drupal method to get services available Issue: https://github.com/hechoendrupal/DrupalConsole/issues/1129 \Drupal::setContainer($this->getContainer()); }
/** * Validates the input value according to this attribute * * @param InputInterface $input The input to validate * * @return string|true True if its valid, string with the error if not */ public static function validate($input) { $value = $input->val(); $attr = $input->attr('maxlength'); return empty($attr) || strlen($value) <= $attr ? true : sprintf(static::$error_message, $attr); }
/** * Validates the input value according to this attribute * * @param InputInterface $input The input to validate * * @return string|true True if its valid, string with the error if not */ public static function validate($input) { $value = $input->val(); $attr = $input->attr('min'); return strlen($value) === 0 || $value >= $attr ? true : sprintf(static::$error_message, $attr); }
protected function parseInput($line, InputInterface $input) { $input->reset(); for ($size = strlen($line), $i = 0; $i < $size; $i++) { if (trim($line[$i]) === '') { continue; } if ($line[$i] == '-') { $i++; if ($i >= $size) { throw new \InvalidArgumentException(sprintf('Invalid command: "%s"', $line)); } if ($line[$i] != '-') { if (preg_match("'[a-z]+'i", substr($line, $i), $m)) { foreach (str_split($m[0], 1) as $flag) { $input->setOption($flag, true); $i++; } } else { throw new \InvalidArgumentException(''); } } elseif (preg_match("'^([^-=\\s]+)(\\s*=\\s*)?'", substr($line, ++$i), $match)) { $hasValue = isset($match[2]) && trim($match[2]) !== ''; $i += strlen($match[1]); if ($hasValue) { $i++; if ($line[$i] == '"') { if (preg_match("'\"((?:[^\"]|\\\")*)\"'", substr($line, $i), $m)) { $input->setOption($match[1], $m[1]); $i += strlen($m[0]); } else { throw new \InvalidArgumentException(''); } } elseif (preg_match("'\\S+'", substr($line, $i), $m)) { $input->setOption($match[1], $m[0]); $i += strlen($m[0]); } else { $input->setOption($match[1], ''); } } else { $input->setOption($match[1], true); } } continue; } if ($line[$i] == '"') { if (preg_match("'\"((?:[^\"]|\\\")*)\"'", substr($line, $i), $m)) { $input->addArgument($m[1]); $i += strlen($m[0]); } else { throw new \InvalidArgumentException(''); } } elseif (preg_match("'\\S+'", substr($line, $i), $m)) { $input->addArgument($m[0]); $i += strlen($m[0]); } } }
protected function _Equal($v1, $v2) { if ($this->Multiple()) { $d1 = array_diff($v1, $v2); $d2 = array_diff($v2, $v1); return empty($d1) && empty($d2); } else { return parent::_Equal($v1, $v2); } }