2016-02-24 07:23:44 -05:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2016-02-24 07:23:44 -05:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-02-24 07:23:44 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCP\Comments;
|
|
|
|
|
|
2019-10-16 06:36:03 -04:00
|
|
|
use OCP\EventDispatcher\Event;
|
2016-02-24 07:23:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class CommentsEntityEvent
|
|
|
|
|
*
|
|
|
|
|
* @since 9.1.0
|
2023-07-11 05:06:29 -04:00
|
|
|
* @since 28.0.0 Dispatched as a typed event
|
2016-02-24 07:23:44 -05:00
|
|
|
*/
|
|
|
|
|
class CommentsEntityEvent extends Event {
|
2021-02-09 07:53:41 -05:00
|
|
|
/**
|
2024-02-14 14:48:27 -05:00
|
|
|
* @since 9.1.0
|
2023-07-11 05:06:29 -04:00
|
|
|
* @deprecated 22.0.0 - Listen to the typed event instead.
|
2021-02-09 07:53:41 -05:00
|
|
|
*/
|
2020-04-10 10:54:27 -04:00
|
|
|
public const EVENT_ENTITY = 'OCP\Comments\ICommentsManager::registerEntity';
|
2016-02-24 07:23:44 -05:00
|
|
|
|
|
|
|
|
/** @var \Closure[] */
|
|
|
|
|
protected $collections;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DispatcherEvent constructor.
|
|
|
|
|
*
|
|
|
|
|
* @since 9.1.0
|
|
|
|
|
*/
|
2023-07-11 05:06:29 -04:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-02-24 07:23:44 -05:00
|
|
|
$this->collections = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @param \Closure $entityExistsFunction The closure should take one
|
|
|
|
|
* argument, which is the id of the entity, that comments
|
|
|
|
|
* should be handled for. The return should then be bool,
|
|
|
|
|
* depending on whether comments are allowed (true) or not.
|
|
|
|
|
* @throws \OutOfBoundsException when the entity name is already taken
|
|
|
|
|
* @since 9.1.0
|
|
|
|
|
*/
|
|
|
|
|
public function addEntityCollection($name, \Closure $entityExistsFunction) {
|
|
|
|
|
if (isset($this->collections[$name])) {
|
|
|
|
|
throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->collections[$name] = $entityExistsFunction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return \Closure[]
|
|
|
|
|
* @since 9.1.0
|
|
|
|
|
*/
|
|
|
|
|
public function getEntityCollections() {
|
|
|
|
|
return $this->collections;
|
|
|
|
|
}
|
|
|
|
|
}
|