Example #1
0
 /**
  * isMatch
  * Trys to match the url of the request to this route
  * @param  string            $path    - the is the urldecoded path in the url
  * @param  \snb\http\Request $request
  * @return bool
  */
 public function isMatch($path, Request $request)
 {
     // See if it is a match for this route
     $regex = $this->getRegex();
     if (!preg_match($regex, $path, $regs)) {
         return false;
     }
     // OK, this URL is a good one
     // Check that the request method matches the route
     $method = $this->getMethod();
     $m = explode('|', mb_strtoupper($method));
     if (!in_array($request->getMethod(), $m)) {
         return false;
     }
     // Something similar for the protocol
     $protocol = $this->getProtocol();
     $p = explode('|', mb_strtolower($protocol));
     if (!in_array($request->getProtocol(), $p)) {
         return false;
     }
     // It is, so prepare the variables and create the controller
     $p = array();
     foreach ($this->vars as $key => $name) {
         // copy over the default value if there is one
         if (array_key_exists($name, $this->defaults)) {
             $p[$name] = $this->defaults[$name];
         }
         // replace it with the value from url, if it was included
         if (array_key_exists($key + 1, $regs)) {
             $p[$name] = $regs[$key + 1];
         }
     }
     // remember these, as someone it likely to want them very soon
     $this->matchedArgs = $p;
     $this->matchedUri = $request->getUri();
     // This route was a match
     return true;
 }