1
|
|
|
<?php namespace CalDAVClient\Facade\Requests; |
2
|
|
|
/** |
3
|
|
|
* Copyright 2017 OpenStack Foundation |
4
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
5
|
|
|
* you may not use this file except in compliance with the License. |
6
|
|
|
* You may obtain a copy of the License at |
7
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
8
|
|
|
* Unless required by applicable law or agreed to in writing, software |
9
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
10
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
11
|
|
|
* See the License for the specific language governing permissions and |
12
|
|
|
* limitations under the License. |
13
|
|
|
**/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class CalDAVRequestFactory |
17
|
|
|
* @package CalDAVClient\Facade\Requests |
18
|
|
|
*/ |
19
|
|
|
final class CalDAVRequestFactory |
20
|
|
|
{ |
21
|
|
|
const PrincipalRequestType = 'PRINCIPAL'; |
22
|
|
|
const CalendarHomeRequestType = 'CALENDAR_HOME'; |
23
|
|
|
const CalendarsRequestType = 'CALENDARS'; |
24
|
|
|
const CalendarRequestType = 'CALENDAR'; |
25
|
|
|
const CalendarSyncRequestType = 'CALENDAR_SYNC'; |
26
|
|
|
const CalendarMultiGetRequestType = 'CALENDAR_MULTIGET'; |
27
|
|
|
const CalendarQueryRequestType = 'CALENDAR_QUERY'; |
28
|
|
|
const CalendarCreateRequestType = 'CREATE_CALENDAR'; |
29
|
|
|
const EventCreateRequestType = 'CREATE_EVENT'; |
30
|
|
|
const EventUpdateRequestType = 'UPDATE_EVENT'; |
31
|
|
|
|
32
|
|
|
private function __construct(){} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var CalDAVRequestFactory |
36
|
|
|
*/ |
37
|
|
|
private static $instance; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return CalDAVRequestFactory |
41
|
|
|
*/ |
42
|
|
|
public static function getInstance(){ |
43
|
|
|
if(is_null(self::$instance)) self::$instance = new CalDAVRequestFactory(); |
44
|
|
|
return self::$instance; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $type |
49
|
|
|
* @param array $params |
50
|
|
|
* @return IAbstractWebDAVRequest|null |
51
|
|
|
* @throws \InvalidArgumentException |
52
|
|
|
*/ |
53
|
|
|
public function build($type, $params = []){ |
54
|
|
|
switch(strtoupper($type)){ |
55
|
|
|
case self::PrincipalRequestType: |
56
|
|
|
return new UserPrincipalRequest(); |
57
|
|
|
case self::CalendarHomeRequestType: |
58
|
|
|
return new CalendarHomeRequest(); |
59
|
|
|
case self::CalendarsRequestType: |
60
|
|
|
return new GetCalendarsRequest(); |
61
|
|
|
case self::CalendarRequestType: |
62
|
|
|
return new GetCalendarRequest(); |
63
|
|
|
case self::CalendarSyncRequestType: |
64
|
|
|
if(count($params) == 0 ) |
65
|
|
|
throw new \InvalidArgumentException(); |
66
|
|
|
return new CalendarSyncRequest($params[0]); |
67
|
|
|
case self::CalendarMultiGetRequestType: |
68
|
|
|
if(count($params) == 0 ) |
69
|
|
|
throw new \InvalidArgumentException(); |
70
|
|
|
return new CalendarMultiGetRequest($params[0]); |
71
|
|
|
case self::CalendarQueryRequestType: |
72
|
|
|
if(count($params) == 0 ) |
73
|
|
|
throw new \InvalidArgumentException(); |
74
|
|
|
return new CalendarQueryRequest($params[0]); |
75
|
|
|
case self::CalendarCreateRequestType: |
76
|
|
|
if(count($params) == 0 ) |
77
|
|
|
throw new \InvalidArgumentException(); |
78
|
|
|
return new CalendarCreateRequest($params[0]); |
79
|
|
|
case self::EventCreateRequestType: |
80
|
|
|
if(count($params) == 0 ) |
81
|
|
|
throw new \InvalidArgumentException(); |
82
|
|
|
return new EventCreateRequest($params[0]); |
83
|
|
|
case self::EventUpdateRequestType: |
84
|
|
|
if(count($params) == 0 ) |
85
|
|
|
throw new \InvalidArgumentException(); |
86
|
|
|
return new EventUpdateRequest($params[0]); |
87
|
|
|
} |
88
|
|
|
return null; |
89
|
|
|
} |
90
|
|
|
} |