-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPackage.php
125 lines (116 loc) · 2.3 KB
/
Package.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
*
* Google_Package
* @desc returns the package loader
* @package Google
* @author Thomas Schaefer
* @copyright Thomas Schaefer
* @since 2009-05-20
*/
/**
*
* Google_Package
* @desc returns the package loader
* @package Google
* @author Thomas Schaefer
* @copyright Thomas Schaefer
* @since 2009-05-20
*/
class Google_Package {
/**
* @staticvar $isRegistered used to register items
*/
private static $isRegistered = array(
"packages"=>true,
"language"=>true,
);
/**
* @var array $properties
*/
private $properties = null;
/**
* @var string $provider
*/
private $provider = 'google';
/**
* @var string $scope
*/
private $scope = 'visualization';
/**
* @var string $type
*/
private $type = 'load';
/**
* @var integer $version
*/
private $version = 1;
/**
*
* @param array $properties
* @param string $provider
* @param string $scope
*/
public function __construct(array $properties = array(), $provider=null, $scope=null) {
if(count($properties))
{
foreach($properties as $name => $value)
{
if(array_key_exists($name, self::$isRegistered)) {
if(empty($this->properties)) {
$this->properties = new stdClass;
}
$this->properties->{$name} = $value;
}
}
}
if($provider) {
$this->provider = $provider;
}
if($scope){
$this->scope = $scope;
}
}
/**
*
* @param string $name
* @param mixed $value
*/
public function __set($name, $value) {
if(array_key_exists($name, self::$isRegistered)) {
if(empty($this->properties)) {
$this->properties = new stdClass;
}
$this->properties->{$name} = $value;
} else {
throw new Exception("no such property named ". $name);
}
}
/**
* setType
* @desc sets the methodType
* @param mixed $type
*/
public function setType($type) {
if(is_array($type)) {
$this->type = implode(".", $type);
} else {
$this->type = $type;
}
}
/**
* @return string
*/
public function __toString() {
$string = '';
$string .= $this->provider;
$string .= '.';
$string .= $this->type;
$string .= '(';
$string .= "'".$this->scope."',";
$string .= "'".$this->version."',";
$string .= (!empty($this->properties)?Google_Base::toJson($this->properties):'');
$string .= ');';
return $string;
}
}