예제 #1
0
 public function get($key, $filter = 'safe', $default = NULL)
 {
     if (is_array($key)) {
         $res = array();
         foreach (parent::get($key) as $k => $v) {
             $v = \Gaia\Filter::against($v, $filter);
             if ($v === NULL) {
                 $v = $default;
             }
             if ($v === NULL) {
                 continue;
             }
             $res[$k] = $v;
         }
         if ($default !== NULL) {
             foreach ($key as $k) {
                 if (!isset($res[$k])) {
                     $res[$k] = $default;
                 }
             }
         }
         return $res;
     }
     $v = \Gaia\Filter::against(parent::get($key), $filter);
     if ($v === NULL) {
         $v = $default;
     }
     return $v;
 }
 public function set($k, $v)
 {
     if (is_array($v) || $v instanceof \Iterator) {
         $v = new self($v);
     }
     return parent::set($k, $v);
 }
 /**
  * get back a the view results.
  * Example:
  *    $params = array(
  *       'startkey'=>'bear',
  *       'endkey'=>'zebra',
  *       'connection_timeout'=> 60000,
  *       'limit'=>10,
  *       'skip'=>0,
  *       'full_set'=>'true',
  *    );
  *    $result = $view->query('mammals' $params);
  *
  */
 public function query($view, $params = NULL)
 {
     $params = new Container($params);
     foreach ($params as $k => $v) {
         if (!is_scalar($v) || preg_match('#key#i', $k)) {
             $params->{$k} = json_encode($v);
         }
     }
     $len = strlen($this->app);
     $app = $len > 0 ? $this->app : 'default/';
     $http = $this->request('_design/' . $app . '_view/' . $view . '/?' . \Gaia\Http\Util::buildQuery($params->all()));
     $response = $this->validateResponse($http->exec(), array(200));
     $result = $response->body;
     if ($len < 1) {
         return $result;
     }
     foreach ($result['rows'] as &$row) {
         if (isset($row['id'])) {
             $row['id'] = substr($row['id'], $len);
         }
     }
     return $result;
 }
예제 #4
0
 /**
  * Specify storage and an entity key.
  * This will load a bunch of key/value pairs associated with the entity
  */
 public function __construct(Iface $storage, $entity)
 {
     $this->storage = $storage;
     // a way to populate an entity without having to read from storage.
     // for internal use only. used by the EAV::bulkLoad() method.
     if (is_array($entity)) {
         $this->entity = $entity["._entity"];
         unset($entity["._entity"]);
         $this->load($entity);
         $this->state = $this->checksum();
         return;
     }
     // standard approach.
     $this->entity = $entity;
     parent::__construct($this->storage->get($entity));
     $this->state = $this->checksum();
 }
예제 #5
0
<?php

include_once __DIR__ . '/../common.php';
use Gaia\Test\Tap;
use Gaia\Container;
Tap::plan(22);
$c = new Container();
foreach (array('result_set', 'result_get', 'result_isset', 'result_unset') as $key) {
    ${$key} = array();
}
if (!isset($input) || !is_array($input)) {
    $input = array();
}
foreach ($input as $k => $v) {
    $result_set[$k] = $c->{$k} = $v;
    $result_isset[$k] = isset($c->{$k});
    $result_get[$k] = $c->{$k};
    unset($c->{$k});
    $result_unset[$k] = $c->{$k};
}
Tap::is($input, $result_set, 'set works properly');
Tap::is($input, $result_get, 'get works properly');
Tap::is(array_fill_keys(array_keys($input), TRUE), $result_isset, 'isset works properly');
Tap::is(array_fill_keys(array_keys($input), NULL), $result_unset, 'unset works properly');
Tap::is($c->non_existent, NULL, 'non-existent variables are null');
$c->load($input);
Tap::is($c->get(array_keys($input)), $input, 'multi-get works properly');
Tap::is($c->all(), $input, 'grabbed all of the data at once');
$each = array();
while (list($k, $v) = $c->each()) {
    $each[$k] = $v;
예제 #6
0
#!/usr/bin/env php
<?php 
use Gaia\Skein;
use Gaia\Container;
use Gaia\DB;
include __DIR__ . '/../common.php';
$thread = 5184;
$cache = new Container();
DB\Connection::load(array('test' => function () {
    return new DB\Except(new Gaia\DB(new MySQLi('127.0.0.1', NULL, NULL, 'test', '3306')));
}));
$callback = function ($table) use($cache) {
    $db = DB\Connection::instance('test');
    if (!$cache->add($table, 1, 60)) {
        return $db;
    }
    $sql = substr($table, -5) == 'index' ? Skein\MySQL::indexSchema($table) : Skein\MySQL::dataSchema($table);
    $db->execute($sql);
    return $db;
};
$skein = new Skein\MySQL($thread, $callback, $app_prefix = 'test002');
$data = 'the time is ' . date('Y/m/d H:i:s');
$id = $skein->add($data);
print "\nID: {$id} \n";
$data = $skein->get($id);
print "\nDATA: " . print_r($data, TRUE) . "\n";
$skein->store($id, array('foo' => $data));
$data = $skein->get($id);
print "\nDATA: " . print_r($data, TRUE) . "\n";
$data = $skein->get($skein->descending());
print "\nDESCENDING ORDER: " . print_r($data, TRUE) . "\n";