public function run($inQuery, $args) { // Parsing user request $inQuery = $inQuery; $inDefaultFrom = $this->app->getDefault('from'); $inDefaultTo = $this->app->getDefault('to'); $out = array(); $objQuery = new e4QueryParser($this->app, $inQuery, $inDefaultFrom, $inDefaultTo); if ($objQuery->parse()) { $tmpFrom = $objQuery->getFrom(); $tmpTo = $objQuery->getTo(); $tmpAmount = $objQuery->getAmount(); if (count($tmpFrom) > 1) { foreach ($tmpFrom as $currency) { $suggest = $objQuery->getSuggestion('from', $currency); $out[] = array('uid' => $currency, 'arg' => 'none', 'title' => $suggest, 'subtitle' => e4Currency::currencyName($currency) . ' (' . $currency . ')', 'autocomplete' => $suggest, 'icon' => 'icon.png', 'valid' => 'no'); } } else { if (count($tmpTo) > 1) { foreach ($tmpTo as $currency) { $suggest = $objQuery->getSuggestion('to', $currency); $out[] = array('uid' => $currency, 'arg' => 'none', 'title' => $suggest, 'subtitle' => e4Currency::currencyName($currency) . ' (' . $currency . ')', 'autocomplete' => $suggest, 'icon' => 'icon.png', 'valid' => 'no'); } } else { $tmpResponse = new e4QuerySend($this->app, $tmpAmount, $tmpFrom[0], $tmpTo[0]); if ($tmpResponse->sendRequest()) { $out[] = array('uid' => 'none', 'arg' => $tmpResponse->getToAmount(), 'title' => implode(' ', array($tmpResponse->getFromAmount(), $tmpResponse->getFromCurrency(), '=', $tmpResponse->getToAmount(), $tmpResponse->getToCurrency())), 'subtitle' => 'Processed by ' . $tmpResponse->getService(), 'icon' => 'icon.png', 'valid' => 'yes'); } } } } // Invalid response matched if (!count($out)) { $out[] = array('uid' => 'none', 'arg' => 'none', 'title' => 'Invalid query ' . $inQuery, 'subtitle' => 'Try ‘12 €‘ or ‘12 € to $‘ or ‘€‘ and have fun!', 'icon' => 'icon.png', 'valid' => 'no'); } return $out; }
if ($objQuery->isValid() != $test['valid']) { // Unexpected different result $errors .= '{ e4QueryParser: ' . ($objQuery->isValid() ? 'parsed' : 'invalid') . ' } '; $errors .= '!= '; $errors .= '{ expected: ' . ($test['valid'] ? 'parsed' : 'invalid') . ' } '; } elseif ($objQuery->isValid()) { // Ok, both are valid; check every property foreach ($testData as $key => $type) { $newKey = $key . '.in'; switch ($type) { case 'currency': $getType = 'get' . ucfirst($key); $test[$newKey] = $objQuery->{$getType}(); break; case 'float': $test[$newKey] = $objQuery->getAmount(); break; } if ($test[$key] != $test[$newKey]) { $errors .= '{ ' . $key . ': '; $errors .= '{ e4QueryParser: ' . json_encode($test[$newKey]) . ' } '; $errors .= '!= '; $errors .= '{ expected: ' . json_encode($test[$key]) . ' } '; $errors .= ' } '; } } } echo $i . ': ' . ($errors ? $test['query'] . ' => ' . $errors : 'Passed!') . "\n"; if ($errors) { die(print_r($objQuery, true)); }