Initialize php application #2
Merged
maxime.batista
merged 3 commits from bootstrap
into master
2 years ago
@ -1 +1,4 @@
|
||||
.idea
|
||||
vendor
|
||||
composer.lock
|
||||
*.phar
|
||||
|
@ -1,2 +1,3 @@
|
||||
# IQBall - Web Application
|
||||
This repository hosts the IQBall application for web
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"altorouter/altorouter": "1.2.0"
|
||||
}
|
||||
}
|
@ -1,16 +1,22 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello world</h1>
|
||||
<?php
|
||||
echo "<h2>hello world</h2>"
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
global $router;
|
||||
require "./vendor/autoload.php";
|
||||
|
||||
use App\Controller\HelloPageController;
|
||||
|
||||
// routes initialization
|
||||
$router = new AltoRouter();
|
||||
// hello page controllers
|
||||
$helloController = new HelloPageController();
|
||||
$router->map("GET", "/", fn() => $helloController->display());
|
||||
|
||||
$match = $router->match();
|
||||
|
||||
if ($match == null) {
|
||||
// TODO redirect to a 404 not found page instead (issue #1)
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
call_user_func($match['target']);
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
class HelloPageController {
|
||||
public function display() {
|
||||
require_once "src/View/hello.html";
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
|||||||
<?php
|
|||||||
|
|||||||
namespace App\Data;
|
|||||||
|
|||||||
use http\Exception\InvalidArgumentException;
|
|||||||
|
|||||||
const PHONE_NUMBER_REGEXP = "\\+[0-9]+";
|
|||||||
|
|||||||
/**
|
|||||||
* Base class of a user account.
|
|||||||
* Contains the private information that we don't want
|
|||||||
* to share to other users, or non-needed public information
|
|||||||
*/
|
|||||||
class Account {
|
|||||||
/**
|
|||||||
* @var string $email account's mail address
|
|||||||
*/
|
|||||||
private string $email;
|
|||||||
/**
|
|||||||
* @var string account's phone number.
|
|||||||
* its format is specified by the {@link PHONE_NUMBER_REGEXP} constant
|
|||||||
*
|
|||||||
*/
|
|||||||
private string $phoneNumber;
|
|||||||
|
|||||||
/**
|
|||||||
* @var AccountUser account's public and shared information
|
|||||||
*/
|
|||||||
private AccountUser $user;
|
|||||||
|
|||||||
/**
|
|||||||
* @var array account's teams
|
|||||||
*/
|
|||||||
private array $teams;
|
|||||||
|
|||||||
|
|||||||
/**
|
|||||||
* @var int account's unique identifier
|
|||||||
*/
|
|||||||
private int $id;
|
|||||||
|
|||||||
/**
|
|||||||
* @param string $email
|
|||||||
* @param string $phoneNumber
|
|||||||
* @param AccountUser $user
|
|||||||
*/
|
|||||||
public function __construct(string $email, string $phoneNumber, AccountUser $user, array $teams, int $id) {
|
|||||||
$this->email = $email;
|
|||||||
$this->phoneNumber = $phoneNumber;
|
|||||||
$this->user = $user;
|
|||||||
$this->teams = $teams;
|
|||||||
$this->id = $id;
|
|||||||
}
|
|||||||
|
|||||||
/**
|
|||||||
* @return string
|
|||||||
*/
|
|||||||
public function getEmail(): string {
|
|||||||
return $this->email;
|
|||||||
}
|
|||||||
|
|||||||
/**
|
|||||||
* @param string $email
|
|||||||
*/
|
|||||||
public function setEmail(string $email): void {
|
|||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|||||||
throw new InvalidArgumentException("Invalid mail address");
|
|||||||
}
|
|||||||
$this->email = $email;
|
|||||||
}
|
|||||||
|
|||||||
/**
|
|||||||
* @return string
|
|||||||
*/
|
|||||||
public function getPhoneNumber(): string {
|
|||||||
return $this->phoneNumber;
|
|||||||
}
|
|||||||
|
|||||||
/**
|
|||||||
* @param string $phoneNumber
|
|||||||
*/
|
|||||||
public function setPhoneNumber(string $phoneNumber): void {
|
|||||||
if (!filter_var($phoneNumber, FILTER_VALIDATE_REGEXP, PHONE_NUMBER_REGEXP)) {
|
|||||||
throw new InvalidArgumentException("Invalid phone number");
|
|||||||
}
|
|||||||
$this->phoneNumber = $phoneNumber;
|
|||||||
}
|
|||||||
|
|||||||
public function getId(): int {
|
|||||||
return $this->id;
|
|||||||
}
|
|||||||
|
|||||||
public function getTeams(): array {
|
|||||||
return $this->teams;
|
|||||||
}
|
|||||||
|
|||||||
public function getUser(): AccountUser {
|
|||||||
return $this->user;
|
|||||||
}
|
|||||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use http\Url;
|
||||
|
||||
/**
|
||||
* This class implements the User and
|
||||
*/
|
||||
class AccountUser implements User {
|
||||
private string $name;
|
||||
private Url $profilePicture;
|
||||
private int $age;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param Url $profilePicture
|
||||
* @param int $age
|
||||
*/
|
||||
public function __construct(string $name, Url $profilePicture, int $age) {
|
||||
$this->name = $name;
|
||||
$this->profilePicture = $profilePicture;
|
||||
$this->age = $age;
|
||||
}
|
||||
|
||||
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getProfilePicture(): Url {
|
||||
return $this->profilePicture;
|
||||
}
|
||||
|
||||
public function getAge(): int {
|
||||
return $this->age;
|
||||
}
|
||||
|
||||
public function setName(string $name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function setProfilePicture(Url $profilePicture) {
|
||||
$this->profilePicture = $profilePicture;
|
||||
}
|
||||
|
||||
public function setAge(int $age) {
|
||||
$this->age = $age;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use http\Exception\InvalidArgumentException;
|
||||
|
||||
class Color {
|
||||
/**
|
||||
* @var int 6 bytes unsigned int that represents an RGB color
|
||||
*/
|
||||
private int $value;
|
||||
|
||||
/**
|
||||
* @param int $value 6 bytes unsigned int that represents an RGB color
|
||||
* @throws \InvalidArgumentException if the value is negative or greater than 0xFFFFFF
|
||||
*/
|
||||
public function __constructor(int $value) {
|
||||
if ($value < 0 || $value > 0xFFFFFF) {
|
||||
throw new InvalidArgumentException("int color value is invalid, must be positive and lower than 0xFFFFFF");
|
||||
}
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getValue(): int {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
/**
|
||||
* information about a team member
|
||||
*/
|
||||
class Member {
|
||||
/**
|
||||
* @var int The member's user id
|
||||
*/
|
||||
private int $userId;
|
||||
|
||||
/**
|
||||
* @var MemberRole the member's role
|
||||
*/
|
||||
private MemberRole $role;
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @param MemberRole $role
|
||||
*/
|
||||
public function __construct(int $userId, MemberRole $role) {
|
||||
$this->userId = $userId;
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getUserId(): int {
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MemberRole
|
||||
*/
|
||||
public function getRole(): MemberRole {
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
|
||||
use http\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Enumeration class workaround
|
||||
* As there is no enumerations in php 7.4, this class
|
||||
* encapsulates an integer value and use it as an enumeration discriminant
|
||||
*/
|
||||
final class MemberRole {
|
||||
private const ROLE_PLAYER = 0;
|
||||
private const ROLE_COACH = 1;
|
||||
private const MIN = self::ROLE_PLAYER;
|
||||
private const MAX = self::ROLE_COACH;
|
||||
|
||||
private int $value;
|
||||
|
||||
private function __construct(int $val) {
|
||||
if (!$this->isValid($val)) {
|
||||
throw new InvalidArgumentException("Valeur du rôle invalide");
|
||||
}
|
||||
$this->value = $val;
|
||||
}
|
||||
|
||||
private function isValid(int $val): bool {
|
||||
return ($val <= self::MAX and $val >= self::MIN);
|
||||
}
|
||||
|
||||
public function isPlayer(): bool {
|
||||
return ($this->value == self::ROLE_PLAYER);
|
||||
}
|
||||
|
||||
public function isCoach(): bool {
|
||||
return ($this->value == self::ROLE_COACH);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use http\Url;
|
||||
|
||||
class Team {
|
||||
private string $name;
|
||||
private Url $picture;
|
||||
private Color $mainColor;
|
||||
private Color $secondColor;
|
||||
|
||||
/**
|
||||
* @var array maps users with their role
|
||||
*/
|
||||
private array $members;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param Url $picture
|
||||
* @param Color $mainColor
|
||||
* @param Color $secondColor
|
||||
* @param array $members
|
||||
*/
|
||||
public function __construct(string $name, Url $picture, Color $mainColor, Color $secondColor, array $members) {
|
||||
$this->name = $name;
|
||||
$this->picture = $picture;
|
||||
$this->mainColor = $mainColor;
|
||||
$this->secondColor = $secondColor;
|
||||
$this->members = $members;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Url
|
||||
*/
|
||||
public function getPicture(): Url {
|
||||
return $this->picture;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Color
|
||||
*/
|
||||
public function getMainColor(): Color {
|
||||
return $this->mainColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Color
|
||||
*/
|
||||
public function getSecondColor(): Color {
|
||||
return $this->secondColor;
|
||||
}
|
||||
|
||||
public function listMembers(): array {
|
||||
return array_map(fn ($id, $role) => new Member($id, $role), $this->members);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use http\Url;
|
||||
|
||||
|
||||
/**
|
||||
* Public information about a user
|
||||
*/
|
||||
interface User {
|
||||
/**
|
||||
* @return string the user's name
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* @return Url The user's profile picture image URL
|
||||
*/
|
||||
|
||||
public function getProfilePicture(): Url;
|
||||
|
||||
/**
|
||||
* @return int The user's age
|
||||
*/
|
||||
public function getAge(): int;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Hello</h1>
|
||||
<h3>World</h3>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue
Aussi présent dans AccountUser
Yes, it's true