示例#1
0
 public function getProcessedResponse(Request $req = null, Error $err = null)
 {
     $this->d('Module.getProcessedResponse(' . ($req ? '`' . $req->method . ' ' . $this->config->get('uri', $req->uri) . '`' : 'NULL') . ')');
     $topLevelApp = $this->getMaster();
     if (static::STATE_DONE !== $topLevelApp->getState()) {
         foreach ($this->routes as $params) {
             $params += array('pattern' => null);
             $matchParams = array();
             if (!$params['pattern'] || is_array($matchParams = RequestMatcher::matches($req, $params))) {
                 $topLevelApp->setState(static::STATE_DONE);
                 return $this->process($req, $this->getNextResponse($req, $err), $params, $matchParams);
             }
         }
     }
     return $this->getNextResponse($req, $err);
 }
示例#2
0
 public function resolve(Request $req = null)
 {
     switch ($this->state) {
         case static::STATE_IDLE:
             $next = $this;
             $hasLayers = false;
             foreach ($this->stack as $params) {
                 $params += array('pattern' => null, 'class' => null, 'instance' => null, 'config' => array());
                 $match = array();
                 if (!$params['pattern'] || is_array($match = RequestMatcher::matches($req, $params, $this->config['uri']))) {
                     $this->d('MATCH PARAMS ', $match);
                     $hasLayers = true;
                     $instance = $this->resolveLayer($params, $next);
                     $instance->configure($params['config'] + $match);
                     $next = $instance;
                 }
             }
             $this->setState(static::STATE_LOOP);
             return $hasLayers ? $next : null;
         default:
             return null;
     }
 }
 public function testNonmatchingMethod()
 {
     $req = new Request('POST', '/test');
     $params = array('method' => 'GET', 'pattern' => '/test');
     $this->assertFalse(RequestMatcher::matches($req, $params));
 }