fix: define class properties for php 8.2

This commit is contained in:
grandeljay 2023-08-30 12:51:23 +02:00
parent df5c4ad16a
commit 3355bd78b9
4 changed files with 247 additions and 31 deletions

View file

@ -48,7 +48,8 @@ if (file_exists($configPath)) {
*/ */
session_start( session_start(
array( array(
'name' => 'wishthis', 'name' => 'wishthis',
'read_and_close' => true,
) )
); );

View file

@ -12,9 +12,6 @@ namespace wishthis;
class User class User
{ {
/**
* Static
*/
public static function getFromID(int $user_id): self public static function getFromID(int $user_id): self
{ {
global $database; global $database;
@ -36,7 +33,7 @@ class User
return $user; return $user;
} }
throw new Exception('Unable to find user with ID ' . $user_id . '. Does it exist?'); throw new \Exception('Unable to find user with ID ' . $user_id . '. Does it exist?');
} }
public static function generatePassword(string $plainPassword): string public static function generatePassword(string $plainPassword): string
@ -45,24 +42,137 @@ class User
} }
/** /**
* Private * The users unique ID.
*
* @var int
*/
private int $id;
/**
* The users unique email address. They are not verified and may be made
* up.
*
* @var string
*/
private string $email;
/**
* The users hashed password.
*
* @var string
*/
private string $password;
/**
* The users password reset token.
*
* @var string
*/
private string $password_reset_token;
/**
* A unix timestamp indicating until when the users password reset token is
* valid.
*
* @var int
*/
private int $password_reset_valid_until;
/**
* A unix timestamp of when the user has logged in last.
*
* @var int
*/
private int $last_login;
/**
* The users power. Administrator have 100, users 1 and unregistered guests
* 0.
*
* @var int
*/
private int $power = 0;
/**
* A unix timestamp of the users birthdate.
*
* @var int
*/
private int $birthdate;
/**
* More accurately, this is the users locale (e. g. `en_GB`).
*
* @var string
*/ */
private string $language; private string $language;
/**
* The users currency (e. g. `EUR`).
*
* @var string
*/
private string $currency; private string $currency;
/**
* The users first name.
*
* @var string
*/
private string $name_first;
/**
* The users last name.
*
* @var string
*/
private string $name_last;
/**
* The users nick name.
*
* @var string
*/
private string $name_nick;
/**
* The users preferred release channel. Usually `stable` or
* `release-candidate` but can also be unset if not defined.
*
* @var string
*/
private string $channel;
/**
* Whether the user consented to seeing advertisements.
*
* @var bool
*/
private bool $advertisements = false;
/** /**
* Non-Static * Non-Static
*/ */
public int $power = 0;
public ?\Gettext\Translations $translations = null; public ?\Gettext\Translations $translations = null;
public bool $advertisements = false;
public function __construct(array $fields = array()) public function __construct(array $fields = array())
{ {
if (!empty($fields)) { if (!empty($fields)) {
foreach ($fields as $key => $value) { $this->id = $fields['id'];
$this->$key = $value; $this->email = $fields['email'];
} $this->password = $fields['password'];
$this->password_reset_token = $fields['password_reset_token'];
$this->password_reset_valid_until = $fields['password_reset_valid_until'];
$this->last_login = $fields['last_login'];
$this->power = $fields['power'];
$this->birthdate = $fields['birthdate'];
$this->language = $fields['language'];
$this->currency = $fields['currency'];
$this->name_first = $fields['name_first'];
$this->name_last = $fields['name_last'];
$this->name_nick = $fields['name_nick'];
$this->channel = $fields['channel'];
$this->advertisements = $fields['advertisements'];
} }
/** Set Language */ /** Set Language */

View file

@ -50,16 +50,78 @@ class Wish
*/ */
private Cache\Embed $cache; private Cache\Embed $cache;
/** General */ /**
public int $id; * The unique wish id.
public int $wishlist; *
public ?string $title; * @var int
public ?string $description; */
public ?string $image; private int $id;
public ?string $url;
public ?int $priority; /**
public bool $is_purchasable; * The wishlist id for this wish.
public ?string $status; *
* TODO: rename this to wishlist_id (the database column too).
*
* @var int
*/
private int $wishlist;
/**
* The wish title.
*
* @var string|null
*/
private string $title;
/**
* The wish description.
*
* @var string|null
*/
private string $description;
/**
* The wish image url.
*
* @var string|null
*/
private string $image;
/**
* The wish (product) url.
*
* @var string|null
*/
private string $url;
/**
* The wish priority
*
* @var int|null
*/
private ?int $priority;
/**
* The wish status.
*
* @var string|null
*/
private ?string $status;
/**
* Whether this wish is purchasable.
*
* @var bool
*/
private bool $is_purchasable;
/**
* A unix timestamp of when this wish was last edited.
*
* @var int
*/
private int $edited;
public string $style = 'grid'; public string $style = 'grid';
/** Product */ /** Product */
@ -96,9 +158,16 @@ class Wish
if ($columns) { if ($columns) {
$this->exists = true; $this->exists = true;
foreach ($columns as $key => $value) { $this->id = $columns['id'];
$this->$key = $value; $this->wishlist = $columns['wishlist'];
} $this->title = $columns['title'];
$this->description = $columns['description'];
$this->image = $columns['image'];
$this->url = $columns['url'];
$this->priority = $columns['priority'];
$this->status = $columns['status'];
$this->is_purchasable = $columns['is_purchasable'];
$this->edited = $columns['edited'];
$this->info = new \stdClass(); $this->info = new \stdClass();

View file

@ -10,6 +10,44 @@ namespace wishthis;
class Wishlist class Wishlist
{ {
/**
* The unique wishlist id.
*
* @var int
*/
private int $id;
/**
* The user id this wishlist belongs to.
*
* TODO: rename this to user_id (the database column too).
*
* @var int
*/
private int $user;
/**
* The wishlist name.
*
* @var string
*/
private string $name;
/**
* The unique wishlist hash.
*
* @var string
*/
private string $hash;
/**
* A unix timestamp of when the last notification was sent to the wishlist
* owner.
*
* @var int
*/
private int $notification_send;
public array $wishes = array(); public array $wishes = array();
public bool $exists = false; public bool $exists = false;
@ -43,13 +81,11 @@ class Wishlist
if ($columns) { if ($columns) {
$this->exists = true; $this->exists = true;
foreach ($columns as $key => $value) { $this->id = $columns['id'];
if (is_string($value)) { $this->user = $columns['user'];
$this->$key = html_entity_decode($value); $this->name = html_entity_decode($columns['name']);
} else { $this->hash = $columns['hash'];
$this->$key = $value; $this->notification_send = $columns['notification_send'];
}
}
} else { } else {
return; return;
} }