Ejemplo n.º 1
0
 /**
  * compares the threshold to a randomly generated value to determine whether
  *
  * @param ProcessableInterface $processable
  * @return
  */
 private function shouldReturnTrue(ProcessableInterface $processable)
 {
     $threshold = $processable->getMatch('threshold');
     if (substr($threshold, -1) === '%') {
         $threshold = substr($threshold, 0, -1) / 100;
     }
     return $threshold > 0 && mt_rand(0, 100) / 100 <= $threshold;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function process(ProcessableInterface $processable, array $variables)
 {
     $values = $processable->getValue();
     foreach ($values as $key => $value) {
         $values[$key] = $this->processor->process($value, $variables);
     }
     return $values;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function process(ProcessableInterface $processable, array $variables)
 {
     $value = $processable->getValue();
     return preg_replace_callback('#<\\{([a-z0-9_\\.-]+)\\}>#i', function ($matches) {
         $key = $matches[1];
         if (!$this->parameters->has($key)) {
             throw new \UnexpectedValueException(sprintf('Parameter "%s" was not found', $key));
         }
         if (is_array($value = $this->parameters->get($key))) {
             return var_export($value, true);
         }
         return $value;
     }, $value);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function process(ProcessableInterface $processable, array $variables)
 {
     $multi = '' !== $processable->getMatch('multi') ? $processable->getMatch('multi') : null;
     $property = !is_null($processable->getMatch('property')) ? $processable->getMatch('property') : null;
     if (strpos($processable->getMatch('reference'), '*')) {
         return $this->objects->random($processable->getMatch('reference'), $multi, $property);
     }
     if (null !== $multi) {
         throw new \UnexpectedValueException('To use multiple references you must use a mask like "' . $processable->getMatch('multi') . 'x @user*", otherwise you would always get only one item.');
     }
     return $this->objects->find($processable->getMatch('reference'), $property);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 public function process(ProcessableInterface $processable, array $variables)
 {
     $fakerRegex = '<(?:(?<locale>[a-z]+(?:_[a-z]+)?):)?(?<name>[a-z0-9_]+?)?\\((?<args>(?:[^)]*|\\)(?!>))*)\\)>';
     if ($processable->valueMatches('#^' . $fakerRegex . '$#i')) {
         return $this->replacePlaceholder($processable->matches, $variables);
     } else {
         // format placeholders inline
         $that = $this;
         return preg_replace_callback('#' . $fakerRegex . '#i', function ($matches) use($that, $variables) {
             return $that->replacePlaceholder($matches, $variables);
         }, $processable->getValue());
     }
 }
Ejemplo n.º 6
0
 /**
  * this custom processor uppercases matching values
  */
 public function process(ProcessableInterface $processable, array $variables)
 {
     return strtoupper($processable->getMatch('uppercaseMe'));
 }
Ejemplo n.º 7
0
 /**
  * {@inheritDoc}
  */
 public function process(ProcessableInterface $processable, array $variables)
 {
     $multi = '' !== $processable->getMatch('multi') ? $processable->getMatch('multi') : null;
     $property = !is_null($processable->getMatch('property')) ? $processable->getMatch('property') : null;
     $sequence = !is_null($processable->getMatch('sequence')) ? $processable->getMatch('sequence') : null;
     if (strpos($reference = $processable->getMatch('reference'), '*')) {
         return $this->objects->random($reference, $multi, $property);
     }
     if ($sequence && ($reference = $processable->getMatch('reference'))) {
         $from = $processable->getMatch('from');
         $to = $processable->getMatch('to');
         $set = [];
         foreach (range($from, $to) as $id) {
             $set[] = $this->objects->get($reference . $id);
         }
         return $set;
     }
     if (null !== $multi) {
         throw new \UnexpectedValueException('To use multiple references you must use a mask like "' . $processable->getMatch('multi') . 'x @user*", otherwise you would always get only one item.');
     }
     return $this->objects->find($processable->getMatch('reference'), $property);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritDoc}
  */
 public function process(ProcessableInterface $processable, array $variables)
 {
     $value = $processable->getValue();
     return preg_replace('{\\\\([@\\\\])}', '$1', $value);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritDoc}
  */
 public function process(ProcessableInterface $processable, array $variables)
 {
     $value = $processable->getValue();
     return str_replace('\\@', '@', $value);
 }