Collection.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAVACL\FS;
  4. use Sabre\DAV\Exception\Forbidden;
  5. use Sabre\DAV\Exception\NotFound;
  6. use Sabre\DAV\FSExt\Directory as BaseCollection;
  7. use Sabre\DAVACL\ACLTrait;
  8. use Sabre\DAVACL\IACL;
  9. /**
  10. * This is an ACL-enabled collection.
  11. *
  12. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  13. * @author Evert Pot (http://evertpot.com/)
  14. * @license http://sabre.io/license/ Modified BSD License
  15. */
  16. class Collection extends BaseCollection implements IACL
  17. {
  18. use ACLTrait;
  19. /**
  20. * A list of ACL rules.
  21. *
  22. * @var array
  23. */
  24. protected $acl;
  25. /**
  26. * Owner uri, or null for no owner.
  27. *
  28. * @var string|null
  29. */
  30. protected $owner;
  31. /**
  32. * Constructor.
  33. *
  34. * @param string $path on-disk path
  35. * @param array $acl ACL rules
  36. * @param string|null $owner principal owner string
  37. */
  38. public function __construct($path, array $acl, $owner = null)
  39. {
  40. parent::__construct($path);
  41. $this->acl = $acl;
  42. $this->owner = $owner;
  43. }
  44. /**
  45. * Returns a specific child node, referenced by its name.
  46. *
  47. * This method must throw Sabre\DAV\Exception\NotFound if the node does not
  48. * exist.
  49. *
  50. * @param string $name
  51. *
  52. * @throws NotFound
  53. *
  54. * @return \Sabre\DAV\INode
  55. */
  56. public function getChild($name)
  57. {
  58. $path = $this->path.'/'.$name;
  59. if (!file_exists($path)) {
  60. throw new NotFound('File could not be located');
  61. }
  62. if ('.' == $name || '..' == $name) {
  63. throw new Forbidden('Permission denied to . and ..');
  64. }
  65. if (is_dir($path)) {
  66. return new self($path, $this->acl, $this->owner);
  67. } else {
  68. return new File($path, $this->acl, $this->owner);
  69. }
  70. }
  71. /**
  72. * Returns the owner principal.
  73. *
  74. * This must be a url to a principal, or null if there's no owner
  75. *
  76. * @return string|null
  77. */
  78. public function getOwner()
  79. {
  80. return $this->owner;
  81. }
  82. /**
  83. * Returns a list of ACE's for this node.
  84. *
  85. * Each ACE has the following properties:
  86. * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  87. * currently the only supported privileges
  88. * * 'principal', a url to the principal who owns the node
  89. * * 'protected' (optional), indicating that this ACE is not allowed to
  90. * be updated.
  91. *
  92. * @return array
  93. */
  94. public function getACL()
  95. {
  96. return $this->acl;
  97. }
  98. }