2018-09-28 11:41:24 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nextcloud - Social Support
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Model;
|
|
|
|
|
|
|
|
|
2018-10-12 06:44:35 +00:00
|
|
|
use daita\MySmallPhpTools\Traits\TArrayTools;
|
2018-09-28 11:41:24 +00:00
|
|
|
use JsonSerializable;
|
|
|
|
|
2018-10-01 12:14:23 +00:00
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
/**
|
|
|
|
* Class InstancePath
|
|
|
|
*
|
|
|
|
* @package OCA\Social\Model
|
|
|
|
*/
|
|
|
|
class InstancePath implements JsonSerializable {
|
2018-10-01 12:14:23 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
use TArrayTools;
|
|
|
|
|
2018-11-27 16:58:08 +00:00
|
|
|
|
2018-11-21 19:22:46 +00:00
|
|
|
const TYPE_PUBLIC = 0;
|
|
|
|
const TYPE_INBOX = 1;
|
|
|
|
const TYPE_GLOBAL = 2;
|
|
|
|
const TYPE_FOLLOWERS = 3;
|
|
|
|
|
2018-11-27 16:58:08 +00:00
|
|
|
const PRIORITY_NONE = 0;
|
|
|
|
const PRIORITY_LOW = 1;
|
|
|
|
const PRIORITY_MEDIUM = 2;
|
|
|
|
const PRIORITY_HIGH = 3;
|
|
|
|
const PRIORITY_TOP = 4;
|
2018-10-01 12:14:23 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/** @var string */
|
2018-10-01 12:14:23 +00:00
|
|
|
private $uri = '';
|
|
|
|
|
2018-11-21 19:22:46 +00:00
|
|
|
/** @var int */
|
|
|
|
private $type = 0;
|
|
|
|
|
2018-11-27 16:58:08 +00:00
|
|
|
/** @var int */
|
|
|
|
private $priority = 0;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 [
|
2018-11-27 16:58:08 +00:00
|
|
|
'uri' => $this->getUri(),
|
|
|
|
'type' => $this->getType(),
|
|
|
|
'priority' => $this->getPriority()
|
2018-09-28 11:41:24 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|