/** * @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; }