1<?php
2
3namespace Sabre\CalDAV\Backend;
4use Sabre\DAV;
5use Sabre\CalDAV;
6
7class MockScheduling extends Mock implements SchedulingSupport {
8
9    public $schedulingObjects = [];
10
11    /**
12     * Returns a single scheduling object.
13     *
14     * The returned array should contain the following elements:
15     *   * uri - A unique basename for the object. This will be used to
16     *           construct a full uri.
17     *   * calendardata - The iCalendar object
18     *   * lastmodified - The last modification date. Can be an int for a unix
19     *                    timestamp, or a PHP DateTime object.
20     *   * etag - A unique token that must change if the object changed.
21     *   * size - The size of the object, in bytes.
22     *
23     * @param string $principalUri
24     * @param string $objectUri
25     * @return array
26     */
27    public function getSchedulingObject($principalUri, $objectUri) {
28
29        if (isset($this->schedulingObjects[$principalUri][$objectUri])) {
30            return $this->schedulingObjects[$principalUri][$objectUri];
31        }
32
33    }
34
35    /**
36     * Returns all scheduling objects for the inbox collection.
37     *
38     * These objects should be returned as an array. Every item in the array
39     * should follow the same structure as returned from getSchedulingObject.
40     *
41     * The main difference is that 'calendardata' is optional.
42     *
43     * @param string $principalUri
44     * @return array
45     */
46    public function getSchedulingObjects($principalUri) {
47
48        if (isset($this->schedulingObjects[$principalUri])) {
49            return array_values($this->schedulingObjects[$principalUri]);
50        }
51        return [];
52
53    }
54
55    /**
56     * Deletes a scheduling object
57     *
58     * @param string $principalUri
59     * @param string $objectUri
60     * @return void
61     */
62    public function deleteSchedulingObject($principalUri, $objectUri) {
63
64        if (isset($this->schedulingObjects[$principalUri][$objectUri])) {
65            unset($this->schedulingObjects[$principalUri][$objectUri]);
66        }
67
68    }
69
70    /**
71     * Creates a new scheduling object. This should land in a users' inbox.
72     *
73     * @param string $principalUri
74     * @param string $objectUri
75     * @param string $objectData;
76     * @return void
77     */
78    public function createSchedulingObject($principalUri, $objectUri, $objectData) {
79
80        if (!isset($this->schedulingObjects[$principalUri])) {
81            $this->schedulingObjects[$principalUri] = [];
82        }
83        $this->schedulingObjects[$principalUri][$objectUri] = [
84            'uri' => $objectUri,
85            'calendardata' => $objectData,
86            'lastmodified' => null,
87            'etag' => '"' . md5($objectData) . '"',
88            'size' => strlen($objectData)
89        ];
90
91    }
92
93}
94