diff options
-rw-r--r-- | Zotlabs/Data/Registration.php | 66 | ||||
-rw-r--r-- | Zotlabs/Entity/Registration.php | 17 | ||||
-rw-r--r-- | include/account.php | 2 | ||||
-rw-r--r-- | tests/unit/Data/RegistrationTest.php (renamed from tests/unit/Entity/RegistrationTest.php) | 4 |
4 files changed, 69 insertions, 20 deletions
diff --git a/Zotlabs/Data/Registration.php b/Zotlabs/Data/Registration.php new file mode 100644 index 000000000..f7b1015b9 --- /dev/null +++ b/Zotlabs/Data/Registration.php @@ -0,0 +1,66 @@ +<?php +/* + * SPDX-FileCopyrightText: 2024 Hubzilla Community + * SPDX-FileContributor: Harald Eilertsen + * + * SPDX-License-Identifier: MIT + */ + +namespace Zotlabs\Data; + +use Zotlabs\Entity; + +/** + * A data model for registrations. + */ +class Registration { + + // We offload the actual content of the registration + // to the Registration Entity class. + private Entity\Registration $entity; + + /** + * Find a registration by it's hash. + * + * @param string $hash The hash of the registration to find. + * + * @return Registration|null An initialized Registration object + * if the registration was found, null otherwise. + */ + public static function find_by_hash(string $hash): ?self + { + $reg = q("SELECT * FROM register WHERE reg_hash = '%s' LIMIT 1", + dbesc($hash) + ); + + if ($reg) { + return new self($reg[0]); + } + + return null; + } + + /** + * Creates a new Registration object from an array or properties. + * + * @param array $properties An array of property name, value pairs. + * The property name is the key in the array, the value is the value. + */ + private function __construct(array $properties) { + $this->entity = new Entity\Registration($properties); + } + + /** + * Delegate method calls to the Registration entity. + */ + public function __call(string $name, array $args): mixed { + return call_user_func([$this->entity, $name], $args); + } + + /** + * Delegate property references to the Registration entity. + */ + public function __get(string $name): mixed { + return $this->entity->{$name}; + } +} diff --git a/Zotlabs/Entity/Registration.php b/Zotlabs/Entity/Registration.php index d210f4d39..e2af8e22b 100644 --- a/Zotlabs/Entity/Registration.php +++ b/Zotlabs/Entity/Registration.php @@ -53,23 +53,6 @@ class Registration } /** - * Find a registration by it's hash. - * - * @param string $hash The hash of the registration to find. - * - * @return Registration|null An initialized Registration object - * if the registration was found, null otherwise. - */ - public static function find_by_hash(string $hash): ?self - { - $reg = q("SELECT * FROM register WHERE reg_hash = '%s' LIMIT 1", - dbesc($hash) - ); - - return $reg ? new self($reg[0], true) : null; - } - - /** * Set the value of a property. * * @param string $name The name of the property, optionally prefixed by `reg_`. diff --git a/include/account.php b/include/account.php index 19ee42457..fce8dc514 100644 --- a/include/account.php +++ b/include/account.php @@ -4,9 +4,9 @@ * @brief Somme account related functions. */ -use Zotlabs\Entity\Registration; use Zotlabs\Lib\Config; use Zotlabs\Lib\Crypto; +use Zotlabs\Data\Registration; require_once('include/config.php'); require_once('include/network.php'); diff --git a/tests/unit/Entity/RegistrationTest.php b/tests/unit/Data/RegistrationTest.php index b705bd516..4799b95f3 100644 --- a/tests/unit/Entity/RegistrationTest.php +++ b/tests/unit/Data/RegistrationTest.php @@ -6,9 +6,9 @@ * SPDX-License-Identifier: MIT */ -namespace Zotlabs\Tests\Unit\Entity; +namespace Zotlabs\Tests\Unit\Data; -use Zotlabs\Entity\Registration; +use Zotlabs\Data\Registration; use Zotlabs\Tests\Unit\UnitTestCase; class RegistrationTest extends UnitTestCase { |