Implemented strict http request serialization for APIs that forbid a session to be used in concurrent requests (e.g. dedimania).
Updated all API requests in DedimaniaPlugin to be serialized by this mechanism. Closes #139.
This commit is contained in:
		| @@ -19,6 +19,11 @@ class Request extends EventDispatcher implements RequestInterface | ||||
|      * @var Options Object containing options for current request | ||||
|      */ | ||||
|     protected $options = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * @var bool Whether requests to the target host should be serialized or not. | ||||
| 	 */ | ||||
|     protected $serializeRequests = false; | ||||
|      | ||||
|     /** | ||||
|      * Create new cURL handle | ||||
| @@ -121,7 +126,8 @@ class Request extends EventDispatcher implements RequestInterface | ||||
| 	 * @param \cURL\RequestsQueue $requestsQueue | ||||
| 	 * @throws \cURL\Exception | ||||
| 	 */ | ||||
| 	public function attachTo(RequestsQueue $requestsQueue) { | ||||
| 	public function attachTo(RequestsQueue $requestsQueue) | ||||
| 	{ | ||||
| 		if (isset($this->queue)) { | ||||
| 			throw new Exception('Already bound to a RequestQueue.'); | ||||
| 		} | ||||
| @@ -129,6 +135,24 @@ class Request extends EventDispatcher implements RequestInterface | ||||
| 		$this->queue->attach($this); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Whether to serialize requests to the same host or not. | ||||
| 	 * | ||||
| 	 * @param bool $serialize | ||||
| 	 */ | ||||
| 	public function setSerialize($serialize = true) | ||||
| 	{ | ||||
| 		$this->serializeRequests = $serialize; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @return bool | ||||
| 	 */ | ||||
| 	public function getSerialize() | ||||
| 	{ | ||||
| 		return $this->serializeRequests; | ||||
| 	} | ||||
|  | ||||
|     /** | ||||
|      * Creates new RequestsQueue with single Request attached to it | ||||
|      * and calls RequestsQueue::socketPerform() method. | ||||
|   | ||||
| @@ -217,4 +217,12 @@ class RequestsQueue extends EventDispatcher implements RequestsQueueInterface, \ | ||||
| 		} | ||||
| 		return curl_multi_select($this->mh, $timeout) !== -1; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param $option | ||||
| 	 * @param $value | ||||
| 	 */ | ||||
| 	public function setOption($option, $value) { | ||||
| 		curl_multi_setopt($this->mh, $option, $value); | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user