forked from cturbelin/rserve-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNative.php
91 lines (76 loc) · 1.97 KB
/
RNative.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Rserve native array wrapper
* @author Clément Turbelin
* From Rserve java Client & php Client
*/
/**
* php Native array with attributes feature
* results wrapped in this class could be used as an array ($result['toto']) to get a results and attributes could be accessed using methods
*/
class Rserve_RNative implements ArrayAccess {
/**
* @var array data = R values
*/
private $data = array();
/**
* @var array R Attributes for this structure
*/
private $attr = array();
/**
* Parsed expression type
* @var int (Rserve_Connection XT_* const value)
*/
private $type = null;
/**
*
* @param $data values
* @param Rserve_RNative $attributes
* @param int $exp_type expression type
*/
public function __construct($data, $attributes = null, $exp_type = null) {
$this->data = $data;
$this->attr = $attributes;
$this->type = $exp_type;
}
/**
* @param string $name get the attribute named $name
* @return mixed
*/
public function getAttr($name) {
return isset($this->attr[$name]) ? $this->attr[$name] : null;
}
/**
* Test if an attibute exists
* @param string $name
*/
public function hasAttr($name) {
return isset($this->attr[$name]) ? true : false;
}
/**
* Type of the parsed expression (vector, list, etc) (@see Rserve_Parser::xtName())
*/
public function getType() {
return $this->type;
}
/**
* Get the attributes
* @return Rserve_RNative
*/
public function getAttributes() {
return $this->attr;
}
// ArrayAccess Implementation allows array-like syntax for instances
public function offsetSet($offset, $value) {
$this->data[$offset] = $value;
}
public function offsetExists($offset) {
return isset($this->data[$offset]);
}
public function offsetUnset($offset) {
unset($this->data[$offset]);
}
public function offsetGet($offset) {
return isset($this->data[$offset]) ? $this->data[$offset] : null;
}
}