summaryrefslogtreecommitdiffstats
path: root/apps/files_external/3rdparty/irodsphp/prods/src/RODSKeyValPair.class.php
blob: f347f7c988af2fc7235184fe8548ef05f97a0102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
 * RODS keyval type class. This class is conresponding to iRODS's keyval type
 * @author Sifang Lu <sifang@sdsc.edu>
 * @copyright Copyright &copy; 2007, TBD
 * @package RODSConn
 */


require_once("autoload.inc.php");

class RODSKeyValPair
{
    private $keys;
    private $vals;

    public function __construct(array $arr = array())
    {
        $this->keys = array_keys($arr);
        $this->vals = array_values($arr);
    }

    public function addPair($key, $val)
    {
        $this->keys[] = $key;
        $this->vals[] = $val;
    }

    /**
     * Make a RP_KeyValPair
     * @return RP_KeyValPair a RP_KeyValPair object
     */
    public function makePacket()
    {
        return new RP_KeyValPair(count($this->keys), $this->keys, $this->vals);
    }

    /**
     * make a RODSKeyValPair from a RP_KeyValPair
     */
    public static function fromPacket(RP_KeyValPair $RP_KeyValPair)
    {
        $new_keyval = new RODSKeyValPair();
        $new_keyval->keys = $RP_KeyValPair->keyWord;
        $new_keyval->vals = $RP_KeyValPair->svalue;
        return $new_keyval;
    }
}