EoD
This commit is contained in:
parent
fac22f76c6
commit
7043d56329
58
tasks/oop/hyperlink/hyperlink.php
Normal file
58
tasks/oop/hyperlink/hyperlink.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
class Hyperlink
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Private members
|
||||||
|
*/
|
||||||
|
|
||||||
|
private string $uri;
|
||||||
|
private string $title;
|
||||||
|
private ?string $colour;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function __construct(string $uri, string $title, string $colour = null)
|
||||||
|
{
|
||||||
|
$this->uri = $uri;
|
||||||
|
$this->title = $title;
|
||||||
|
$this->setColour($colour);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Getters and Setters
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function setColour(string $colour = null)
|
||||||
|
{
|
||||||
|
if ($colour === null) {
|
||||||
|
$this->colour = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match("/^#([0-9A-Fa-f]{3,4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/", $colour)) {
|
||||||
|
trigger_error("Colour invalid", E_USER_WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->colour = $colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColour()
|
||||||
|
{
|
||||||
|
return $this->colour ?? "No colour specified";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Meta
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
$style = $this->colour ? "style=\"color:$this->colour;\"" : "";
|
||||||
|
return <<<END
|
||||||
|
<a href="$this->uri" $style>$this->title</a>
|
||||||
|
END;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
tasks/oop/hyperlink/index.php
Normal file
33
tasks/oop/hyperlink/index.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<?php include_once "../../../base/meta.php" ?>
|
||||||
|
|
||||||
|
<title>Person Test</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
include_once "../../../base/settings.php";
|
||||||
|
include_once "../../../base/headers.php";
|
||||||
|
Headers::html();
|
||||||
|
|
||||||
|
//Testdatei für die Klasse Hyperlink
|
||||||
|
include_once "./hyperlink.php";
|
||||||
|
|
||||||
|
//Objektinstanzen
|
||||||
|
$link1 = new Hyperlink("https://www.google.de", "Google");
|
||||||
|
echo "<p>$link1</p>";
|
||||||
|
$link1->setColour("#CC0000");
|
||||||
|
echo "<p>$link1</p>\n";
|
||||||
|
|
||||||
|
$link2 = new Hyperlink("https://portal.zedat.fu-berlin.de", "Zedat-Portal");
|
||||||
|
echo "<p>$link2</p>\n";
|
||||||
|
|
||||||
|
$link3 = new Hyperlink("https://userpage.fu-berlin.de/db-admin", "phpMyAdmin", "#009900");
|
||||||
|
echo "<p>Die Farbe des Links $link3 ist " . $link3->getColour() . "</p>\n";
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
23
tasks/oop/person/index.php
Normal file
23
tasks/oop/person/index.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<?php include_once "../../../base/meta.php" ?>
|
||||||
|
|
||||||
|
<title>Person Test</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
include_once "../../../base/settings.php";
|
||||||
|
include_once "../../../base/headers.php";
|
||||||
|
Headers::html();
|
||||||
|
|
||||||
|
include_once "./person.php";
|
||||||
|
$person = new Person("John Doe", 170, new DateTime("01-01-1970"));
|
||||||
|
|
||||||
|
echo $person;
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
33
tasks/oop/person/person.php
Normal file
33
tasks/oop/person/person.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
class Person
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Private members
|
||||||
|
*/
|
||||||
|
|
||||||
|
private string $name;
|
||||||
|
private float $weight;
|
||||||
|
private DateTime $birthdate;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function __construct(string $name, float $weight, DateTime $birthdate)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
$this->weight = $weight;
|
||||||
|
$this->birthdate = $birthdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Meta
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
$formatter = new IntlDateFormatter('en_UK', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
|
||||||
|
$formatter->setPattern('E dd.MM.yyyy');
|
||||||
|
return "$this->name, currently {$this->weight}lbs, was born on {$formatter->format($this->birthdate)}";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user