xref: /plugin/davcal/vendor/sabre/dav/lib/DAV/MkCol.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\DAV;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehler/**
6*a1a3b679SAndreas Boehler * This class represents a MKCOL operation.
7*a1a3b679SAndreas Boehler *
8*a1a3b679SAndreas Boehler * MKCOL creates a new collection. MKCOL comes in two flavours:
9*a1a3b679SAndreas Boehler *
10*a1a3b679SAndreas Boehler * 1. MKCOL with no body, signifies the creation of a simple collection.
11*a1a3b679SAndreas Boehler * 2. MKCOL with a request body. This can create a collection with a specific
12*a1a3b679SAndreas Boehler *    resource type, and a set of properties that should be set on the new
13*a1a3b679SAndreas Boehler *    collection. This can be used to create caldav calendars, carddav address
14*a1a3b679SAndreas Boehler *    books, etc.
15*a1a3b679SAndreas Boehler *
16*a1a3b679SAndreas Boehler * Property updates must always be atomic. This means that a property update
17*a1a3b679SAndreas Boehler * must either completely succeed, or completely fail.
18*a1a3b679SAndreas Boehler *
19*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
20*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
21*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
22*a1a3b679SAndreas Boehler */
23*a1a3b679SAndreas Boehlerclass MkCol extends PropPatch {
24*a1a3b679SAndreas Boehler
25*a1a3b679SAndreas Boehler    /**
26*a1a3b679SAndreas Boehler     * A list of resource-types in clark-notation.
27*a1a3b679SAndreas Boehler     *
28*a1a3b679SAndreas Boehler     * @var array
29*a1a3b679SAndreas Boehler     */
30*a1a3b679SAndreas Boehler    protected $resourceType;
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler    /**
33*a1a3b679SAndreas Boehler     * Creates the MKCOL object.
34*a1a3b679SAndreas Boehler     *
35*a1a3b679SAndreas Boehler     * @param string[] $resourceType List of resourcetype values.
36*a1a3b679SAndreas Boehler     * @param array $mutations List of new properties values.
37*a1a3b679SAndreas Boehler     */
38*a1a3b679SAndreas Boehler    function __construct(array $resourceType, array $mutations) {
39*a1a3b679SAndreas Boehler
40*a1a3b679SAndreas Boehler        $this->resourceType = $resourceType;
41*a1a3b679SAndreas Boehler        parent::__construct($mutations);
42*a1a3b679SAndreas Boehler
43*a1a3b679SAndreas Boehler    }
44*a1a3b679SAndreas Boehler
45*a1a3b679SAndreas Boehler    /**
46*a1a3b679SAndreas Boehler     * Returns the resourcetype of the new collection.
47*a1a3b679SAndreas Boehler     *
48*a1a3b679SAndreas Boehler     * @return string[]
49*a1a3b679SAndreas Boehler     */
50*a1a3b679SAndreas Boehler    function getResourceType() {
51*a1a3b679SAndreas Boehler
52*a1a3b679SAndreas Boehler        return $this->resourceType;
53*a1a3b679SAndreas Boehler
54*a1a3b679SAndreas Boehler    }
55*a1a3b679SAndreas Boehler
56*a1a3b679SAndreas Boehler    /**
57*a1a3b679SAndreas Boehler     * Returns true or false if the MKCOL operation has at least the specified
58*a1a3b679SAndreas Boehler     * resource type.
59*a1a3b679SAndreas Boehler     *
60*a1a3b679SAndreas Boehler     * If the resourcetype is specified as an array, all resourcetypes are
61*a1a3b679SAndreas Boehler     * checked.
62*a1a3b679SAndreas Boehler     *
63*a1a3b679SAndreas Boehler     * @param string|string[] $resourceType
64*a1a3b679SAndreas Boehler     */
65*a1a3b679SAndreas Boehler    function hasResourceType($resourceType) {
66*a1a3b679SAndreas Boehler
67*a1a3b679SAndreas Boehler        return count(array_diff((array)$resourceType, $this->resourceType)) === 0;
68*a1a3b679SAndreas Boehler
69*a1a3b679SAndreas Boehler    }
70*a1a3b679SAndreas Boehler
71*a1a3b679SAndreas Boehler}
72