Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Wei\Validator\All
  • Wei\Validator\AllOf
  • Wei\Validator\Alnum
  • Wei\Validator\Alpha
  • Wei\Validator\BaseValidator
  • Wei\Validator\Between
  • Wei\Validator\Blank
  • Wei\Validator\Callback
  • Wei\Validator\CharLength
  • Wei\Validator\Chinese
  • Wei\Validator\Color
  • Wei\Validator\Contains
  • Wei\Validator\CreditCard
  • Wei\Validator\Date
  • Wei\Validator\DateTime
  • Wei\Validator\Decimal
  • Wei\Validator\Digit
  • Wei\Validator\Dir
  • Wei\Validator\DivisibleBy
  • Wei\Validator\DoubleByte
  • Wei\Validator\Email
  • Wei\Validator\EndsWith
  • Wei\Validator\EqualTo
  • Wei\Validator\Exists
  • Wei\Validator\FieldExists
  • Wei\Validator\File
  • Wei\Validator\GreaterThan
  • Wei\Validator\GreaterThanOrEqual
  • Wei\Validator\IdCardCn
  • Wei\Validator\IdCardHk
  • Wei\Validator\IdCardMo
  • Wei\Validator\IdCardTw
  • Wei\Validator\IdenticalTo
  • Wei\Validator\Image
  • Wei\Validator\In
  • Wei\Validator\Ip
  • Wei\Validator\Length
  • Wei\Validator\LessThan
  • Wei\Validator\LessThanOrEqual
  • Wei\Validator\Lowercase
  • Wei\Validator\Luhn
  • Wei\Validator\MaxLength
  • Wei\Validator\MinLength
  • Wei\Validator\MobileCn
  • Wei\Validator\NaturalNumber
  • Wei\Validator\NoneOf
  • Wei\Validator\Null
  • Wei\Validator\Number
  • Wei\Validator\OneOf
  • Wei\Validator\Password
  • Wei\Validator\Phone
  • Wei\Validator\PhoneCn
  • Wei\Validator\PlateNumberCn
  • Wei\Validator\PositiveInteger
  • Wei\Validator\PostcodeCn
  • Wei\Validator\Present
  • Wei\Validator\QQ
  • Wei\Validator\RecordExists
  • Wei\Validator\Regex
  • Wei\Validator\Required
  • Wei\Validator\SomeOf
  • Wei\Validator\StartsWith
  • Wei\Validator\Time
  • Wei\Validator\Tld
  • Wei\Validator\Type
  • Wei\Validator\Uppercase
  • Wei\Validator\Url
  • Wei\Validator\Uuid
  • Overview
  • Namespace
  • Function
  1: <?php
  2: 
  3: namespace Wei;
  4: 
  5: /**
  6:  * An HTTP client that inspired by jQuery Ajax
  7:  *
  8:  * @author      Twin Huang <twinhuang@qq.com>
  9:  */
 10: class Http extends Base implements \ArrayAccess, \Countable, \IteratorAggregate
 11: {
 12:     /**
 13:      * The request URL
 14:      *
 15:      * @var string
 16:      */
 17:     protected $url;
 18: 
 19:     /**
 20:      * The HTTP request method
 21:      *
 22:      * The method could be `GET`, `POST`, `DELETE`, `PUT`, `PATCH` or any other
 23:      * methods that the server is supported
 24:      *
 25:      * @var string
 26:      */
 27:     protected $method = 'GET';
 28: 
 29:     /**
 30:      * The content type in HTTP request header
 31:      *
 32:      * @var string
 33:      */
 34:     protected $contentType;
 35: 
 36:     /**
 37:      * A key-value array to store cookies
 38:      *
 39:      * @var array
 40:      */
 41:     protected $cookies = array();
 42: 
 43:     /**
 44:      * The data to send to the server
 45:      *
 46:      * @var array|string
 47:      */
 48:     protected $data = array();
 49: 
 50:     /**
 51:      * The files send to the server
 52:      *
 53:      * @var array
 54:      */
 55:     protected $files = array();
 56: 
 57:     /**
 58:      * Whether use the global options in `$wei->http` object when create a
 59:      * new object
 60:      *
 61:      * @var bool
 62:      */
 63:     protected $global = false;
 64: 
 65:     /**
 66:      * A key-value array to store request headers
 67:      *
 68:      * @var array
 69:      */
 70:     protected $headers = array();
 71: 
 72:     /**
 73:      * Whether includes the header in the response string,
 74:      * equals the CURLOPT_HEADER option
 75:      * Set to true when you need to call getResponseHeaders, getResponseHeader,
 76:      * getResponseCookies or getResponseCookie methods
 77:      *
 78:      * @var bool
 79:      */
 80:     protected $header = false;
 81: 
 82:     /**
 83:      * The IP address for the host name in URL, NOT your client IP
 84:      *
 85:      * @var string
 86:      */
 87:     protected $ip;
 88: 
 89:     /**
 90:      * A number of milliseconds to wait in the whole connection
 91:      *
 92:      * @var int
 93:      */
 94:     protected $timeout;
 95: 
 96:     /**
 97:      * The data type to parse the response body
 98:      *
 99:      * The data type could by `json`, `jsonObject`, `xml`, `query`(URL query string),
100:      * `serialize` and `text`
101:      *
102:      * @var string
103:      */
104:     protected $dataType = 'text';
105: 
106:     /**
107:      * The custom HTTP referer string
108:      *
109:      * If set to true, it will use the request URL as referer string
110:      *
111:      * @var string|true
112:      */
113:     protected $referer;
114: 
115:     /**
116:      * The custom HTTP user agent string
117:      *
118:      * @var string
119:      */
120:     protected $userAgent;
121: 
122:     /**
123:      * Whether throw exception or keep silent when request error
124:      *
125:      * Note that the exception is thrown after triggered complete callback, rather than triggered error callback
126:      *
127:      * @var bool
128:      */
129:     protected $throwException = true;
130: 
131:     /**
132:      * A callback triggered after prepared the data and before the process the request
133:      *
134:      * @var callable
135:      */
136:     protected $beforeSend;
137: 
138:     /**
139:      * A callback triggered after the request is called success
140:      *
141:      * @var callable
142:      */
143:     protected $success;
144: 
145:     /**
146:      * A callback triggered when the request fails
147:      *
148:      * The `$textStatus` could be `curl`, `http`, and `parser`
149:      *
150:      * @var callable
151:      */
152:     protected $error;
153: 
154:     /**
155:      * A callback triggered when request finishes (after `success` and `error` callbacks are executed)
156:      *
157:      * @var callable
158:      */
159:     protected $complete;
160: 
161:     /**
162:      * The user define options for cURL handle
163:      *
164:      * @var array
165:      */
166:     protected $curlOptions = array();
167: 
168:     /**
169:      * The predefined options for cURL handle
170:      *
171:      * @var array
172:      */
173:     protected $defaultCurlOptions = array(
174:         CURLOPT_RETURNTRANSFER => true,
175:         CURLOPT_FOLLOWLOCATION => true,
176:     );
177: 
178:     /**
179:      * The request result
180:      *
181:      * @var bool
182:      */
183:     protected $result;
184: 
185:     /**
186:      * The response body string
187:      *
188:      * @var string
189:      */
190:     protected $responseText;
191: 
192:     /**
193:      * The parsed response data
194:      *
195:      * @var mixed
196:      */
197:     protected $response;
198: 
199:     /**
200:      * The response header string
201:      *
202:      * @var string
203:      */
204:     protected $responseHeader;
205: 
206:     /**
207:      * The parsed response header array
208:      *
209:      * @var string
210:      */
211:     protected $responseHeaders;
212: 
213:     /**
214:      * A key-value array contains the response cookies
215:      *
216:      * @var array
217:      */
218:     protected $responseCookies;
219: 
220:     /**
221:      * The cURL session
222:      *
223:      * @var resource
224:      */
225:     protected $ch;
226: 
227:     /**
228:      * The error text status
229:      *
230:      * @var string
231:      */
232:     protected $errorStatus = '';
233: 
234:     /**
235:      * The error exception object
236:      *
237:      * @var \ErrorException
238:      */
239:     protected $errorException;
240: 
241:     /**
242:      * The default options of current object
243:      *
244:      * @var array
245:      */
246:     private $defaultOptions;
247: 
248:     /**
249:      * Constructor
250:      *
251:      * @param array $options
252:      */
253:     public function __construct(array $options = array())
254:     {
255:         // Merges options from default HTTP service
256:         if (isset($options['global']) && true == $options['global']) {
257:             $options += (array)$options['wei']->getConfig('http');
258:         }
259:         parent::__construct($options);
260:         $this->defaultOptions = $options;
261:     }
262: 
263:     /**
264:      * Create a new HTTP object and execute
265:      *
266:      * @param array|string $url A options array or the request URL
267:      * @param array $options A options array if the first parameter is string
268:      * @return $this A new HTTP object
269:      */
270:     public function __invoke($url = null, array $options = array())
271:     {
272:         // Merge and set options
273:         if (is_array($url)) {
274:             $options = $url;
275:         } else {
276:             $options['url'] = $url;
277:         }
278:         $options = $options + $this->defaultOptions;
279: 
280:         $http = new self($options);
281:         $http->execute();
282: 
283:         return $http;
284:     }
285: 
286:     /**
287:      * Execute the request, parse the response data and trigger relative callbacks
288:      */
289:     public function execute()
290:     {
291:         // Prepare request
292:         $ch = $this->ch = curl_init();
293:         curl_setopt_array($ch, $this->prepareCurlOptions());
294:         $this->beforeSend && call_user_func($this->beforeSend, $this, $ch);
295: 
296:         // Execute request
297:         $response = curl_exec($ch);
298: 
299:         // Handle response
300:         $this->handleResponse($response);
301:         $this->complete && call_user_func($this->complete, $this, $ch);
302: 
303:         if ($this->throwException && $this->errorException) {
304:             throw $this->errorException;
305:         }
306:     }
307: 
308:     /**
309:      * Prepare cURL options
310:      *
311:      * @return array
312:      */
313:     protected function prepareCurlOptions()
314:     {
315:         $opts = array();
316:         $url = $this->url;
317: 
318:         // CURLOPT_RESOLVE
319:         if ($this->ip) {
320:             $host = parse_url($url, PHP_URL_HOST);
321:             $url = substr_replace($url, $this->ip, strpos($url, $host), strlen($host));
322:             $this->headers['Host'] = $host;
323:         }
324: 
325:         switch ($this->method) {
326:             case 'GET' :
327:                 $postData = false;
328:                 break;
329: 
330:             case 'POST' :
331:                 $postData = true;
332:                 $opts[CURLOPT_POST] = 1;
333:                 break;
334: 
335:             case 'DELETE':
336:             case 'PUT':
337:             case 'PATCH':
338:                 $postData = true;
339:                 $opts[CURLOPT_CUSTOMREQUEST] = $this->method;
340:                 break;
341: 
342:             default:
343:                 $postData = false;
344:                 $opts[CURLOPT_CUSTOMREQUEST] = $this->method;
345:         }
346: 
347:         if ($this->data) {
348:             $data = is_string($this->data) ? $this->data : http_build_query($this->data);
349:             if ($postData) {
350:                 $opts[CURLOPT_POSTFIELDS] = $data;
351:             } else {
352:                 if (false === strpos($url, '?')) {
353:                     $url .= '?' . $data;
354:                 } else {
355:                     $url .= '&' . $data;
356:                 }
357:             }
358:         }
359: 
360:         if ($this->timeout > 0) {
361:             $opts[CURLOPT_TIMEOUT_MS] = $this->timeout;
362:         }
363: 
364:         if ($this->referer) {
365:             // Automatic use current request URL as referer URL
366:             if (true === $this->referer) {
367:                 $opts[CURLOPT_REFERER] = $this->url;
368:             } else {
369:                 $opts[CURLOPT_REFERER] = $this->referer;
370:             }
371:         }
372: 
373:         if ($this->userAgent) {
374:             $opts[CURLOPT_USERAGENT] = $this->userAgent;
375:         }
376: 
377:         if ($this->cookies) {
378:             $cookies = array();
379:             foreach ($this->cookies as $key => $value) {
380:                 $cookies[] = $key . '=' . urlencode($value);
381:             }
382:             $opts[CURLOPT_COOKIE] = implode('; ', $cookies);
383:         }
384: 
385:         if ($this->contentType) {
386:             $this->headers['Content-Type'] = $this->contentType;
387:         }
388: 
389:         // Custom headers will overwrite other options
390:         if ($this->headers) {
391:             $headers = array();
392:             foreach ($this->headers as $key => $value) {
393:                 $headers[] = $key . ': ' . $value;
394:             }
395:             $opts[CURLOPT_HTTPHEADER] = $headers;
396:         }
397: 
398:         $opts[CURLOPT_HEADER] = $this->header;
399:         $opts[CURLOPT_URL] = $url;
400: 
401:         $this->curlOptions += $opts + $this->defaultCurlOptions;
402:         return $this->curlOptions;
403:     }
404: 
405:     /**
406:      * Parse response text
407:      *
408:      * @param string $response
409:      */
410:     protected function handleResponse($response)
411:     {
412:         $ch = $this->ch;
413: 
414:         if (false !== $response) {
415:             $curlInfo = curl_getinfo($ch);
416: 
417:             // Parse response header
418:             if ($this->getCurlOption(CURLOPT_HEADER)) {
419:                 // Fixes header size error when use CURLOPT_PROXY and CURLOPT_HTTPPROXYTUNNEL is true
420:                 // http://sourceforge.net/p/curl/bugs/1204/
421:                 if (false !== stripos($response, "HTTP/1.1 200 Connection established\r\n\r\n")) {
422:                     $response = str_ireplace("HTTP/1.1 200 Connection established\r\n\r\n", '', $response);
423:                 }
424: 
425:                 $this->responseHeader = trim(substr($response, 0, $curlInfo['header_size']));
426:                 $this->responseText = substr($response, $curlInfo['header_size']);
427:             } else {
428:                 $this->responseText = $response;
429:             }
430: 
431:             $statusCode = $curlInfo['http_code'];
432:             $isSuccess = $statusCode >= 200 && $statusCode < 300 || $statusCode === 304;
433:             if ($isSuccess) {
434:                 $this->response = $this->parseResponse($this->responseText, $exception);
435:                 if (!$exception) {
436:                     $this->result = true;
437:                     $this->success && call_user_func($this->success, $this->response, $this);
438:                 } else {
439:                     $this->triggerError('parser', $exception);
440:                 }
441:             } else {
442:                 if ($this->responseHeader) {
443:                     preg_match('/[\d]{3} (.+?)\r/', $this->responseHeader, $matches);
444:                     $statusText = $matches[1];
445:                 } else {
446:                     $statusText = 'HTTP request error';
447:                 }
448:                 $exception = new \ErrorException($statusText, $statusCode);
449:                 $this->triggerError('http', $exception);
450:             }
451:         } else {
452:             $exception = new \ErrorException(curl_error($ch), curl_errno($ch));
453:             $this->triggerError('curl', $exception);
454:         }
455:     }
456: 
457:     /**
458:      * Trigger error callback
459:      *
460:      * @param string $status
461:      * @param \ErrorException $exception
462:      */
463:     protected function triggerError($status, \ErrorException $exception)
464:     {
465:         $this->result = false;
466:         $this->errorStatus = $status;
467:         $this->errorException = $exception;
468:         $this->error && call_user_func($this->error, $this, $status, $exception);
469:     }
470: 
471:     /**
472:      * Parse response data by specified type
473:      *
474:      * @param string $data
475:      * @param null $exception A variable to store exception when parsing error
476:      * @return mixed
477:      */
478:     protected function parseResponse($data, &$exception)
479:     {
480:         switch ($this->dataType) {
481:             case 'json' :
482:             case 'jsonObject' :
483:                 $data = json_decode($data, $this->dataType === 'json');
484:                 if (null === $data && json_last_error() != JSON_ERROR_NONE) {
485:                     $exception = new \ErrorException('JSON parsing error', json_last_error());
486:                 }
487:                 break;
488: 
489:             case 'xml' :
490:             case 'serialize' :
491:                 $methods = array(
492:                     'xml' => 'simplexml_load_string',
493:                     'serialize' => 'unserialize',
494:                 );
495:                 $data = @$methods[$this->dataType]($data);
496:                 if (false === $data && $e = error_get_last()) {
497:                     $exception = new \ErrorException($e['message'], $e['type'], 0, $e['file'], $e['line']);
498:                 }
499:                 break;
500: 
501:             case 'query' :
502:                 // Parse $data(string) and assign the result to $data(array)
503:                 parse_str($data, $data);
504:                 break;
505: 
506:             case 'text':
507:             default :
508:                 break;
509:         }
510:         return $data;
511:     }
512: 
513:     /**
514:      * Sets an option on the current cURL handle
515:      *
516:      * @param int $option
517:      * @param mixed $value
518:      * @return $this
519:      */
520:     public function setCurlOption($option, $value)
521:     {
522:         $this->curlOptions[$option] = $value;
523:         return $this;
524:     }
525: 
526:     /**
527:      * Returns an option value of the current cURL handle
528:      *
529:      * @param int $option
530:      * @return null
531:      */
532:     public function getCurlOption($option)
533:     {
534:         return isset($this->curlOptions[$option]) ? $this->curlOptions[$option] : null;
535:     }
536: 
537:     /**
538:      * Returns the response text
539:      *
540:      * @return string
541:      */
542:     public function getResponseText()
543:     {
544:         return $this->responseText;
545:     }
546: 
547:     /**
548:      * Returns the parsed response data
549:      *
550:      * @return mixed
551:      */
552:     public function getResponse()
553:     {
554:         return $this->response;
555:     }
556: 
557:     /**
558:      * Returns the request URL
559:      *
560:      * @return string
561:      */
562:     public function getUrl()
563:     {
564:         return $this->url;
565:     }
566: 
567:     /**
568:      * Returns the request method
569:      *
570:      * @return string
571:      */
572:     public function getMethod()
573:     {
574:         return $this->method;
575:     }
576: 
577:     /**
578:      * Returns the IP address for the host name in URL
579:      *
580:      * @return string
581:      */
582:     public function getIp()
583:     {
584:         return $this->ip;
585:     }
586: 
587:     /**
588:      * Returns the data to send to the server
589:      *
590:      * @return array|string
591:      */
592:     public function getData()
593:     {
594:         return $this->data;
595:     }
596: 
597:     /**
598:      * Returns request header value
599:      *
600:      * @param string $name The header name
601:      * @param bool $first Return the first element or the whole header values
602:      * @return string|array When $first is true, returns string, otherwise, returns array
603:      */
604:     public function getResponseHeader($name = null, $first = true)
605:     {
606:         // Return response header string when parameter is not provided
607:         if (is_null($name)) {
608:             return $this->responseHeader;
609:         }
610: 
611:         $name = strtoupper($name);
612:         $headers = $this->getResponseHeaders();
613: 
614:         if (!isset($headers[$name])) {
615:             return $first ? null : array();
616:         } else {
617:             return $first ? current($headers[$name]) : $headers[$name];
618:         }
619:     }
620: 
621:     /**
622:      * Returns response headers array
623:      *
624:      * @return array
625:      */
626:     public function getResponseHeaders()
627:     {
628:         if (!is_array($this->responseHeaders)) {
629:             $this->responseHeaders = array();
630:             foreach (explode("\n", $this->responseHeader) as $line) {
631:                 $line = explode(':', $line, 2);
632:                 $name = strtoupper($line[0]);
633:                 $value = isset($line[1]) ? trim($line[1]) : null;
634:                 $this->responseHeaders[$name][] = $value;
635:             }
636:         }
637:         return $this->responseHeaders;
638:     }
639: 
640:     /**
641:      * Returns a key-value array contains the response cookies, like $_COOKIE
642:      *
643:      * @return array
644:      */
645:     public function getResponseCookies()
646:     {
647:         if (!is_array($this->responseCookies)) {
648:             $cookies = $this->getResponseHeader('SET-COOKIE', false);
649:             $this->responseCookies = array();
650:             foreach ($cookies as $cookie) {
651:                 $this->responseCookies += $this->parseCookie($cookie);
652:             }
653:         }
654:         return $this->responseCookies;
655:     }
656: 
657:     /**
658:      * Returns the cookie value by specified name
659:      *
660:      * @param string $name
661:      * @return string|null
662:      */
663:     public function getResponseCookie($name)
664:     {
665:         $cookies = $this->getResponseCookies();
666:         return isset($cookies[$name]) ? $cookies[$name] : null;
667:     }
668: 
669:     /**
670:      * Parse cookie from header, returns result like $_COOKIE
671:      *
672:      * @param string $header
673:      * @return array
674:      */
675:     protected function parseCookie($header)
676:     {
677:         $elements = explode(';', $header);
678:         $cookies = array();
679: 
680:         $currentName = null;
681:         foreach ($elements as $element) {
682:             $pieces = explode('=', trim($element), 2);
683:             if (!isset($pieces[1])) {
684:                 continue;
685:             }
686:             list($name, $value) = $pieces;
687: 
688:             if (strtolower($name) == 'expires' && strtotime($value) < time()) {
689:                 // Removes expired cookie
690:                 unset($cookies[$currentName]);
691:             } elseif (in_array(strtolower($name), array('domain', 'path', 'comment', 'expires', 'secure', 'max-age'))) {
692:                 // Ignore cookie attribute
693:                 continue;
694:             } else {
695:                 $cookies[$name] = trim(urldecode($value));
696:                 $currentName = $name;
697:             }
698:         }
699:         return $cookies;
700:     }
701: 
702:     /**
703:      * Returns if the request is success
704:      *
705:      * @return bool
706:      */
707:     public function isSuccess()
708:     {
709:         return $this->result;
710:     }
711: 
712:     /**
713:      * Set request method
714:      *
715:      * @param string $method
716:      * @return $this
717:      */
718:     public function setMethod($method)
719:     {
720:         $this->method = strtoupper($method);
721:         return $this;
722:     }
723: 
724:     /**
725:      * Execute a GET method request
726:      *
727:      * @param string $url
728:      * @param array $data
729:      * @param string $dataType
730:      * @return $this
731:      */
732:     public function get($url, $data = array(), $dataType = null)
733:     {
734:         return $this->processMethod($url, $data, $dataType, 'GET');
735:     }
736: 
737:     /**
738:      * Execute a GET method request and parser response data to JSON array
739:      *
740:      * @param string $url
741:      * @param array $data
742:      * @return $this
743:      */
744:     public function getJson($url, $data = array())
745:     {
746:         return $this->processMethod($url, $data, 'json', 'GET');
747:     }
748: 
749:     /**
750:      * Execute a GET method request and parser response data to JSON object
751:      *
752:      * @param string $url
753:      * @param array $data
754:      * @return $this
755:      */
756:     public function getJsonObject($url, $data = array())
757:     {
758:         return $this->processMethod($url, $data, 'jsonObject', 'GET');
759:     }
760: 
761:     /**
762:      * Execute a POST method request
763:      *
764:      * @param string $url
765:      * @param array $data
766:      * @param string $dataType
767:      * @return $this
768:      */
769:     public function post($url, $data = array(), $dataType = null)
770:     {
771:         return $this->processMethod($url, $data, $dataType, 'POST');
772:     }
773: 
774:     /**
775:      * Execute a POST method request and parser response data to JSON array
776:      *
777:      * @param string $url
778:      * @param array $data
779:      * @return $this
780:      */
781:     public function postJson($url, $data = array())
782:     {
783:         return $this->processMethod($url, $data, 'json', 'POST');
784:     }
785: 
786:     /**
787:      * Execute a PUT method request
788:      *
789:      * @param string $url
790:      * @param array $data
791:      * @param string $dataType
792:      * @return $this
793:      */
794:     public function put($url, $data = array(), $dataType = null)
795:     {
796:         return $this->processMethod($url, $data, $dataType, 'PUT');
797:     }
798: 
799:     /**
800:      * Execute a DELETE method request
801:      *
802:      * @param string $url
803:      * @param array $data
804:      * @param string $dataType
805:      * @return $this
806:      */
807:     public function delete($url, $data = array(), $dataType = null)
808:     {
809:         return $this->processMethod($url, $data, $dataType, 'DELETE');
810:     }
811: 
812:     /**
813:      * Execute a PATCH method request
814:      *
815:      * @param string $url
816:      * @param array $data
817:      * @param string $dataType
818:      * @return $this
819:      */
820:     public function patch($url, $data = array(), $dataType = null)
821:     {
822:         return $this->processMethod($url, $data, $dataType, 'PATCH');
823:     }
824: 
825:     public function upload($url, $data = array(), $dataType = null)
826:     {
827:         return $this->processMethod($url, $data, $dataType, 'POST');
828:     }
829: 
830:     /**
831:      * Execute a specified method request
832:      *
833:      * @param string $url
834:      * @param array $data
835:      * @param string $dataType
836:      * @param string $method
837:      * @return $this
838:      */
839:     protected function processMethod($url, $data, $dataType, $method)
840:     {
841:         return $this->__invoke(array(
842:             'url' => $url,
843:             'method' => $method,
844:             'dataType' => $dataType,
845:             'data' => $data
846:         ));
847:     }
848: 
849:     /**
850:      * Returns the error status text
851:      *
852:      * @return string
853:      */
854:     public function getErrorStatus()
855:     {
856:         return $this->errorStatus;
857:     }
858: 
859:     /**
860:      * Returns the error exception object
861:      *
862:      * @return \ErrorException
863:      */
864:     public function getErrorException()
865:     {
866:         return $this->errorException;
867:     }
868: 
869:     /**
870:      * Check if the offset exists
871:      *
872:      * @param  string $offset
873:      * @return bool
874:      */
875:     public function offsetExists($offset)
876:     {
877:         return array_key_exists($offset, $this->response);
878:     }
879: 
880:     /**
881:      * Get the offset value
882:      *
883:      * @param  string $offset
884:      * @return mixed
885:      */
886:     public function offsetGet($offset)
887:     {
888:         return isset($this->response[$offset]) ? $this->response[$offset] : null;
889:     }
890: 
891:     /**
892:      * Set the offset value
893:      *
894:      * @param string $offset
895:      * @param mixed $value
896:      */
897:     public function offsetSet($offset, $value)
898:     {
899:         $this->response[$offset] = $value;
900:     }
901: 
902:     /**
903:      * Unset the offset
904:      *
905:      * @param string $offset
906:      */
907:     public function offsetUnset($offset)
908:     {
909:         unset($this->response[$offset]);
910:     }
911: 
912:     /**
913:      * Return the length of data
914:      *
915:      * @return int the length of data
916:      */
917:     public function count()
918:     {
919:         return count($this->response);
920:     }
921: 
922:     /**
923:      * Retrieve an array iterator
924:      *
925:      * @return \ArrayIterator
926:      */
927:     public function getIterator()
928:     {
929:         return new \ArrayIterator($this->response);
930:     }
931: 
932:     /**
933:      * Returns to response body string
934:      *
935:      * @return string
936:      */
937:     public function __toString()
938:     {
939:         return (string)$this->responseText;
940:     }
941: 
942:     /**
943:      * @return array
944:      */
945:     public function getCurlInfo()
946:     {
947:         return curl_getinfo($this->ch);
948:     }
949: 
950:     /**
951:      * Close the cURL session
952:      */
953:     public function __destruct()
954:     {
955:         if ($this->ch) {
956:             curl_close($this->ch);
957:             unset($this->ch);
958:         }
959:     }
960: }
Wei Framework API documentation generated by ApiGen