/** * 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; }
/** * {@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); }
/** * this custom processor uppercases matching values */ public function process(ProcessableInterface $processable, array $variables) { return strtoupper($processable->getMatch('uppercaseMe')); }
/** * {@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); }