Пример #1
0
 /**
  * Creates a log entry from the given request
  *
  * @param Slim\Http\Request $request The request
  *
  * @return \API\Document\Log The log document
  */
 public function logRequest($request)
 {
     $collection = $this->getDocumentManager()->getCollection('logs');
     $document = $collection->createDocument();
     $document->setIp($request->getIp());
     $document->setMethod($request->getMethod());
     $document->setEndpoint($request->getPathInfo());
     $currentDate = new \DateTime();
     $document->setTimestamp(Util\Date::dateTimeToMongoDate($currentDate));
     $document->save();
     return $document;
 }
Пример #2
0
 public function testSlimRequest()
 {
     $env = \Slim\Environment::mock(array('REQUEST_METHOD' => 'GET', 'X_REQUESTED_WITH' => 'foo', 'slim.input' => 'This is the body.', 'PATH_INFO' => '/bar/xyz'));
     $req = new \Slim\Http\Request($env);
     $this->assertEquals('GET', $req->getMethod());
     $slimRequest = new SlimRequest($req);
     $this->assertEquals('GET', $slimRequest->getMethod());
     $this->assertEquals('/bar/xyz', $slimRequest->getResource());
     $this->assertEquals('This is the body.', $slimRequest->getBody());
     $this->assertTrue($slimRequest->hasHeader('X_REQUESTED_WITH'));
     $this->assertEquals('foo', $slimRequest->getHeader('X_REQUESTED_WITH'));
 }
Пример #3
0
 /**
  * Test sets HTTP method
  */
 public function testGetMethod()
 {
     $env = \Slim\Environment::mock(array('REQUEST_METHOD' => 'GET'));
     $req = new \Slim\Http\Request($env);
     $this->assertEquals('GET', $req->getMethod());
 }
Пример #4
0
 /**
  * Combines the request and route parameters into one array for
  * Honeybadger notices.
  *
  * @param   Slim\Http\Request  $request
  * @return  array  The combined request and route parameters.
  */
 private function combined_params($request)
 {
     $router = $this->app->router();
     // Find the matching route for the request, to extract parameters for
     // routes such as: `/books/:id`.
     $router->getMatchedRoutes($request->getMethod(), $request->getPathInfo());
     if ($route = $router->getCurrentRoute()) {
         $params = $route->getParams();
     } else {
         $params = array();
     }
     // Merge the route and request parameters into one array.
     return Arr::merge($request->params(), $params);
 }