composer package updates
[openemr.git] / vendor / doctrine / couchdb / lib / Doctrine / CouchDB / HTTP / AbstractHTTPClient.php
blob25c00dea01381968ff98553f7fc52b3f867355fe
1 <?php
2 /** HTTP Client interface
4 */
6 namespace Doctrine\CouchDB\HTTP;
8 /**
9 * Basic couch DB connection handling class
11 * @license http://www.opensource.org/licenses/mit-license.php MIT
12 * @link www.doctrine-project.com
13 * @since 1.0
14 * @author Kore Nordmann <kore@arbitracker.org>
16 abstract class AbstractHTTPClient implements Client
18 /**
19 * CouchDB connection options
21 * @var array
23 protected $options = array(
24 'host' => 'localhost',
25 'port' => 5984,
26 'ip' => '127.0.0.1',
27 'ssl' => false,
28 'timeout' => 0.01,
29 'keep-alive' => true,
30 'username' => null,
31 'password' => null,
32 'path' => null,
35 /**
36 * Construct a CouchDB connection
38 * Construct a CouchDB connection from basic connection parameters for one
39 * given database.
41 * @param string $host
42 * @param int $port
43 * @param string $username
44 * @param string $password
45 * @param string $ip
46 * @param bool $ssl
47 * @param string $path
48 * @return \Doctrine\CouchDB\HTTP\AbstractHTTPClient
50 public function __construct($host = 'localhost', $port = 5984, $username = null, $password = null, $ip = null , $ssl = false, $path = null, $timeout = 0.01)
52 $this->options['host'] = (string) $host;
53 $this->options['port'] = (int) $port;
54 $this->options['ssl'] = $ssl;
55 $this->options['username'] = $username;
56 $this->options['password'] = $password;
57 $this->options['path'] = $path;
58 $this->options['timeout'] = (float) $timeout;
60 if ($ip === null) {
61 $this->options['ip'] = gethostbyname($this->options['host']);
62 } else {
63 $this->options['ip'] = $ip;
67 /**
68 * Set option value
70 * Set the value for an connection option. Throws an
71 * InvalidArgumentException for unknown options.
73 * @param string $option
74 * @param mixed $value
76 * @throws \InvalidArgumentException
78 * @return void
80 public function setOption( $option, $value )
82 switch ( $option ) {
83 case 'keep-alive':
84 case 'ssl':
85 $this->options[$option] = (bool) $value;
86 break;
88 case 'http-log':
89 case 'password':
90 case 'username':
91 $this->options[$option] = $value;
92 break;
94 default:
95 throw new \InvalidArgumentException( "Unknown option $option." );
99 /**
100 * Get the connection options.
102 * @return array
104 public function getOptions()
106 return $this->options;