2018-09-28 11:41:24 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-09-08 13:46:22 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Model;
|
|
|
|
|
|
|
|
use JsonSerializable;
|
2023-05-25 20:45:28 +00:00
|
|
|
use OCA\Social\Tools\Traits\TArrayTools;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
/**
|
|
|
|
* Class InstancePath
|
|
|
|
*
|
|
|
|
* @package OCA\Social\Model
|
|
|
|
*/
|
|
|
|
class InstancePath implements JsonSerializable {
|
2018-09-28 11:41:24 +00:00
|
|
|
use TArrayTools;
|
|
|
|
|
2018-11-27 16:58:08 +00:00
|
|
|
|
2022-04-15 11:34:01 +00:00
|
|
|
public const TYPE_PUBLIC = 0;
|
|
|
|
public const TYPE_INBOX = 1;
|
|
|
|
public const TYPE_GLOBAL = 2;
|
|
|
|
public const TYPE_FOLLOWERS = 3;
|
2023-01-05 09:58:13 +00:00
|
|
|
public const TYPE_ALL = 4;
|
2018-11-21 19:22:46 +00:00
|
|
|
|
2022-04-15 11:34:01 +00:00
|
|
|
public const PRIORITY_NONE = 0;
|
|
|
|
public const PRIORITY_LOW = 1;
|
|
|
|
public const PRIORITY_MEDIUM = 2;
|
|
|
|
public const PRIORITY_HIGH = 3;
|
|
|
|
public const PRIORITY_TOP = 4;
|
2018-10-01 12:14:23 +00:00
|
|
|
|
2022-04-15 11:01:18 +00:00
|
|
|
private string $uri = '';
|
|
|
|
private int $type = 0;
|
|
|
|
private int $priority = 0;
|
2018-11-27 16:58:08 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2018-11-21 19:22:46 +00:00
|
|
|
/**
|
|
|
|
* InstancePath constructor.
|
|
|
|
*
|
|
|
|
* @param string $uri
|
|
|
|
* @param int $type
|
2018-11-27 16:58:08 +00:00
|
|
|
* @param int $priority
|
2018-11-21 19:22:46 +00:00
|
|
|
*/
|
2018-11-27 16:58:08 +00:00
|
|
|
public function __construct(string $uri = '', int $type = 0, int $priority = 0) {
|
2018-10-01 12:14:23 +00:00
|
|
|
$this->uri = $uri;
|
2018-11-21 19:22:46 +00:00
|
|
|
$this->type = $type;
|
2018-11-27 16:58:08 +00:00
|
|
|
$this->priority = $priority;
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-27 16:58:08 +00:00
|
|
|
/**
|
|
|
|
* @param string $uri
|
|
|
|
*
|
|
|
|
* @return InstancePath
|
|
|
|
*/
|
|
|
|
public function setUri(string $uri): InstancePath {
|
|
|
|
$this->uri = $uri;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-10-01 12:14:23 +00:00
|
|
|
public function getUri(): string {
|
|
|
|
return $this->uri;
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-01 12:14:23 +00:00
|
|
|
|
2018-11-27 16:58:08 +00:00
|
|
|
/**
|
|
|
|
* @param int $type
|
|
|
|
*
|
|
|
|
* @return InstancePath
|
|
|
|
*/
|
|
|
|
public function setType(int $type): InstancePath {
|
|
|
|
$this->type = $type;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2018-11-21 19:22:46 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getType(): int {
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-27 16:58:08 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPriority(): int {
|
|
|
|
return $this->priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $priority
|
|
|
|
*
|
|
|
|
* @return InstancePath
|
|
|
|
*/
|
|
|
|
public function setPriority(int $priority): InstancePath {
|
|
|
|
$this->priority = $priority;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-17 14:20:02 +00:00
|
|
|
public function getProtocol(): string {
|
|
|
|
$info = parse_url($this->getUri());
|
|
|
|
|
|
|
|
return $this->get('scheme', $info, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-21 19:22:46 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAddress(): string {
|
2018-11-27 16:58:08 +00:00
|
|
|
$info = parse_url($this->getUri());
|
2018-11-21 19:22:46 +00:00
|
|
|
|
|
|
|
return $this->get('host', $info, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/**
|
2018-11-12 22:55:10 +00:00
|
|
|
* @return string
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function getPath(): string {
|
2018-11-27 16:58:08 +00:00
|
|
|
$info = parse_url($this->getUri());
|
2018-10-01 12:14:23 +00:00
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
return $this->get('path', $info, '');
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 19:22:46 +00:00
|
|
|
|
2018-11-27 16:58:08 +00:00
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
2018-11-21 19:22:46 +00:00
|
|
|
public function import(array $data) {
|
2018-11-27 16:58:08 +00:00
|
|
|
$this->setUri($this->get('uri', $data, ''));
|
|
|
|
$this->setType($this->getInt('type', $data, 0));
|
|
|
|
$this->setPriority($this->getInt('priority', $data, 0));
|
2018-11-21 19:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-01 12:14:23 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function jsonSerialize(): array {
|
2018-09-28 11:41:24 +00:00
|
|
|
return [
|
2022-04-15 11:34:01 +00:00
|
|
|
'uri' => $this->getUri(),
|
|
|
|
'type' => $this->getType(),
|
2018-11-27 16:58:08 +00:00
|
|
|
'priority' => $this->getPriority()
|
2018-09-28 11:41:24 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|