2021-01-18 23:32:28 -05:00
|
|
|
<?php
|
2024-08-24 15:27:00 +02:00
|
|
|
|
|
|
|
// Copyright (C) 2010-2024, the Friendica project
|
|
|
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2021-01-18 23:32:28 -05:00
|
|
|
|
|
|
|
namespace Friendica;
|
|
|
|
|
2024-12-03 21:44:35 +00:00
|
|
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
2021-01-18 23:32:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Entity classes directly inheriting from this abstract class are meant to represent a single business entity.
|
|
|
|
* Their properties may or may not correspond with the database fields of the table we use to represent it.
|
|
|
|
* Each model method must correspond to a business action being performed on this entity.
|
|
|
|
* Only these methods will be allowed to alter the model data.
|
|
|
|
*
|
|
|
|
* To persist such a model, the associated Repository must be instantiated and the "save" method must be called
|
|
|
|
* and passed the entity as a parameter.
|
|
|
|
*
|
|
|
|
* Ideally, the constructor should only be called in the associated Factory which will instantiate entities depending
|
|
|
|
* on the provided data.
|
|
|
|
*
|
|
|
|
* Since these objects aren't meant to be using any dependency, including logging, unit tests can and must be
|
|
|
|
* written for each and all of their methods
|
|
|
|
*/
|
|
|
|
abstract class BaseEntity extends BaseDataTransferObject
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @return mixed
|
2024-12-03 21:44:35 +00:00
|
|
|
* @throws InternalServerErrorException
|
2021-01-18 23:32:28 -05:00
|
|
|
*/
|
|
|
|
public function __get(string $name)
|
|
|
|
{
|
|
|
|
if (!property_exists($this, $name)) {
|
2024-12-03 21:44:35 +00:00
|
|
|
throw new InternalServerErrorException('Unknown property ' . $name . ' in Entity ' . static::class);
|
2021-01-18 23:32:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->$name;
|
|
|
|
}
|
2021-10-17 23:10:10 +02:00
|
|
|
|
|
|
|
/**
|
2022-06-16 16:35:39 +02:00
|
|
|
* @param mixed $name
|
2021-10-17 23:10:10 +02:00
|
|
|
* @return bool
|
2024-12-03 21:44:35 +00:00
|
|
|
* @throws InternalServerErrorException
|
2021-10-17 23:10:10 +02:00
|
|
|
*/
|
2022-06-16 16:35:39 +02:00
|
|
|
public function __isset($name): bool
|
2021-10-17 23:10:10 +02:00
|
|
|
{
|
|
|
|
if (!property_exists($this, $name)) {
|
2024-12-03 21:44:35 +00:00
|
|
|
throw new InternalServerErrorException('Unknown property ' . $name . ' of type ' . gettype($name) . ' in Entity ' . static::class);
|
2021-10-17 23:10:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return !empty($this->$name);
|
|
|
|
}
|
2021-01-18 23:32:28 -05:00
|
|
|
}
|