|
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 implements ICalDAVRequestFactory |
|
20
|
|
|
{ |
|
21
|
|
|
private function __construct(){} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var ICalDAVRequestFactory |
|
25
|
|
|
*/ |
|
26
|
|
|
private static $instance; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return ICalDAVRequestFactory |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function getInstance(){ |
|
32
|
|
|
if(is_null(self::$instance)) self::$instance = new CalDAVRequestFactory(); |
|
33
|
|
|
return self::$instance; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Override which class is used to create new request objects. |
|
38
|
|
|
* @param ICalDAVRequestFactory $factory |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function setInstance(ICalDAVRequestFactory $factory) { |
|
41
|
|
|
self::$instance = $factory; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $type |
|
46
|
|
|
* @param array $params |
|
47
|
|
|
* @return IAbstractWebDAVRequest|null |
|
48
|
|
|
* @throws \InvalidArgumentException |
|
49
|
|
|
*/ |
|
50
|
|
|
public function build($type, $params = []){ |
|
51
|
|
|
switch(strtoupper($type)){ |
|
52
|
|
|
case self::PrincipalRequestType: |
|
53
|
|
|
return new UserPrincipalRequest(); |
|
54
|
|
|
case self::CalendarHomeRequestType: |
|
55
|
|
|
return new CalendarHomeRequest(); |
|
56
|
|
|
case self::CalendarsRequestType: |
|
57
|
|
|
return new GetCalendarsRequest(); |
|
58
|
|
|
case self::CalendarRequestType: |
|
59
|
|
|
return new GetCalendarRequest(); |
|
60
|
|
|
case self::CalendarSyncRequestType: |
|
61
|
|
|
if(count($params) == 0 ) |
|
62
|
|
|
throw new \InvalidArgumentException(); |
|
63
|
|
|
return new CalendarSyncRequest($params[0]); |
|
64
|
|
|
case self::CalendarMultiGetRequestType: |
|
65
|
|
|
if(count($params) == 0 ) |
|
66
|
|
|
throw new \InvalidArgumentException(); |
|
67
|
|
|
return new CalendarMultiGetRequest($params[0]); |
|
68
|
|
|
case self::CalendarQueryRequestType: |
|
69
|
|
|
if(count($params) == 0 ) |
|
70
|
|
|
throw new \InvalidArgumentException(); |
|
71
|
|
|
return new CalendarQueryRequest($params[0]); |
|
72
|
|
|
case self::CalendarCreateRequestType: |
|
73
|
|
|
if(count($params) == 0 ) |
|
74
|
|
|
throw new \InvalidArgumentException(); |
|
75
|
|
|
return new CalendarCreateRequest($params[0]); |
|
76
|
|
|
case self::EventCreateRequestType: |
|
77
|
|
|
if(count($params) == 0 ) |
|
78
|
|
|
throw new \InvalidArgumentException(); |
|
79
|
|
|
return new EventCreateRequest($params[0]); |
|
80
|
|
|
case self::EventUpdateRequestType: |
|
81
|
|
|
if(count($params) == 0 ) |
|
82
|
|
|
throw new \InvalidArgumentException(); |
|
83
|
|
|
return new EventUpdateRequest($params[0]); |
|
84
|
|
|
} |
|
85
|
|
|
return null; |
|
86
|
|
|
} |
|
87
|
|
|
} |