Пример #1
0
 /**
  * @param Request $request
  * @param $context
  * @return Destination
  */
 public function route(Request $request, Destination $context = null)
 {
     $result = new Destination();
     $pattern = $this->getNeedle();
     $subject = $this->matchSubject($request, $context);
     $source = $this->getSource();
     $offset = strlen($pattern);
     $isPartial = $this->isPartial();
     if ($source == 'host') {
         // Suffix matching:
         $part = $isPartial ? substr($subject, -$offset) : $subject;
         $match = $part == $pattern;
         $result->setMatch($match);
         if ($match) {
             $result->setParams(clone $this->getDefaults());
             $result->setRemainder($isPartial ? substr($subject, 0, $offset) : false);
         }
     } else {
         // Prefix matching:
         $part = $isPartial ? substr($subject, 0, $offset) : $subject;
         $match = $part == $pattern;
         $result->setMatch($match);
         if ($match) {
             $result->setParams(clone $this->getDefaults());
             $result->setRemainder($isPartial ? substr($subject, $offset) : false);
         }
     }
     $result->setFinal(!$result->getRemainder());
     return $result;
 }
Пример #2
0
 /**
  * @param Request $request
  * @param Destination $context
  */
 public function route(Request $request, Destination $context = null)
 {
     $matchinfo = null;
     $result = new Destination();
     $pattern = $this->getRegex();
     $subject = $this->matchSubject($request, $context);
     if (preg_match($pattern, $subject, $matchinfo, PREG_OFFSET_CAPTURE)) {
         $result->setMatch(true);
         $params = $this->matchParams($matchinfo);
         $offset = $matchinfo[0][1];
         $length = strlen($matchinfo[0][0]);
         $remainder = substr($subject, 0, $offset) . substr($subject, $offset + $length);
         $result->setFinal(!$remainder);
         $result->setRemainder($remainder);
         $this->processParams($result, $params);
     }
     return $result;
 }