Skip to content

Commit

Permalink
Merge pull request #34249 from nextcloud/bugfix/noid/reference-public
Browse files Browse the repository at this point in the history
Move Reference class to public namespace
  • Loading branch information
szaimen authored Sep 26, 2022
2 parents 671c365 + 042474b commit 4a034ac
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
'OCP\\Collaboration\\Reference\\IReference' => $baseDir . '/lib/public/Collaboration/Reference/IReference.php',
'OCP\\Collaboration\\Reference\\IReferenceManager' => $baseDir . '/lib/public/Collaboration/Reference/IReferenceManager.php',
'OCP\\Collaboration\\Reference\\IReferenceProvider' => $baseDir . '/lib/public/Collaboration/Reference/IReferenceProvider.php',
'OCP\\Collaboration\\Reference\\Reference' => $baseDir . '/lib/public/Collaboration/Reference/Reference.php',
'OCP\\Collaboration\\Reference\\RenderReferenceEvent' => $baseDir . '/lib/public/Collaboration/Reference/RenderReferenceEvent.php',
'OCP\\Collaboration\\Resources\\CollectionException' => $baseDir . '/lib/public/Collaboration/Resources/CollectionException.php',
'OCP\\Collaboration\\Resources\\ICollection' => $baseDir . '/lib/public/Collaboration/Resources/ICollection.php',
Expand Down Expand Up @@ -835,7 +836,6 @@
'OC\\Collaboration\\Reference\\File\\FileReferenceEventListener' => $baseDir . '/lib/private/Collaboration/Reference/File/FileReferenceEventListener.php',
'OC\\Collaboration\\Reference\\File\\FileReferenceProvider' => $baseDir . '/lib/private/Collaboration/Reference/File/FileReferenceProvider.php',
'OC\\Collaboration\\Reference\\LinkReferenceProvider' => $baseDir . '/lib/private/Collaboration/Reference/LinkReferenceProvider.php',
'OC\\Collaboration\\Reference\\Reference' => $baseDir . '/lib/private/Collaboration/Reference/Reference.php',
'OC\\Collaboration\\Reference\\ReferenceManager' => $baseDir . '/lib/private/Collaboration/Reference/ReferenceManager.php',
'OC\\Collaboration\\Resources\\Collection' => $baseDir . '/lib/private/Collaboration/Resources/Collection.php',
'OC\\Collaboration\\Resources\\Listener' => $baseDir . '/lib/private/Collaboration/Resources/Listener.php',
Expand Down
2 changes: 1 addition & 1 deletion lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Collaboration\\Reference\\IReference' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReference.php',
'OCP\\Collaboration\\Reference\\IReferenceManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReferenceManager.php',
'OCP\\Collaboration\\Reference\\IReferenceProvider' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/IReferenceProvider.php',
'OCP\\Collaboration\\Reference\\Reference' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/Reference.php',
'OCP\\Collaboration\\Reference\\RenderReferenceEvent' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Reference/RenderReferenceEvent.php',
'OCP\\Collaboration\\Resources\\CollectionException' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/CollectionException.php',
'OCP\\Collaboration\\Resources\\ICollection' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Resources/ICollection.php',
Expand Down Expand Up @@ -868,7 +869,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Collaboration\\Reference\\File\\FileReferenceEventListener' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/File/FileReferenceEventListener.php',
'OC\\Collaboration\\Reference\\File\\FileReferenceProvider' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/File/FileReferenceProvider.php',
'OC\\Collaboration\\Reference\\LinkReferenceProvider' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/LinkReferenceProvider.php',
'OC\\Collaboration\\Reference\\Reference' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/Reference.php',
'OC\\Collaboration\\Reference\\ReferenceManager' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Reference/ReferenceManager.php',
'OC\\Collaboration\\Resources\\Collection' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Resources/Collection.php',
'OC\\Collaboration\\Resources\\Listener' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Resources/Listener.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

namespace OC\Collaboration\Reference\File;

use OC\Collaboration\Reference\Reference;
use OC\User\NoUserException;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\Collaboration\Reference\Reference;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OC\SystemConfig;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\Collaboration\Reference\Reference;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\NotFoundException;
use OCP\Http\Client\IClientService;
Expand Down
1 change: 1 addition & 0 deletions lib/private/Collaboration/Reference/ReferenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Collaboration\Reference\IReferenceProvider;
use OCP\Collaboration\Reference\Reference;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IURLGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,99 +23,171 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OC\Collaboration\Reference;

use OCP\Collaboration\Reference\IReference;
namespace OCP\Collaboration\Reference;

/**
* @since 25.0.0
*/
class Reference implements IReference {
private string $reference;
protected string $reference;

private bool $accessible = true;
protected bool $accessible = true;

private ?string $title = null;
private ?string $description = null;
private ?string $imageUrl = null;
private ?string $contentType = null;
private ?string $url = null;
protected ?string $title = null;
protected ?string $description = null;
protected ?string $imageUrl = null;
protected ?string $contentType = null;
protected ?string $url = null;

private ?string $richObjectType = null;
private ?array $richObject = null;
protected ?string $richObjectType = null;
protected ?array $richObject = null;

/**
* @since 25.0.0
*/
public function __construct(string $reference) {
$this->reference = $reference;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getId(): string {
return $this->reference;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function setAccessible(bool $accessible): void {
$this->accessible = $accessible;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getAccessible(): bool {
return $this->accessible;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function setTitle(string $title): void {
$this->title = $title;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getTitle(): string {
return $this->title ?? $this->reference;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function setDescription(?string $description): void {
$this->description = $description;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getDescription(): ?string {
return $this->description;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function setImageUrl(?string $imageUrl): void {
$this->imageUrl = $imageUrl;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getImageUrl(): ?string {
return $this->imageUrl;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function setImageContentType(?string $contentType): void {
$this->contentType = $contentType;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getImageContentType(): ?string {
return $this->contentType;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function setUrl(?string $url): void {
$this->url = $url;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getUrl(): ?string {
return $this->url;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function setRichObject(string $type, ?array $richObject): void {
$this->richObjectType = $type;
$this->richObject = $richObject;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getRichObjectType(): string {
if ($this->richObjectType === null) {
return 'open-graph';
}
return $this->richObjectType;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getRichObject(): array {
if ($this->richObject === null) {
return $this->getOpenGraphObject();
}
return $this->richObject;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function getOpenGraphObject(): array {
return [
'id' => $this->getId(),
Expand All @@ -126,6 +198,11 @@ public function getOpenGraphObject(): array {
];
}

/**
* @param IReference $reference
* @return array
* @since 25.0.0
*/
public static function toCache(IReference $reference): array {
return [
'id' => $reference->getId(),
Expand All @@ -140,6 +217,11 @@ public static function toCache(IReference $reference): array {
];
}

/**
* @param array $cache
* @return IReference
* @since 25.0.0
*/
public static function fromCache(array $cache): IReference {
$reference = new Reference($cache['id']);
$reference->setTitle($cache['title']);
Expand All @@ -152,6 +234,10 @@ public static function fromCache(array $cache): IReference {
return $reference;
}

/**
* @inheritdoc
* @since 25.0.0
*/
public function jsonSerialize() {
return [
'richObjectType' => $this->getRichObjectType(),
Expand Down

0 comments on commit 4a034ac

Please sign in to comment.