示例#1
0
 /**
  * Call
  *
  * Implements Slim middleware interface. This method is invoked and passed
  * an array of environemnt variables. This middleware inspects the environment
  * variables for the HTTP method override parameter; if found, this middleware
  * modifies the environment settings so downstream middleware and/or the Slim
  * application will treat the request with the desired HTTP method.
  *
  * @param   array $env
  * @return  array[status, header, body]
  */
 public function call(&$env)
 {
     if (isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'POST') {
         $req = new Slim_Http_Request($env);
         $method = $req->post($this->settings['key']);
         if ($method) {
             $env['slim.method_override.original_method'] = $env['REQUEST_METHOD'];
             $env['REQUEST_METHOD'] = strtoupper($method);
         }
     }
     return $this->app->call($env);
 }
示例#2
0
 /**
  * Call
  *
  * Implements Slim middleware interface. This method is invoked and passed
  * an array of environment variables. This middleware inspects the environment
  * variables for the HTTP method override parameter; if found, this middleware
  * modifies the environment settings so downstream middleware and/or the Slim
  * application will treat the request with the desired HTTP method.
  *
  * @param   array $env
  * @return  array[status, header, body]
  */
 public function call()
 {
     $env = $this->app->environment();
     if (isset($env['X_HTTP_METHOD_OVERRIDE'])) {
         // Header commonly used by Backbone.js and others
         $env['slim.method_override.original_method'] = $env['REQUEST_METHOD'];
         $env['REQUEST_METHOD'] = strtoupper($env['X_HTTP_METHOD_OVERRIDE']);
     } else {
         if (isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'POST') {
             // HTML Form Override
             $req = new Slim_Http_Request($env);
             $method = $req->post($this->settings['key']);
             if ($method) {
                 $env['slim.method_override.original_method'] = $env['REQUEST_METHOD'];
                 $env['REQUEST_METHOD'] = strtoupper($method);
             }
         }
     }
     $this->next->call();
 }
示例#3
0
文件: Post.php 项目: stojg/puny
 /**
  * savePost saves / creates a post
  *
  * @param Slim_Http_Request $request
  * @param \stojg\puny\Post $post
  */
 public static function save_post(\Slim_Http_Request $request, Post $post)
 {
     $post->setContent($request->post('content'))->setTitle($request->post('title'))->setDate($request->post('date'))->setCategories($request->post('categories'))->setDraft($request->post('draft'))->save('posts');
 }
示例#4
0
 /**
  * Test fetch POST params even if multipart/form-data request
  */
 public function testPostWithMultipartRequest()
 {
     $_POST = array('foo' => 'bar');
     //<-- Set by PHP
     $env = Slim_Environment::mock(array('REQUEST_METHOD' => 'POST', 'slim.input' => '', 'CONTENT_TYPE' => 'multipart/form-data', 'CONTENT_LENGTH' => 0));
     $req = new Slim_Http_Request($env);
     $this->assertEquals(1, count($req->post()));
     $this->assertEquals('bar', $req->post('foo'));
     $this->assertNull($req->post('xyz'));
 }
示例#5
0
 /**
  * Test fetch POST without slim.input
  */
 public function testPostWithoutInput()
 {
     $this->setExpectedException('RuntimeException');
     Slim_Environment::mock(array('REQUEST_METHOD' => 'POST', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '/foo/index.php', 'PATH_INFO' => '/bar/xyz', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.errors' => fopen('php://stderr', 'w'), 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => 15));
     $env = Slim_Environment::getInstance();
     $req = new Slim_Http_Request($env);
     $req->post('foo');
 }
示例#6
0
 /**
  * Test fetch POST without slim.input
  */
 public function testPostWithoutInput()
 {
     $this->setExpectedException('RuntimeException');
     $env = Slim_Environment::mock();
     unset($env['slim.input']);
     $req = new Slim_Http_Request($env);
     $req->post('foo');
 }
示例#7
0
 public function testParams()
 {
     //Case A: PUT params
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST = array('_METHOD' => 'PUT', 'foo1' => 'bar1');
     $r = new Slim_Http_Request();
     $this->assertEquals('bar1', $r->params('foo1'));
     $this->assertEquals('bar1', $r->put('foo1'));
     $this->assertEquals(array('foo1' => 'bar1'), $r->put());
     //Case B: POST params
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST = array('foo1' => 'bar1');
     $r = new Slim_Http_Request();
     $this->assertEquals('bar1', $r->params('foo1'));
     $this->assertEquals('bar1', $r->post('foo1'));
     $this->assertEquals($_POST, $r->post());
     //Case C: GET params
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_POST = array();
     $_GET = array('foo1' => 'bar1');
     $r = new Slim_Http_Request();
     $this->assertEquals('bar1', $r->params('foo1'));
     $this->assertEquals('bar1', $r->get('foo1'));
     $this->assertEquals($_GET, $r->get());
     //Case D: COOKIE params
     $_COOKIE['foo'] = 'bar';
     $r = new Slim_Http_Request();
     $this->assertEquals($_COOKIE, $r->cookies());
     $this->assertEquals('bar', $r->cookies('foo'));
     //Case E: NULL params
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_GET = array();
     $_POST = array();
     $r = new Slim_Http_Request();
     $this->assertNull($r->params('foo1'));
     $this->assertNull($r->put('foo1'));
     $this->assertNull($r->post('foo1'));
     $this->assertNull($r->get('foo1'));
     $this->assertNull($r->cookies('foo1'));
 }