/** * class constructor * * @param string $dsn CouchDB server data source name (eg. http://localhost:5984) * @param string $dbname CouchDB database name * @param array $options Additionnal configuration options */ public function __construct($dsn, $dbname, $options = array()) { // in the case of a cookie based authentification we have to remove user and password infos from the DSN if (array_key_exists("cookie_auth", $options) && $options["cookie_auth"] == "true") { $parts = parse_url($dsn); if (!array_key_exists("user", $parts) || !array_key_exists("pass", $parts)) { throw new Exception("You should provide a user and a password to use cookie based authentification"); } $user = $parts["user"]; $pass = $parts["pass"]; $dsn = $parts["scheme"] . "://" . $parts["host"]; $dsn .= array_key_exists("port", $parts) ? ":" . $parts["port"] : ""; $dsn .= array_key_exists("path", $parts) ? $parts["path"] : ""; } $this->useDatabase($dbname); parent::__construct($dsn, $options); if (array_key_exists("cookie_auth", $options) && $options["cookie_auth"] == "true") { $raw_data = $this->query("POST", "/_session", null, http_build_query(array("name" => $user, "password" => $pass)), "application/x-www-form-urlencoded"); list($headers, $body) = explode("\r\n\r\n", $raw_data, 2); $headers_array = explode("\n", $headers); foreach ($headers_array as $line) { if (strpos($line, "Set-Cookie: ") === 0) { $line = substr($line, 12); $line = explode("; ", $line, 2); $this->setSessionCookie(reset($line)); break; } } if (!$this->sessioncookie) { throw new Exception("Cookie authentification failed"); } } }
/** * class constructor * * @param string $dsn CouchDB server data source name (eg. http://localhost:5984) * @param integer $port CouchDB server port * @param string $dbname CouchDB database name */ public function __construct($dsn, $dbname) { if (!strlen($dbname)) { throw new InvalidArgumentException("Database name can't be empty"); } parent::__construct($dsn); $this->dbname = $dbname; }
/** * class constructor * * @param string $dsn CouchDB server data source name (eg. http://localhost:5984) * @param integer $port CouchDB server port * @param string $dbname CouchDB database name */ public function __construct($dsn, $dbname) { if (!strlen($dbname)) { throw new InvalidArgumentException("Database name can't be empty"); } if (!$this->isValidDatabaseName($dbname)) { throw new InvalidArgumentException('Database name contains invalid characters. Only lowercase characters (a-z), digits (0-9), and any of the characters _, $, (, ), +, -, and / are allowed.'); } parent::__construct($dsn); $this->dbname = $dbname; }
/** * class constructor * * @param string $dsn CouchDB server data source name (eg. http://localhost:5984) * @param string $dbname CouchDB database name * @param array $options Additionnal configuration options */ public function __construct($dsn, $dbname, $options = array()) { $this->useDatabase($dbname); parent::__construct($dsn, $options); }
/** * class constructor * * @param string $dsn CouchDB server data source name (eg. http://localhost:5984) * @param integer $port CouchDB server port * @param string $dbname CouchDB database name */ public function __construct($dsn, $dbname) { $this->useDatabase($dbname); parent::__construct($dsn); }