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