コード例 #1
0
ファイル: Reference.php プロジェクト: devster/alice
 /**
  * {@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);
 }
コード例 #2
0
ファイル: Reference.php プロジェクト: reisraff/alice
 /**
  * {@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);
 }