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