-
Notifications
You must be signed in to change notification settings - Fork 13
/
cascade.php
309 lines (308 loc) · 8.45 KB
/
cascade.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
/*
Function List:
$obj = new Cascade($username, $password, $domain); //wrap in try/catch
$obj->changeAuth($username, $password); //wrap in try/catch
$identifier = $obj->identifier($type, $path, $siteName);
$identifier = $obj->identifierByPath($type, $path, $siteName);
$identifier = $obj->identifier($type, $id);
$identifier = $obj->identifierById($type, $id);
$acl= $obj->createACL($name, $level, $type);
$bool = $obj->result($reply);
$reply = $obj->listSites();
$reply = $obj->listSubscribers($identifier);
$reply = $obj->read($identifier);
$reply = $obj->readWorkflowSettings($identifier);
$reply = $obj->readAccessRights($identifier);
$reply = $obj->search($searchInfo);
$reply = $obj->edit($asset);
$reply = $obj->editWorkflowSettings($workflowSettings, $childrenInherit, $childrenRequire);
$reply = $obj->editAccessRights($acls, $children);
$reply = $obj->move($identifier, $destIdentifier, $newName, $doWorkflow = false);
$reply = $obj->create($asset);
$reply = $obj->copy($identifier, $destIdentifier, $newName);
$reply = $obj->delete($identifier);
$reply = $obj->publish($identifier, $destIdentifiers, $unpublish);
$array = $obj->objectToArray($object);
$object = $obj->arrayToObject($array);
$obj->test($arr);
*/
class Cascade
{
private $auth;
private $client;
/*
Builds $auth and $client, then tests authentication
NOTE:Wrap in try/catch
*/
function __construct($username, $password, $domain)
{
$this->auth = array ('username' => $username, 'password' => $password );
$soapURL = "https://".$domain."/ws/services/AssetOperationService?wsdl";
$this->client = new SoapClient
(
$soapURL,
array ('trace' => 1, 'location' => str_replace('?wsdl', '', $soapURL))
);
$this->testAuth();
}
/*
Allows: identifier($type,$path,$siteName);
Allows: identifier($type,$id);
*/
function __call($method, $arguments)
{
/*
Allows:
$obj->identifier($type,$path,$siteName);
$obj->identifier($type,$id);
*/
if($method == 'identifier')
{
if(count($arguments) == 2)
return call_user_func_array(array ($this,'identifierById'), $arguments);
elseif(count($arguments) == 3)
return call_user_func_array(array ($this,'identifierByPath'), $arguments);
}
}
/*
Changes the authenticated user, and test the authentication
NOTE:Wrap in try/catch
*/
function changeAuth($username, $password)
{
$this->auth = array ('username' => $username, 'password' => $password );
$this->testAuth();
}
/*
Tests authentication using listSites()
Throws an exception on failure
*/
private function testAuth()
{
if(!$this->result($this->listSites()))
throw new Exception('Invalid Username/Password');
}
/*
Return boolean on $reply->success
*/
function result($reply)
{
return ($reply->success == "true");
}
/*
Builds path based identifier
*/
function identifierByPath($type, $path, $siteName)
{
return array(
'path' => array(
'path' => $path,
'siteName' => $siteName),
'type' => $type
);
}
/*
Builds id based identifier
*/
function identifierById($type, $id)
{
return array(
'id' => $id,
'type' => $type
);
}
/*
Builds single ACL
*/
function createACL($name, $level = 'read', $type = 'group')
{
return array(
'name' => $name,
'level' => $level,
'type' => $type
);
}
/*
Returns list of sites
*/
function listSites()
{
$params = array ('authentication' => $this->auth);
$reply = $this->client->listSites($params);
return $reply->listSitesReturn;
}
/*
Returns list of subscribers
*/
function listSubscribers($identifier)
{
$params = array ('authentication' => $this->auth, 'identifier' => $identifier);
$reply = $this->client->listSubscribers($params);
return $reply->listSubscribersReturn;
}
/*
Returns readReturn from identifier
*/
function read($identifier)
{
$params = array ('authentication' => $this->auth, 'identifier' => $identifier);
$reply = $this->client->read($params);
return $reply->readReturn;
}
/*
Returns readWorkflowSettingsReturn from identifier
*/
function readWorkflowSettings($identifier)
{
$params = array ('authentication' => $this->auth, 'identifier' => $identifier);
$reply = $this->client->readWorkflowSettings($params);
return $reply->readWorkflowSettingsReturn;
}
/*
Returns readAccessRightsReturn from identifier
*/
function readAccessRights($identifier)
{
$params = array ('authentication' => $this->auth, 'identifier' => $identifier);
$reply = $this->client->readAccessRights($params);
return $reply->readAccessRightsReturn;
}
/*
Returns searchReturn from identifier
*/
function search($searchInfo)
{
$params = array ('authentication' => $this->auth, 'searchInformation' => $searchInfo);
$reply = $this->client->search($params);
return $reply->searchReturn;
}
/*
Returns editReturn from identifier
*/
function edit($asset)
{
$params = array ('authentication' => $this->auth, 'asset' => $asset);
$reply = $this->client->edit($params);
return $reply->editReturn;
}
/*
Returns editWorkflowSettingsReturn from identifier
*/
function editWorkflowSettings($workflowSettings, $childrenInherit, $childrenRequire)
{
$params = array ('authentication' => $this->auth, 'workflowSettings' => $workflowSettings, 'applyInheritWorkflowsToChildren' => $childrenInherit, 'applyRequireWorkflowToChildren' => $childrenRequire);
$reply = $this->client->editWorkflowSettings($params);
return $reply->editWorkflowSettingsReturn;
}
/*
Returns editAccessRightsReturn from identifier
*/
function editAccessRights($acls, $children)
{
$params = array ('authentication' => $this->auth, 'accessRightsInformation' => $acls, 'applyToChildren' => $children);
$reply = $this->client->editAccessRights($params);
return $reply->editAccessRightsReturn;
}
/*
Returns moveReturn from identifier
*/
function move($identifier, $destIdentifier, $newName, $doWorkflow = false)
{
$params = array ('authentication' => $this->auth, 'identifier' => $identifier, 'moveParameters' => array('destinationContainerIdentifier' => $destIdentifier, 'newName' => $newName, 'doWorkflow' => $doWorkflow));
$reply = $this->client->move($params);
return $reply->moveReturn;
}
/*
Returns createReturn from identifier
*/
function create($asset)
{
$params = array ('authentication' => $this->auth, 'asset' => $asset);
$reply = $this->client->create($params);
return $reply->createReturn;
}
/*
Returns copyReturn from identifier
*/
function copy($identifier, $destIdentifier, $newName)
{
$params = array ('authentication' => $this->auth, 'identifier' => $identifier, 'copyParameters' => array('destinationContainerIdentifier' => $destIdentifier, 'newName' => $newName, 'doWorkflow' => false));
$reply = $this->client->copy($params);
return $reply->copyReturn;
}
/*
Returns deleteReturn from identifier
*/
function delete($identifier)
{
$params = array ('authentication' => $this->auth, 'identifier' => $identifier);
$reply = $this->client->delete($params);
return $reply->deleteReturn;
}
/*
Returns publishReturn from identifier
*/
function publish($identifier, $destIdentifiers = false, $unpublish = false)
{
$publishInformation = array
(
'identifier' => $identifier,
'unpublish' => $unpublish
);
if($destIdentifiers)
{
if(is_array($destIdentifiers))
$publishInformation['destinations'] = $destIdentifiers;
else
$publishInformation['destinations'] = array($destIdentifiers);
}
$params = array ('authentication' => $this->auth, 'publishInformation' => $publishInformation);
$reply = $this->client->publish($params);
return $reply->publishReturn;
}
/*
For converting the multi-dimensional object to a multi-dimensional array
*/
function objectToArray($object)
{
if (is_object($object))
$object = get_object_vars($object);
if (is_array($object))
return array_map(array ($this,'objectToArray'), $object);
else
return $object;
}
/*
For converting the a multi-dimensional array to a multi-dimensional object
*/
function arrayToObject($array)
{
if (is_array($array) && (bool)count(array_filter(array_keys($array), 'is_string')))
return (object) array_map(array ($this,'arrayToObject'), $array);
elseif(is_array($array) && !(bool)count(array_filter(array_keys($array), 'is_string')))
{
$temp = array();
foreach($array as $arr)
{
if(is_array($arr))
$temp[] = (object) array_map(array ($this,'arrayToObject'), $arr);
else
$temp[] = $arr;
}
return $temp;
}
else
return $array;
}
/*
For checking values in array/object
*/
function test($arr)
{
echo "<pre>";
print_r($arr);
echo "</pre>";
}
}
?>