MkCol.php 1.9 KB

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