/** * 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. * * @return array[status, header, body] */ public function call() { $env = $this->app->environment(); if (isset($env['HTTP_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['HTTP_X_HTTP_METHOD_OVERRIDE']); } elseif (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(); }
/** * 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')); }
function postAll() { return $this->slimRequest->post(); }