$dispatcher = new sfEventDispatcher(); // ->initialize() $t->diag('->initialize()'); $request = new myRequest($dispatcher); $t->is($dispatcher, $request->getEventDispatcher(), '->initialize() takes a sfEventDispatcher object as its first argument'); $request->initialize($dispatcher, array('foo' => 'bar')); $t->is($request->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); $options = $request->getOptions(); $t->is($options['logging'], false, '->getOptions() returns options for request instance'); // ->getMethod() ->setMethod() $t->diag('->getMethod() ->setMethod()'); $request->setMethod(sfRequest::GET); $t->is($request->getMethod(), sfRequest::GET, '->getMethod() returns the current request method'); try { $request->setMethod('foo'); $t->fail('->setMethod() throws a sfException if the method is not valid'); } catch (sfException $e) { $t->pass('->setMethod() throws a sfException if the method is not valid'); } // ->extractParameters() $t->diag('->extractParameters()'); $request->initialize($dispatcher, array('foo' => 'foo', 'bar' => 'bar'));
public function basicGet($url, $data = NULL) { $token = $this->getToken(); if (!$token) { return false; } // $reqUrl = 'https://' . $this->host . $url; $request = new myRequest(); $request->setMethod(myRequest::METHOD_GET); // if ($data) { $request->setParameters($data); } // $request->setHeaders(['Content-type' => 'application/json', 'Authorization' => $token]); $response = $request->sendRequest($reqUrl); if ($response->getStatus() == myResponse::STATUS_FORBIDDEN) { // try to regenerate token $request->setHeaders(['Content-type' => 'application/json', 'Authorization' => $this->generateToken()]); // retry request $response = $request->sendRequest($reqUrl); } return $response->getBody(true); }