Пример #1
0
 /**
  * Returns true if the handler determines it should handle this request and false otherwise.
  * @param string $path The URL path for the request.
  * @param array $query The query parameters.
  * @param array $post The post data.
  * @param string $verb The HTTP verb used in the request.
  * @return boolean Returns true if this handler will handle the request and false otherwise.
  */
 public function isAppropriate($path, $query, $post, $verb)
 {
     // use the parent method to match the routes
     if (false === parent::isAppropriate($path, $query, $post, $verb)) {
         return false;
     }
     // determine the route information from the path
     $routeInfo = $this->getRouteInfo($verb, $path, true);
     $this->routeParams = array($routeInfo[2]['version']);
     if ($routeInfo[1] & self::MATCHES_ID) {
         $this->routeParams[] = intval($routeInfo[2]['objectId']);
     }
     return true;
 }
 /**
  * Tests that we can use folder provisioning to retrieve a controller.
  */
 public function testFolderProvisioning()
 {
     $options = array(Config::KEY_FOLDERS => array(realpath(__DIR__ . '/../Controller')), ControllerHandler::KEY_VIEWS => array(ControllerHandler::KEY_VIEWS_PATH => __DIR__ . '/../Controller/Views'));
     $handler = new ControllerHandler($options);
     $this->assertTrue($handler->isAppropriate('/nonNamespaced/test', array(), array(), 'GET'));
     $this->assertEquals('This is a test string.', $handler->performRoute());
 }
 /**
  * Tests that the whitelist can be the string 'all' instead of an array
  * allowing access to any service.
  */
 public function testWhitelistingAllActions()
 {
     // make it appear that we are generating a cross origin request
     $_SERVER['HTTP_ORIGIN'] = 'www.example.com';
     // some dummy variables that are needed by the plugin
     $handler = new ControllerHandler(array());
     $this->assertTrue($handler->isAppropriate('/testDummy', array(), array(), 'GET'));
     $plugin = new CrossOriginRequestPlugin(array('whitelist' => 'all'));
     try {
         $plugin->afterHandlerSelected($handler);
         $this->assertTrue(true);
     } catch (AccessDeniedException $e) {
         $this->fail('Cross origin plugin should not have denied access.');
     }
 }