public function testCreateDefaultInstance()
 {
     phpillowConnection::createInstance('example.com', '80');
     $instance = phpillowConnection::getInstance();
     $this->assertTrue($instance instanceof phpillowConnection);
     $this->assertTrue($instance instanceof phpillowCustomConnection);
 }
Esempio n. 2
0
 public function saveDataToCouch($data)
 {
     try {
         phpillowConnection::createInstance($this->to_host, $this->to_port, '', '');
         phpillowConnection::setDatabase($this->to_database);
     } catch (Exception $e) {
         die("Nie moge nawiazac polaczenia z baza Couch ({$this->to_host}:{$this->to_port})");
     }
     $allowKeys = array('nazwa', 'dlugosc', 'szerokosc', 'ludnosc', 'link');
     foreach ($data as $k => $value) {
         if (is_array($value) && !empty($value)) {
             $doc = new miastoDocument();
             foreach ($value as $k1 => $v1) {
                 if (in_array($k1, $allowKeys)) {
                     $doc->{$k1} = $v1;
                 }
             }
             $doc->save();
         }
     }
 }
<?php

// Include all required classes
$autoload = (require ($base = dirname(__FILE__) . '/../src/') . 'classes/autoload.php');
foreach ($autoload as $file) {
    require_once $base . $file;
}
// Configure parameters for speed testing
$puts = 1000;
$gets = 5000;
$views = 2000;
// Set up backend connection
phpillowConnection::createInstance('10.0.118.171', 5984, 'admin', 'm4!1.d3');
phpillowConnection::setDatabase('test');
$db = phpillowConnection::getInstance();
try {
    $db->delete('/test');
} catch (Exception $e) {
    /* Ignore */
}
$db->put('/test');
// /*
$start = microtime(true);
for ($i = 0; $i < $puts; ++$i) {
    $doc = new phpillowUserDocument();
    $doc->login = '******' . $i;
    $doc->name = 'Kore Nordmann';
    $doc->save();
}
printf("%d PUTs in %.2fs (%d req/s)\n", $puts, $time = microtime(true) - $start, $puts / $time);
// */
Esempio n. 4
0
 /**
  * Create a new couch DB connection instance.
  *
  * Static method to create a new couch DB connection instance. This method
  * should be used to configure the connection for later use.
  *
  * The host and its port default to localhost:5984.
  *
  * @param string $host
  * @param int $port
  * @param string $username
  * @param string $password
  * @param string $called
  * @return void
  */
 public static function createInstance($host = '127.0.0.1', $port = 5984, $username = null, $password = null, $called = "phpillowStreamConnection")
 {
     parent::createInstance($host, $port, $username, $password, $called);
 }
Esempio n. 5
0
<?php

//Install PHPillow using PEAR
require "PHPillow/bootstrap.php";
require "documents.php";
require "views.php";
require "settings.php";
phpillowConnection::createInstance('localhost', 5984, COUCHDB_USER, COUCHDB_PASSWORD);
phpillowConnection::setDatabase(COUCHDB_DATABASE);
function tripHash($password)
{
    //TODO: Talk to someone smart about cryptographic hash functions
    //This appears to work well, but there could be a flaw.
    //based on wikipedia description of algo
    $tripcode = substr(crypt($password, TRIPCODE_SALT), -10, 10);
    return $tripcode;
}
function validMessage($json)
{
    //make sure username is appropriate length and alphanumeric plus underscore
    if (strlen($json->username) > 30 || strlen($json->username) < 3) {
        return false;
    }
    $alphanumeric = '/^[0-9a-zA-Z_]+$/';
    if (!preg_match($alphanumeric, $json->username)) {
        return false;
    }
    //make sure message isn't too long.
    if (strlen($json->message) > 1000) {
        return false;
    }
 public function testDeleteDocumentMultipleRevisions()
 {
     phpillowConnection::createInstance();
     phpillowConnection::setDatabase('test');
     // Create test database
     $db = phpillowConnection::getInstance();
     $db->put('/test');
     // Add document to fetch
     $author = phpillowManager::createDocument('user');
     $author->login = '******';
     $author->save();
     $doc = phpillowManager::fetchDocument('user', 'user-kore');
     $doc->name = 'Kore';
     $doc->save();
     // Test delete
     phpillowManager::deleteDocument('user', 'user-kore');
     try {
         $user = phpillowManager::fetchDocument('user', 'user-kore');
         $this->fail('Expected phpillowResponseNotFoundErrorException.');
     } catch (phpillowResponseNotFoundErrorException $e) {
         /* Expected exception */
     }
     // Remove / clear test database
     $db = phpillowConnection::getInstance();
     $db->delete('/test');
     phpillowConnectionTestHelper::reset();
 }
Esempio n. 7
0
<?php

/** Configuration Variables **/
define('DEVELOPMENT_ENVIRONMENT', true);
//RANDOM HASH STRING
define('HASH_STRING', '2d5A212fE35c');
//Typ bazy
define('DB_TYPE', 'couchdb');
//couchdb, mysql
//MYSQL
define('DB_NAME', 'yourdatabasename');
define('DB_USER', 'yourusername');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');
//couchDB
define('CDB_USER', '');
define('CDB_PASSWORD', '');
define('CDB_HOST', '127.0.0.1');
define('CDB_PORT', '5984');
define('CDB_NAME', 'baza');
//nazwa bazy
phpillowConnection::createInstance(CDB_HOST, CDB_PORT, CDB_USER, CDB_PASSWORD);
phpillowConnection::setDatabase(CDB_NAME);
<?php

// Set up PHPillow autoloading
include dirname(__FILE__) . '/../src/bootstrap.php';
// Set up database connection with default parameters
phpillowConnection::createInstance();
// Set database, which will be used and get connection handler
$db = phpillowConnection::getInstance();
phpillowConnection::setDatabase('test');
// Delete maybe existing database, ignoring the error, if it does not exist
// yet.
try {
    $db->delete('/test');
} catch (Exception $e) {
    /* Ignore */
}
// Create new database
$db->put('/test');
// Create a new document of the predefined user class
$doc = new phpillowUserDocument();
$doc->login = '******';
$doc->name = 'Kore Nordmann';
$docId = $doc->save();
// Fetch the document from the database
$doc = new phpillowUserDocument();
$doc->fetchById($docId);
// Update the document
$doc->email = '*****@*****.**';
$doc->save();
// Fetch the document again and dump the revisions
$doc = new phpillowUserDocument();