all() public method

public all ( $trim = false )
Beispiel #1
0
 public function __construct(ValueBag $values, ValueBag $extra, \Exception $error = null)
 {
     $this->values = $values->all();
     $this->valueBag = $values;
     $this->extra = $extra;
     $this->error = $error;
 }
Beispiel #2
0
 private function extractVariables($extractions, ValueBag $values = null, Crawler $crawler = null, RequestInterface $request, ResponseInterface $response)
 {
     if (null === $values) {
         throw new LogicException('Unable to extract variables if no ValueBag is registered.');
     }
     $variables = $this->createVariables($response, $crawler);
     foreach ($extractions as $name => $extract) {
         list($expression, $attributes) = $extract;
         if (!is_array($attributes)) {
             $attributes = [$attributes];
         }
         try {
             $data = $this->language->evaluate($expression, $variables + $values->all(true));
             if ($data instanceof Crawler) {
                 $value = $data->extract($attributes);
                 if (count($attributes) == 1) {
                     $data = count($data) > 1 ? $value : $value[0];
                 } else {
                     $data = $value;
                 }
             }
             $values->set($name, $data);
         } catch (ExpressionSyntaxError $e) {
             $msg = sprintf('Syntax Error in "%s": %s', $expression, $e->getMessage());
             $this->logger and $this->logger->critical($msg, ['request' => $request->getHeaderLine('X-Request-Id')]);
             throw new ExpectationErrorException($msg);
         }
     }
 }
Beispiel #3
0
 private function prepareRequest(Step $step, ValueBag $values, RequestInterface $request, $options)
 {
     $options['allow_redirects'] = false;
     if (!$step->getDelay()) {
         $options['delay'] = 0;
     } else {
         try {
             $options['delay'] = $this->language->evaluate($step->getDelay(), $values->all(true));
         } catch (ExpressionSyntaxError $e) {
             $msg = sprintf('Delay syntax error in "%s": %s', $step->getDelay(), $e->getMessage());
             $this->logger and $this->logger->critical($msg, ['request' => $request->getHeaderLine('X-Request-Id')]);
             throw new InvalidArgumentException($msg);
         }
     }
     unset($options['expectations']);
     if ($step->getExpectations()) {
         $options['expectations'] = $step->getExpectations();
     }
     unset($options['extractions']);
     if ($step->getExtractions()) {
         $options['extractions'] = $step->getExtractions();
     }
     foreach ($this->extensions as $extension) {
         $options = $extension->prepareRequest($step, $values, $request, $options);
     }
     return $options;
 }
Beispiel #4
0
 private function evaluateValues(ValueBag $values, $data)
 {
     if (is_string($data)) {
         return $this->language->evaluate($data, $values->all(false));
     }
     foreach ($data as $key => $value) {
         $data[$key] = $this->language->evaluate($value, $values->all(false));
     }
     return $data;
 }
 private function extractVariables($extractions, ValueBag $values = null, Crawler $crawler = null, RequestInterface $request, ResponseInterface $response)
 {
     if (null === $values) {
         throw new LogicException('Unable to extract variables if no ValueBag is registered.');
     }
     $variables = $this->createVariables($response, $crawler);
     foreach ($extractions as $name => $expression) {
         try {
             $data = $this->language->evaluate($expression, $variables + $values->all(true));
             if ($data instanceof Crawler) {
                 $data = $data->extract('_text');
                 $data = count($data) > 1 ? $data : $data[0];
             }
             $msg = sprintf('Extracting value form "%s": %s', $name, is_scalar($data) ? $data : '[Non-scalar-data]');
             $this->logger and $this->logger->debug($msg, ['request' => $request->getHeaderLine('X-Request-Id')]);
             $values->set($name, $data);
         } catch (ExpressionSyntaxError $e) {
             $msg = sprintf('Syntax Error in "%s": %s', $expression, $e->getMessage());
             $this->logger and $this->logger->critical($msg, ['request' => $request->getHeaderLine('X-Request-Id')]);
             throw new ExpectationErrorException($msg);
         }
     }
 }