/** * Add request * @param \Curl\Request $request */ public function addRequest(Request $request) { $reflection = new \ReflectionClass($request); if (!empty($this->commonRequestOptions)) { $possibleCurlOpts = array(); $eventTypes = Request::getAvailableEventTypes(); foreach ($this->commonRequestOptions as $k => $p) { if (is_string($k)) { try { if ($reflection->hasMethod($m = 'set' . ucfirst($k))) { // try to set param call_user_func_array(array($request, $m), (array) $p); } else { if (isset($eventTypes[strtolower($k)])) { // try to attach event handler $request->on(strtolower($k), $p); } } } catch (\Exception $e) { // TODO add debug mode trigger_error('Invalid param in common options. Error: ' . $e->getMessage(), E_USER_NOTICE); } } else { if (is_numeric($k)) { $possibleCurlOpts[$k] = $p; } } } // end foreach // try to set cURL option $request->setOptions($possibleCurlOpts); } $this->requests[] = $request; return $this; }
/** * Test setOptions() and getOptions() methods */ public function testSetGetOptions() { $req = new cURL\Request(); $opts = $req->getOptions(); $this->assertInstanceOf('cURL\\Options', $opts); $this->assertEmpty($opts->toArray()); $opts = new cURL\Options(); $opts->set(CURLOPT_RETURNTRANSFER, true); $req->setOptions($opts); $this->assertEquals($opts, $req->getOptions()); }