aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Comments/RootCollection.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/Comments/RootCollection.php')
-rw-r--r--apps/dav/lib/Comments/RootCollection.php107
1 files changed, 32 insertions, 75 deletions
diff --git a/apps/dav/lib/Comments/RootCollection.php b/apps/dav/lib/Comments/RootCollection.php
index 839eb34aa90..493d73ec531 100644
--- a/apps/dav/lib/Comments/RootCollection.php
+++ b/apps/dav/lib/Comments/RootCollection.php
@@ -1,81 +1,35 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\DAV\Comments;
use OCP\Comments\CommentsEntityEvent;
use OCP\Comments\ICommentsManager;
-use OCP\ILogger;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserManager;
use OCP\IUserSession;
-use Sabre\DAV\Exception\NotAuthenticated;
+use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\Forbidden;
+use Sabre\DAV\Exception\NotAuthenticated;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class RootCollection implements ICollection {
-
/** @var EntityTypeCollection[]|null */
- private $entityTypeCollections;
-
- /** @var ICommentsManager */
- protected $commentsManager;
-
- /** @var string */
- protected $name = 'comments';
+ private ?array $entityTypeCollections = null;
+ protected string $name = 'comments';
- /** @var ILogger */
- protected $logger;
-
- /** @var IUserManager */
- protected $userManager;
-
- /** @var IUserSession */
- protected $userSession;
-
- /** @var EventDispatcherInterface */
- protected $dispatcher;
-
- /**
- * @param ICommentsManager $commentsManager
- * @param IUserManager $userManager
- * @param IUserSession $userSession
- * @param EventDispatcherInterface $dispatcher
- * @param ILogger $logger
- */
public function __construct(
- ICommentsManager $commentsManager,
- IUserManager $userManager,
- IUserSession $userSession,
- EventDispatcherInterface $dispatcher,
- ILogger $logger)
- {
- $this->commentsManager = $commentsManager;
- $this->logger = $logger;
- $this->userManager = $userManager;
- $this->userSession = $userSession;
- $this->dispatcher = $dispatcher;
+ protected ICommentsManager $commentsManager,
+ protected IUserManager $userManager,
+ protected IUserSession $userSession,
+ protected IEventDispatcher $dispatcher,
+ protected LoggerInterface $logger,
+ ) {
}
/**
@@ -86,15 +40,16 @@ class RootCollection implements ICollection {
* @throws NotAuthenticated
*/
protected function initCollections() {
- if($this->entityTypeCollections !== null) {
+ if ($this->entityTypeCollections !== null) {
return;
}
$user = $this->userSession->getUser();
- if(is_null($user)) {
+ if (is_null($user)) {
throw new NotAuthenticated();
}
- $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
+ $event = new CommentsEntityEvent();
+ $this->dispatcher->dispatchTyped($event);
$this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
$this->entityTypeCollections = [];
@@ -118,7 +73,7 @@ class RootCollection implements ICollection {
* @return null|string
* @throws Forbidden
*/
- function createFile($name, $data = null) {
+ public function createFile($name, $data = null) {
throw new Forbidden('Cannot create comments by id');
}
@@ -128,7 +83,7 @@ class RootCollection implements ICollection {
* @param string $name
* @throws Forbidden
*/
- function createDirectory($name) {
+ public function createDirectory($name) {
throw new Forbidden('Permission denied to create collections');
}
@@ -142,9 +97,9 @@ class RootCollection implements ICollection {
* @return \Sabre\DAV\INode
* @throws NotFound
*/
- function getChild($name) {
+ public function getChild($name) {
$this->initCollections();
- if(isset($this->entityTypeCollections[$name])) {
+ if (isset($this->entityTypeCollections[$name])) {
return $this->entityTypeCollections[$name];
}
throw new NotFound('Entity type "' . $name . '" not found."');
@@ -155,8 +110,9 @@ class RootCollection implements ICollection {
*
* @return \Sabre\DAV\INode[]
*/
- function getChildren() {
+ public function getChildren() {
$this->initCollections();
+ assert(!is_null($this->entityTypeCollections));
return $this->entityTypeCollections;
}
@@ -166,8 +122,9 @@ class RootCollection implements ICollection {
* @param string $name
* @return bool
*/
- function childExists($name) {
+ public function childExists($name) {
$this->initCollections();
+ assert(!is_null($this->entityTypeCollections));
return isset($this->entityTypeCollections[$name]);
}
@@ -176,7 +133,7 @@ class RootCollection implements ICollection {
*
* @throws Forbidden
*/
- function delete() {
+ public function delete() {
throw new Forbidden('Permission denied to delete this collection');
}
@@ -187,7 +144,7 @@ class RootCollection implements ICollection {
*
* @return string
*/
- function getName() {
+ public function getName() {
return $this->name;
}
@@ -197,16 +154,16 @@ class RootCollection implements ICollection {
* @param string $name The new name
* @throws Forbidden
*/
- function setName($name) {
+ public function setName($name) {
throw new Forbidden('Permission denied to rename this collection');
}
/**
* Returns the last modification time, as a unix timestamp
*
- * @return int
+ * @return ?int
*/
- function getLastModified() {
+ public function getLastModified() {
return null;
}
}