Example #1
0
 /**
  * Processes a URI and extracts the information
  *
  * @param string $uri
  * @return array
  */
 public function handle($uri)
 {
     $variableList = PatternMatcher::extract($uri, $this->pattern);
     // Now check for some given params in the routes scheme file
     // Overwrites any values obtained from URL
     if ($this->parameters) {
         foreach ($this->parameters as $parameterName => $parameterValue) {
             $variableList[$parameterName] = $parameterValue;
         }
     }
     // Now check if there are requirements
     if ($this->requirements) {
         foreach ($this->requirements as $variableField => $requirement) {
             foreach ($requirement as $req_type => $req_value) {
                 switch ($req_type) {
                     case 'type':
                         if (gettype($variableList[$variableField]) != $req_value) {
                             return false;
                         }
                         break;
                     default:
                         trigger_error('Requirement type ' . $requirement . ' does not exist');
                         break;
                 }
             }
         }
     }
     $variableList['target'] = $this->target;
     $variableList['route'] = $this;
     return $variableList;
 }
 /**
  * @dataProvider dataRoutes
  */
 public function testRoutePatternExtraction($string, $pattern, $expOutput)
 {
     self::assertEquals($expOutput, PatternMatcher::extract($string, $pattern));
 }