2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 2010 Takahiro Ooishi |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 3.0 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available through the world-wide-web at the following url: |
11 // | http://www.php.net/license/3_0.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Author: Takahiro Ooishi <taka0125.biz@gmail.com> |
17 // +----------------------------------------------------------------------+
21 require_once 'Http/Error.class.php';
23 abstract class Core_Http_AgentTemplate
30 const DefaultTimeout = 300;
32 abstract function send($url, $request);
33 abstract protected function open();
34 abstract protected function close();
35 abstract protected function setOptions($options);
36 abstract function setOption($name, $option);
37 abstract function setBasicAuthenticationAccount($user, $password);
39 function __construct($options = array(), $timeout = self::DefaultTimeout)
41 $this->setOptions($options);
42 $this->setTimeout($timeout);
44 $this->error = new Http_Error();
54 return $this->options;
57 function setTimeout($timeout)
59 if (!is_numeric($timeout)) throw new ValidationException($timeout, 'Invalid Timeout.');
60 $timeout = intval($timeout);
61 if ($timeout < 1) throw new ValidationException($timeout, 'Invalid Timeout.');
62 $this->timeout = $timeout;
67 return $this->error->isError();
72 return $this->error->get();
75 protected function clearError()
77 return $this->error->clear();