|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Description: a SOAP Calendar Server. |
|
5
|
|
|
*/ |
|
6
|
|
|
if (!@require_once __DIR__ . '/SOAP/Server.php') { |
|
7
|
|
|
exit('You must have PEAR::SOAP installed'); |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
if (!@require_once __DIR__ . '/Calendar/Calendar.php') { |
|
11
|
|
|
define('CALENDAR_ROOT', '../../'); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Calendar_Server. |
|
16
|
|
|
*/ |
|
17
|
|
|
class Calendar_Server |
|
18
|
|
|
{ |
|
19
|
|
|
public $__dispatch_map = []; |
|
20
|
|
|
public $__typedef = []; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->__dispatch_map['getMonth'] = [ |
|
25
|
|
|
'in' => ['year' => 'int', 'month' => 'int'], |
|
26
|
|
|
'out' => ['month' => '{urn:PEAR_SOAP_Calendar}Month'], |
|
27
|
|
|
]; |
|
28
|
|
|
$this->__typedef['Month'] = [ |
|
29
|
|
|
'monthname' => 'string', |
|
30
|
|
|
'days' => '{urn:PEAR_SOAP_Calendar}MonthDays', |
|
31
|
|
|
]; |
|
32
|
|
|
$this->__typedef['MonthDays'] = [['{urn:PEAR_SOAP_Calendar}Day']]; |
|
33
|
|
|
$this->__typedef['Day'] = [ |
|
34
|
|
|
'isFirst' => 'int', |
|
35
|
|
|
'isLast' => 'int', |
|
36
|
|
|
'isEmpty' => 'int', |
|
37
|
|
|
'day' => 'int', |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param $methodname |
|
43
|
|
|
* @return mixed|void |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __dispatch($methodname) |
|
46
|
|
|
{ |
|
47
|
|
|
if (isset($this->__dispatch_map[$methodname])) { |
|
48
|
|
|
return $this->__dispatch_map[$methodname]; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param $year |
|
54
|
|
|
* @param $month |
|
55
|
|
|
* |
|
56
|
|
|
* @return array |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getMonth($year, $month) |
|
59
|
|
|
{ |
|
60
|
|
|
require_once CALENDAR_ROOT . 'Month/Weekdays.php'; |
|
61
|
|
|
$Month = new Calendar_Month_Weekdays($year, $month); |
|
62
|
|
|
if (!$Month->isValid()) { |
|
63
|
|
|
$V = $Month->getValidator(); |
|
64
|
|
|
$errorMsg = ''; |
|
65
|
|
|
while (false !== ($error = $V->fetch())) { |
|
66
|
|
|
$errorMsg .= $error->toString() . "\n"; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return new Soap_fault($errorMsg, 'Client'); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
$monthname = date('F Y', $Month->getTimestamp()); |
|
|
|
|
|
|
72
|
|
|
$days = []; |
|
73
|
|
|
$Month->build(); |
|
74
|
|
|
while (false !== ($Day = $Month->fetch())) { |
|
75
|
|
|
$day = [ |
|
76
|
|
|
'isFirst' => (int)$Day->isFirst(), |
|
77
|
|
|
'isLast' => (int)$Day->isLast(), |
|
78
|
|
|
'isEmpty' => (int)$Day->isEmpty(), |
|
79
|
|
|
'day' => (int)$Day->thisDay(), |
|
80
|
|
|
]; |
|
81
|
|
|
$days[] = $day; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return ['monthname' => $monthname, 'days' => $days]; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$server = new Soap_server(); |
|
|
|
|
|
|
89
|
|
|
$server->_auto_translation = true; |
|
90
|
|
|
$calendar = new Calendar_Server(); |
|
91
|
|
|
$server->addObjectMap($calendar, 'urn:PEAR_SOAP_Calendar'); |
|
92
|
|
|
|
|
93
|
|
|
if ('POST' === mb_strtoupper($_SERVER['REQUEST_METHOD'])) { |
|
94
|
|
|
$server->service($GLOBALS['HTTP_RAW_POST_DATA']); |
|
95
|
|
|
} else { |
|
96
|
|
|
require_once __DIR__ . '/SOAP/Disco.php'; |
|
97
|
|
|
$disco = new SOAP_DISCO_Server($server, 'PEAR_SOAP_Calendar'); |
|
|
|
|
|
|
98
|
|
|
if (\Xmf\Request::hasVar('QUERY_STRING', 'SERVER') && 0 == strcasecmp($_SERVER['QUERY_STRING'], 'wsdl')) { |
|
99
|
|
|
header('Content-type: text/xml'); |
|
100
|
|
|
echo $disco->getWSDL(); |
|
101
|
|
|
} else { |
|
102
|
|
|
echo 'This is a PEAR::SOAP Calendar Server. For client try <a href="8.php">here</a><br>'; |
|
103
|
|
|
echo 'For WSDL try <a href="?wsdl">here</a>'; |
|
104
|
|
|
} |
|
105
|
|
|
exit; |
|
106
|
|
|
} |
|
107
|
|
|
|