abschluss
This commit is contained in:
72
app/Entity/Post.php
Normal file
72
app/Entity/Post.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace Blog\Entity;
|
||||
|
||||
/**
|
||||
* Repräsentiert einen Blogpost mit ID, Titel, Inhalt, Autor und Zeitstempel.
|
||||
*/
|
||||
class Post {
|
||||
/**
|
||||
* Erstellt eine neue Post-Instanz.
|
||||
*
|
||||
* @param int $id Die eindeutige ID des Blogposts.
|
||||
* @param string $title Der Titel des Blogposts.
|
||||
* @param string $content Der Inhalt des Blogposts.
|
||||
* @param string $author Der Name des Autors.
|
||||
* @param int $stamp Der Zeitstempel der Veröffentlichung.
|
||||
*/
|
||||
public function __construct(
|
||||
private int $id,
|
||||
private string $title,
|
||||
private string $content,
|
||||
private string $author,
|
||||
private int $stamp
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Gibt die ID des Blogposts zurück.
|
||||
*
|
||||
* @return int Die eindeutige ID.
|
||||
*/
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Titel des Blogposts zurück.
|
||||
*
|
||||
* @return string Der Titel des Blogposts.
|
||||
*/
|
||||
public function getTitle(): string {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Inhalt des Blogposts zurück. Optional kann eine maximale Länge angegeben werden.
|
||||
*
|
||||
* @param int|null $maxlength Die maximale Zeichenanzahl, falls angegeben.
|
||||
* @return string Der gekürzte oder vollständige Inhalt des Blogposts.
|
||||
*/
|
||||
public function getContent($maxlength = null): string {
|
||||
return $maxlength
|
||||
? mb_strimwidth($this->content, 0, $maxlength, "...")
|
||||
: $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Namen des Autors zurück.
|
||||
*
|
||||
* @return string Der Name des Autors.
|
||||
*/
|
||||
public function getAuthor(): string {
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt das Veröffentlichungsdatum und die Uhrzeit formatiert zurück.
|
||||
*
|
||||
* @return string Das Datum und die Uhrzeit im Format `d.m.Y H:i:s`.
|
||||
*/
|
||||
public function getDateTime(): string {
|
||||
return date('d.m.Y H:i:s', $this->stamp);
|
||||
}
|
||||
}
|
47
app/Entity/User.php
Normal file
47
app/Entity/User.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Blog\Entity;
|
||||
|
||||
/**
|
||||
* Repräsentiert einen Benutzer mit ID, Benutzernamen und Passwort.
|
||||
*/
|
||||
class User {
|
||||
/**
|
||||
* Erstellt eine neue User-Instanz.
|
||||
*
|
||||
* @param int $id Die eindeutige ID des Benutzers.
|
||||
* @param string $username Der Benutzername.
|
||||
* @param string $password Das Passwort des Benutzers.
|
||||
*/
|
||||
public function __construct(
|
||||
private int $id,
|
||||
private string $username,
|
||||
private string $password
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Gibt die ID des Benutzers zurück.
|
||||
*
|
||||
* @return int Die eindeutige ID des Benutzers.
|
||||
*/
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Benutzernamen zurück.
|
||||
*
|
||||
* @return string Der Benutzername.
|
||||
*/
|
||||
public function getUsername(): string {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt das Passwort des Benutzers zurück.
|
||||
*
|
||||
* @return string Das Passwort.
|
||||
*/
|
||||
public function getPassword(): string {
|
||||
return $this->password;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
namespace Blog\Entity;
|
||||
|
||||
class Post {
|
||||
public function __construct(
|
||||
private int $id,
|
||||
private string $title,
|
||||
private string $content,
|
||||
private string $author,
|
||||
private int $stamp
|
||||
) {}
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getContent($maxlength = null) {
|
||||
return $maxlength ? mb_strimwidth($this->content, 0, $maxlength, "...") : $this->content;
|
||||
}
|
||||
|
||||
public function getAuthor() {
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
public function getDateTime() {
|
||||
return $this->stamp;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
namespace Blog\Entity;
|
||||
|
||||
class User {
|
||||
private $id;
|
||||
private $username;
|
||||
private $password;
|
||||
|
||||
public function __construct($id, $username, $password) {
|
||||
$this->id = $id;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUsername() {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getPassword() {
|
||||
return $this->password;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user