--- /dev/null
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @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 <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica;
+
+/**
+ * These data transfer object classes are meant for API representations. As such, their members should be protected.
+ * Then the JsonSerializable interface ensures the protected members will be included in a JSON encode situation.
+ *
+ * Constructors are supposed to take as arguments the Friendica dependencies/model/collection/data it needs to
+ * populate the class members.
+ */
+abstract class BaseDataTransferObject implements \JsonSerializable
+{
+ /**
+ * Returns the current entity as an json array
+ *
+ * @return array
+ */
+ public function jsonSerialize(): array
+ {
+ return $this->toArray();
+ }
+
+ /**
+ * Returns the current entity as an array
+ *
+ * @return array
+ */
+ public function toArray(): array
+ {
+ return get_object_vars($this);
+ }
+}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (C) 2020, Friendica
- *
- * @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 <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica;
-
-/**
- * The API entity classes are meant as data transfer objects. As such, their member should be protected.
- * Then the JsonSerializable interface ensures the protected members will be included in a JSON encode situation.
- *
- * Constructors are supposed to take as arguments the Friendica dependencies/model/collection/data it needs to
- * populate the class members.
- */
-abstract class BaseEntity implements \JsonSerializable
-{
- /**
- * Returns the current entity as an json array
- *
- * @return array
- */
- public function jsonSerialize()
- {
- return $this->toArray();
- }
-
- /**
- * Returns the current entity as an array
- *
- * @return array
- */
- public function toArray()
- {
- return get_object_vars($this);
- }
-}
*
* @property int id
*/
-abstract class BaseModel extends BaseEntity
+abstract class BaseModel extends BaseDataTransferObject
{
/** @var Database */
protected $dba;
$this->originalData = $data;
}
- public function getOriginalData()
+ public function getOriginalData(): array
{
return $this->originalData;
}
* @param array $data
* @return BaseModel
*/
- public static function createFromPrototype(BaseModel $prototype, array $data)
+ public static function createFromPrototype(BaseModel $prototype, array $data): BaseModel
{
$model = clone $prototype;
$model->data = $data;
* @param $name
* @return bool
*/
- public function __isset($name)
+ public function __isset($name): bool
{
return in_array($name, array_merge(array_keys($this->data), array_keys(get_object_vars($this))));
}
}
/**
+ * * Magic setter. This allows to set model fields with the following syntax:
+ * - $model->field = $value (outside of class)
+ * - $this->field = $value (inside of class)
+ *
* @param string $name
- * @param mixed $value
+ * @param mixed $value
*/
- public function __set($name, $value)
+ public function __set(string $name, $value)
{
$this->data[$name] = $value;
}
- public function toArray()
+ public function toArray(): array
{
return $this->data;
}
namespace Friendica\Object\Api\Friendica;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Model\Notify;
*
* @see https://github.com/friendica/friendica/blob/develop/doc/API-Entities.md#notification
*/
-class Notification extends BaseEntity
+class Notification extends BaseDataTransferObject
{
/** @var integer */
protected $id;
namespace Friendica\Object\Api\Mastodon;
use Friendica\App\BaseURL;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
use Friendica\Collection\Api\Mastodon\Fields;
use Friendica\Content\Text\BBCode;
use Friendica\Database\DBA;
*
* @see https://docs.joinmastodon.org/entities/account
*/
-class Account extends BaseEntity
+class Account extends BaseDataTransferObject
{
/** @var string */
protected $id;
*
* @return array
*/
- public function toArray()
+ public function toArray(): array
{
$account = parent::toArray();
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Activity
*
* @see https://docs.joinmastodon.org/entities/activity
*/
-class Activity extends BaseEntity
+class Activity extends BaseDataTransferObject
{
/** @var string (UNIX Timestamp) */
protected $week;
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Application
*
* @see https://docs.joinmastodon.org/entities/application
*/
-class Application extends BaseEntity
+class Application extends BaseDataTransferObject
{
/** @var string */
protected $name;
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Attachment
*
* @see https://docs.joinmastodon.org/entities/attachment
*/
-class Attachment extends BaseEntity
+class Attachment extends BaseDataTransferObject
{
/** @var string */
protected $id;
*
* @return array
*/
- public function toArray()
+ public function toArray(): array
{
$attachment = parent::toArray();
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Card
*
* @see https://docs.joinmastodon.org/entities/card
*/
-class Card extends BaseEntity
+class Card extends BaseDataTransferObject
{
/** @var string */
protected $url;
*
* @return array
*/
- public function toArray()
+ public function toArray(): array
{
if (empty($this->url)) {
- return null;
+ return [];
}
return parent::toArray();
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Emoji
*
* @see https://docs.joinmastodon.org/entities/emoji/
*/
-class Emoji extends BaseEntity
+class Emoji extends BaseDataTransferObject
{
//Required attributes
/** @var string */
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Error
*
* @see https://docs.joinmastodon.org/entities/error
*/
-class Error extends BaseEntity
+class Error extends BaseDataTransferObject
{
/** @var string */
protected $error;
*
* @return array
*/
- public function toArray()
+ public function toArray(): array
{
$error = parent::toArray();
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Field
*
* @see https://docs.joinmastodon.org/entities/field/
*/
-class Field extends BaseEntity
+class Field extends BaseDataTransferObject
{
/** @var string */
protected $name;
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
*
* @see https://docs.joinmastodon.org/api/entities/#instance
*/
-class Instance extends BaseEntity
+class Instance extends BaseDataTransferObject
{
/** @var string (URL) */
protected $uri;
namespace Friendica\Object\Api\Mastodon;
use Friendica\App\BaseURL;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Mention
*
* @see https://docs.joinmastodon.org/entities/mention
*/
-class Mention extends BaseEntity
+class Mention extends BaseDataTransferObject
{
/** @var string */
protected $id;
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
use Friendica\Model\Contact;
use Friendica\Util\Network;
*
* @see https://docs.joinmastodon.org/api/entities/#relationship
*/
-class Relationship extends BaseEntity
+class Relationship extends BaseDataTransferObject
{
/** @var int */
protected $id;
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\DI;
*
* @see https://docs.joinmastodon.org/api/entities/#stats
*/
-class Stats extends BaseEntity
+class Stats extends BaseDataTransferObject
{
/** @var int */
protected $user_count = 0;
namespace Friendica\Object\Api\Mastodon;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
use Friendica\Content\Text\BBCode;
use Friendica\Object\Api\Mastodon\Status\Counts;
use Friendica\Object\Api\Mastodon\Status\UserAttributes;
*
* @see https://docs.joinmastodon.org/entities/status
*/
-class Status extends BaseEntity
+class Status extends BaseDataTransferObject
{
/** @var string */
protected $id;
*
* @return array
*/
- public function toArray()
+ public function toArray(): array
{
$status = parent::toArray();
namespace Friendica\Object\Api\Mastodon;
use Friendica\App\BaseURL;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
/**
* Class Tag
*
* @see https://docs.joinmastodon.org/entities/tag
*/
-class Tag extends BaseEntity
+class Tag extends BaseDataTransferObject
{
/** @var string */
protected $name;
namespace Friendica\Object\Api\Twitter;
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Text\BBCode;
/**
* @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
*/
-class User extends BaseEntity
+class User extends BaseDataTransferObject
{
/** @var int */
protected $id;