merge issue_030 on merged

master
Antoine PEREDERII 1 year ago
parent 29e611487e
commit 484a87554d

2
.gitignore vendored

@ -1,6 +1,4 @@
.idea .idea
*.ben
*.txt
node_modules node_modules
dist dist
.vscode .vscode

@ -9,19 +9,29 @@
"Repository\\": "src/data/model/repository", "Repository\\": "src/data/model/repository",
"Manager\\": "src/data/model/manager", "Manager\\": "src/data/model/manager",
"Network\\": "src/data/core/network", "Network\\": "src/data/core/network",
"Console\\": "src/console",
"Stub\\": [ "Stub\\": [
"src/data/stub", "src/data/stub",
"src/data/stub/service", "src/data/stub/service",
"src/data/stub/repository" "src/data/stub/repository"
], ],
"Shared\\": "src/shared", "Console\\": "src/console",
"Shared\\Exception\\": "src/shared/exception" "App\\Router\\": "src/app/router",
"App\\Controller\\": "src/app/controller",
"App\\Router\\Response\\" : "src/app/router/response",
"App\\Router\\Middleware\\" : "src/app/router/middleware",
"App\\Router\\Request\\" : "src/app/router/request",
"Shared\\": "src/shared/",
"Shared\\Exception\\": "src/shared/exception",
"Shared\\Attributes\\": "src/shared/attributes",
"App\\Views\\Directives\\" : "src/app/views/directives",
"Data\\Core\\": "src/data/core/"
} }
}, },
"require": { "require": {
"twig/twig": "^3.0", "twig/twig": "^3.0",
"altorouter/altorouter": "1.1.0",
"vlucas/phpdotenv": "^5.5", "vlucas/phpdotenv": "^5.5",
"psr/container": "^2.0",
"adriangibbons/php-fit-file-analysis": "^3.2.0" "adriangibbons/php-fit-file-analysis": "^3.2.0"
}, },
"require-dev": { "require-dev": {
@ -29,6 +39,7 @@
}, },
"scripts": { "scripts": {
"dev": "php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL", "dev": "php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL",
"dev:console": "export APP_ENV=console && php public/index.php" "dev:console": "export APP_ENV=console && php public/index.php",
"dev:html" : "export APP_ENV=html && php -S localhost:8080 -t public -d display_errors=1 -d error_reporting=E_ALL"
} }
} }

112
Sources/composer.lock generated

@ -4,45 +4,62 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "6dee42c458d187b6e08086b3015d19e1", "content-hash": "c8acec96dcc23612616eedff9886528e",
"packages": [ "packages": [
{ {
"name": "adriangibbons/php-fit-file-analysis", "name": "altorouter/altorouter",
"version": "v3.2.4", "version": "v1.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/adriangibbons/php-fit-file-analysis.git", "url": "https://github.com/dannyvankooten/AltoRouter.git",
"reference": "8efd36b1b963f01c42dc5329626519c040dec664" "reference": "09d9d946c546bae6d22a7654cdb3b825ffda54b4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/adriangibbons/php-fit-file-analysis/zipball/8efd36b1b963f01c42dc5329626519c040dec664", "url": "https://api.github.com/repos/dannyvankooten/AltoRouter/zipball/09d9d946c546bae6d22a7654cdb3b825ffda54b4",
"reference": "8efd36b1b963f01c42dc5329626519c040dec664", "reference": "09d9d946c546bae6d22a7654cdb3b825ffda54b4",
"shasum": "" "shasum": ""
}, },
"require-dev": { "require": {
"phpunit/phpunit": "4.8.*", "php": ">=5.3.0"
"satooshi/php-coveralls": "^2.0",
"squizlabs/php_codesniffer": "2.*"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
"psr-4": { "classmap": [
"adriangibbons\\": "src/" "AltoRouter.php"
} ]
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
"description": "A PHP class for analysing FIT files created by Garmin GPS devices", "license": [
"homepage": "https://github.com/adriangibbons/php-fit-file-analysis", "MIT"
],
"authors": [
{
"name": "Danny van Kooten",
"email": "dannyvankooten@gmail.com",
"homepage": "http://dannyvankooten.com/"
},
{
"name": "Koen Punt",
"homepage": "https://github.com/koenpunt"
},
{
"name": "niahoo",
"homepage": "https://github.com/niahoo"
}
],
"description": "A lightning fast router for PHP",
"homepage": "https://github.com/dannyvankooten/AltoRouter",
"keywords": [ "keywords": [
"Fit", "lightweight",
"garmin" "router",
"routing"
], ],
"support": { "support": {
"issues": "https://github.com/adriangibbons/php-fit-file-analysis/issues", "issues": "https://github.com/dannyvankooten/AltoRouter/issues",
"source": "https://github.com/adriangibbons/php-fit-file-analysis/tree/master" "source": "https://github.com/dannyvankooten/AltoRouter/tree/master"
}, },
"time": "2019-11-20T06:58:56+00:00" "time": "2014-04-16T09:44:40+00:00"
}, },
{ {
"name": "graham-campbell/result-type", "name": "graham-campbell/result-type",
@ -181,6 +198,59 @@
], ],
"time": "2023-11-12T21:59:55+00:00" "time": "2023-11-12T21:59:55+00:00"
}, },
{
"name": "psr/container",
"version": "2.0.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963",
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/2.0.2"
},
"time": "2021-11-05T16:47:00+00:00"
},
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.28.0", "version": "v1.28.0",

@ -1,17 +0,0 @@
# Activer la réécriture d'URL
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
<Files *>
Order Allow,Deny
Deny from all
</Files>
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>

@ -1,4 +1,4 @@
FROM php:8.2-apache FROM php:8.2-fpm
# Installation de dépendances nécessaires pour Composer # Installation de dépendances nécessaires pour Composer
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
git \ git \
@ -10,10 +10,8 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local
RUN docker-php-ext-install pdo pdo_mysql RUN docker-php-ext-install pdo pdo_mysql
COPY . /var/www/html COPY . /var/www/
WORKDIR /var/www/html WORKDIR /var/www/
RUN chown -R www-data:www-data /var/www/html
RUN composer install
EXPOSE 80
RUN composer install

@ -4,17 +4,22 @@ use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__); $dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load(); $dotenv->load();
use Dotenv\Dotenv;
use Shared\Log;
$dotenv = Dotenv::createUnsafeImmutable(__DIR__,'.env');
$dotenv->safeLoad();
// apenrently getEnv is not a good thing cause
// const DB_HOST = $_ENV['DB_HOST'] ?? 'localhost'; // const DB_HOST = $_ENV['DB_HOST'] ?? 'localhost';
// const DB_DATABASE = $_ENV['DB_DATABASE'] ?? 'heartTrack'; // const DB_DATABASE = $_ENV['DB_DATABASE'] ?? 'heartTrack';
// const DB_USER = $_ENV['DB_USER'] ?? 'toto'; // const DB_USER = $_ENV['DB_USER'] ?? 'toto';
// const DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? 'achanger'; // const DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? 'achanger';
// const APP_ENV = $_ENV['APP_ENV'] ?? 'development'; define("APP_ENV", 'development');
const DB_HOST ='localhost';
const DB_DATABASE = 'heartTrack';
const DB_USER = 'toto';
const DB_PASSWORD = 'achanger';
const DB_HOST = 'localhost';
const DB_DATABASE = 'heartTrack';
const DB_USER = 'toto';
const DB_PASSWORD = 'achanger';
const APP_ENV = 'console'; const APP_ENV = 'console';
const DSN = "mysql:host=" . DB_HOST . ";dbname=" . DB_DATABASE; const DSN = "mysql:host=" . DB_HOST . ";dbname=" . DB_DATABASE;

@ -1,21 +1,28 @@
server { server {
listen 80; listen 80;
server_name localhost; index index.php;
root /var/www/public;
error_page 404 /index.php;
root /var/www/html; location ~ ^/(images|javascript|js|css|flash|media|static)/ {
index index.php index.html; root /var/www/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
} }
location ~ \.php$ { location ~ \.php$ {
include fastcgi_params; fastcgi_pass web:9000; # service name defined in docker-compose.yml file like web
fastcgi_pass php:9000; # service name defined in docker-compose.yml file fastcgi_param REQUEST_METHOD $request_method;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
} }
location ~ /\.ht { location / {
deny all; try_files $uri $uri/ /index.php?$query_string;
} }
} }

@ -1,15 +1,42 @@
version: '3' version: '3'
services: services:
web:
nginx:
image: nginx:latest image: nginx:latest
ports: ports:
- "8080:80" - "3000:80"
volumes: volumes:
- ./public:/var/www/html - ./config/nginx.conf:/etc/nginx/conf.d/default.conf
- ./config/nginx.conf:/etc/nginx/conf.d - .:/var/www
links: depends_on:
- php - mysql
php: - web
image: php:7.4-fpm
web:
build:
context: .
dockerfile: ./config/Dockerfile
ports:
- 9000:9000
volumes: volumes:
- ./src:/var/www/html - .:/var/www
depends_on:
- mysql
environment:
DB_HOST: mysql
DB_PORT: port
DB_DATABASE: test
DB_USER: user
DB_PASSWORD: pass
APP_ENV: development
mysql:
image: mysql:latest
container_name: my-mysql-container
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: test
MYSQL_USER: user
MYSQL_PASSWORD: pass
ports:
- "3307:3306"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,9 +1,36 @@
<?php <?php
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config/config.php'; require_once __DIR__ . '/../config/config.php';
if (APP_ENV === 'console') {
require_once __DIR__ . '/../src/console/Console.php'; use App\AppCreator;
} use App\Router\Middleware\LoggingMiddleware;
elseif (APP_ENV === 'development') { use App\Router\Request\RequestFactory;
require_once __DIR__ . DIRECTORY_SEPARATOR . '../src/app/index.test.php'; use Shared\ArgumentControllerResolver;
use Shared\IArgumentResolver;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Shared\Log;
$appFactory = new AppCreator();
$appFactory->registerService(IArgumentResolver::class, ArgumentControllerResolver::class);
$appFactory->registerService(\Twig\Loader\LoaderInterface::class, function() {
return new FilesystemLoader(__DIR__ . '/../src/app/views/Templates');
});
$appFactory->registerService(\Twig\Environment::class,\Twig\Environment::class);
// Connexion à la base de données
// $databaseContext = DatabaseContext::getInstance();
$appFactory->AddControllers();
$app = $appFactory->create();
if (!is_null($app)){
// Ajout des Middleware
/*$app->use(new LoggingMiddleware());*/
$app->mapControllers();
$app->run(RequestFactory::createFromGlobals());
} }

@ -0,0 +1,15 @@
document.getElementById('saveButton').addEventListener('click', function() {
var preferences = {
notifications: document.getElementById('notif').checked,
theme: document.getElementById('theme').value
};
fetch('/index.php/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(preferences),
})
.catch((error) => console.error('Error:', error));
});

@ -0,0 +1,158 @@
<?php
namespace App;
use App\Controller\BaseController;
use App\Controller\FrontController;
use App\Router\Request\HttpRequest;
use App\Router\Middleware\IHttpMiddleware;
use App\Router\Request\IRequest;
use App\Router\Route;
use App\Views\Directives\Navigate;
use Shared\Attributes\Route as RouteAttribute;
use App\Router\Router;
use App\Router\Session;
use Shared\Log;
class App
{
private string $appName;
private int $version;
private ?IHttpMiddleware $middlewarePipeline = null;
private Container $container;
private Router $router;
private array $controllers = [];
private FrontController $frontController;
public function __construct(string $appName, int $version, \App\Container $diContainer)
{
$this->appName = $appName;
$this->version = $version;
$this->container = $diContainer;
$this->router = new Router("");
$this->frontController = new FrontController($this->router,$this->container);
}
public function use(IHttpMiddleware $middleware)
{
if ($this->middlewarePipeline === null) {
$this->middlewarePipeline = $middleware;
} else {
// Chain the new middleware to the end of the existing pipeline
$currentMiddleware = $this->middlewarePipeline;
while ($currentMiddleware->getNext() !== null) {
$currentMiddleware = $currentMiddleware->getNext();
}
$currentMiddleware->setNext($middleware);
}
}
public function getAppName(): string
{
return $this->appName;
}
/* public function twigConfigure(array $extensionClassNames = []): void
{
if (!$this->container->has(\Twig\Environment::class)) {
throw new \LogicException('You cannot use the "twigConfigure" method if the Twig Bundle is not available. Try running "composer require twig/twig".');
}
$twigEnvironment = $this->container->get(\Twig\Environment::class);
if (empty($extensionClassNames)) {
$twigEnvironment->addExtension(new Navigate($this->router));
} else {
foreach ($extensionClassNames as $extensionClassName) {
if (class_exists($extensionClassName)) {
$extensionInstance = new $extensionClassName();
if ($extensionInstance instanceof \Twig\Extension\ExtensionInterface) {
$twigEnvironment->addExtension($extensionInstance);
} else {
throw new \InvalidArgumentException("Class '$extensionClassName' does not implement Twig\Extension\ExtensionInterface.");
}
} else {
throw new \InvalidArgumentException("Class '$extensionClassName' does not exist.");
}
}
}
}*/
public function getVersion(): int
{
return $this->version;
}
public function run(IRequest $request)
{
if ($this->middlewarePipeline == null) {
return $this->frontController->dispatch($request);
}
// Exécutez le middleware en utilisant le pipeline
return $this->middlewarePipeline->handle($request, function($request) {
// Logique de gestion principale de la requête ici
$this->frontController->dispatch($request);
});
}
/**
* @throws \ReflectionException
*/
public function mapControllers(): void
{
$classes = $this->container->getAllRegisteredClassNames();
foreach ($classes as $class) {
if ($this->isController($class)) {
$this->mapControllerRoutes($class);
}
}
}
/**
* @throws \ReflectionException
*/
function mapControllerRoutes(string $controllerClass): void
{
$reflectionClass = new \ReflectionClass($controllerClass);
$attributes = $reflectionClass->getAttributes(RouteAttribute::class);
$prefix = '';
if (!empty($attributes)) {
$prefix = $attributes[0]->newInstance()->getPath();
}
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
foreach ($method->getAttributes(RouteAttribute::class) as $attribute) {
/** @var RouteAttribute $route */
$route = $attribute->newInstance();
$this->router->addControllerRoute(
implode('|', $route->getMethods()),
$prefix . $route->getPath(),
$controllerClass,
$method->getName(),
$route->getName()
);
}
}
}
function isController(string $class): bool
{
$reflectionClass = new \ReflectionClass($class);
return $reflectionClass->isSubclassOf(BaseController::class);
}
}

@ -0,0 +1,91 @@
<?php
namespace App;
use App\Controller\BaseController;
use Shared\Log;
use Twig\Loader\FilesystemLoader;
class AppCreator
{
private Container $container;
private array $services = [];
public function __construct()
{
$this->container = new Container;
}
public function registerService(string $serviceId, callable|string $service): self
{
$this->container->set($serviceId, $service);
$this->services[] = $serviceId;
return $this;
}
/**
* Create an instance or perform actions based on the current application environment.
*
* @return App|null An instance of the App class in the 'development' environment, or null in other environments.
*/
public function create(): ?App
{
// Check the application environment
switch (APP_ENV) {
case 'console':
// Load the Console.php file in case of the 'console' environment
require_once __DIR__ . '/../console/Console.php';
break;
case 'development':
// Create a new instance of the App class in the 'development' environment
return new App("HeartTrack", 1, $this->container);
break;
case 'html':
// Load the index.test.php file in case of the 'html' environment
require_once __DIR__ . '/index.test.php';
break;
default:
// Handle other environment cases here, if necessary
break;
}
return null;
}
function AddControllers($namespacePrefix = 'App\Controller', $pathToControllers = __DIR__ . '/controller'): self
{
$controllerFiles = glob($pathToControllers . '/*.php');
foreach ($controllerFiles as $file) {
// Get class name from file name
$class = basename($file, '.php');
$fullClassName = $namespacePrefix . '\\' . $class;
if (!class_exists($fullClassName)) {
continue;
}
// Use reflection to check if class extends BaseController
$reflectionClass = new \ReflectionClass($fullClassName);
if ($reflectionClass->isSubclassOf(BaseController::class)) {
// Register in DI container
$this->container->set($fullClassName, function () use ($fullClassName) {
$controllerInstance = new $fullClassName();
$controllerInstance->setContainer($this->container);
return $controllerInstance;
});
}
}
return $this;
}
public function getServiceRegistered(): array
{
return $this->services;
}
}

@ -0,0 +1,109 @@
<?php
namespace App;
use Psr\Container\ContainerInterface;
use Shared\Log;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
class Container implements ContainerInterface
{
private array $entries = [];
public function get(string $id)
{
if ($this->has($id)) {
$entry = $this->entries[$id];
if (is_callable($entry)) {
return $entry($this);
}
$id = $entry;
}
return $this->resolve($id);
}
public function has(string $id): bool
{
return isset($this->entries[$id]);
}
public function set(string $id, callable|string $concrete): void
{
$this->entries[$id] = $concrete;
}
public function resolve(string $id)
{
// 1. Inspect the class that we are trying to get from the container
try {
$reflectionClass = new \ReflectionClass($id);
} catch (\ReflectionException $e) {
throw new \Exception($e->getMessage(), $e->getCode(), $e);
}
if (!$reflectionClass->isInstantiable()) {
throw new \Exception('Class "' . $id . '" is not instantiable');
}
// 2. Inspect the constructor of the class
$constructor = $reflectionClass->getConstructor();
if (!$constructor) {
return new $id;
}
// 3. Inspect the constructor parameters (dependencies)
$parameters = $constructor->getParameters();
if (!$parameters) {
return new $id;
}
// 4. If the constructor parameter is a class then try to resolve that class using the container
$dependencies = array_map(
function (\ReflectionParameter $param) use ($id) {
$name = $param->getName();
$type = $param->getType();
// Check for a default value
if ($param->isDefaultValueAvailable()) {
return $param->getDefaultValue();
}
if (!$type) {
throw new \Exception(
'Failed to resolve class "' . $id . '" because param "' . $name . '" is missing a type hint'
);
}
if ($type instanceof \ReflectionUnionType) {
throw new \Exception(
'Failed to resolve class "' . $id . '" because of union type for param "' . $name . '"'
);
}
if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) {
return $this->get($type->getName());
}
throw new \Exception(
'Failed to resolve class "' . $id . '" because invalid param "' . $name . '"'
);
},
$parameters
);
return $reflectionClass->newInstanceArgs($dependencies);
}
public function getAllRegisteredClassNames(): array
{
return array_keys($this->entries);
}
}

@ -0,0 +1,177 @@
<?php
// namespace App\Controller;
// use App\Container;
// use App\Router\Request\IRequest;
// use App\Router\Response\Response;
// use Shared\Attributes\Route;
// use Twig\Environment;
// use Data\Core\Preferences;
// use Shared\Log;
// class AthleteController extends BaseController
// {
// #[Route(path: '/search-user', name: 'search-user', methods: ['GET'])]
// public function searchUser(string $username, IRequest $req): Response
// {
// $taberror = [];
// $utiliArray = [
// [
// 'nom' => 'John',
// 'prenom' => 'Doe',
// 'img' => 'john_doe',
// 'username' => 'johndoe',
// ],
// [
// 'nom' => 'Alice',
// 'prenom' => 'Smith',
// 'img' => 'alice_smith',
// 'username' => 'alicesmith',
// ],
// ];
// // if(!Validation::val_string($name)){
// try {
// //code...
// // $model->userMgr->getUser($name);
// return $this->render('./page/addfriend.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => $utiliArray,
// 'infoUser' => [],
// 'exos' => [],
// 'member' => [],
// 'responce' => "Notification d'ajout envoyée à $username"
// ]);
// } catch (\Throwable $th) {
// //throw $th;
// // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]);
// }
// // }
// }
// #[Route(path: '/analyses', name: 'analyses', methods: ['GET'])]
// public function analyses(): Response
// {
// return $this->render('./page/analyze.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// #[Route(path: '/exercice', name: 'exercice', methods: ['GET'])] // 8
// public function exercice(): Response
// {
// return $this->render('./page/exercice.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// #[Route(path: '/add-friend', name: 'add-friend', methods: ['POST'])]
// public function addFriend(string $username, IRequest $req): Response
// {
// $taberror = [];
// $utiliArray = [
// [
// 'nom' => 'John',
// 'prenom' => 'Doe',
// 'img' => 'john_doe',
// 'username' => 'johndoe',
// ],
// [
// 'nom' => 'Alice',
// 'prenom' => 'Smith',
// 'img' => 'alice_smith',
// 'username' => 'alicesmith',
// ],
// ];
// // if(!Validation::val_string($name)){
// try {
// //code...
// // $model->userMgr->addFriend($name);
// return $this->render('./page/addfriend.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => $utiliArray,
// 'infoUser' => [],
// 'exos' => [],
// 'member' => [],
// 'responce' => "Notification d'ajout envoyée à $username"
// ]);
// } catch (\Throwable $th) {
// //throw $th;
// // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]);
// }
// // }
// }
// #[Route(path: '/delete-friend', name: 'delete-friend', methods: ['POST'])]
// #[Route(path: '/friend', name: 'friend', methods: ['GET'])]
// public function friend(): Response
// {
// $utiliArray = [
// [
// 'nom' => 'John',
// 'prenom' => 'Doe',
// 'img' => 'john_doe',
// 'username' => 'johndoe',
// ],
// [
// 'nom' => 'Alice',
// 'prenom' => 'Smith',
// 'img' => 'alice_smith',
// 'username' => 'alicesmith',
// ],
// ];
// // $this->Auth->getUser->role->getFriends
// return $this->render('./page/addfriend.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => $utiliArray,
// 'infoUser' => [],
// 'exos' => [],
// 'member' => [],
// ]);
// }
// }

@ -0,0 +1,82 @@
<?php
// namespace App\Controller;
// use App\Container;
// use App\Router\Request\IRequest;
// use App\Router\Response\Response;
// use Shared\Attributes\Route;
// use Twig\Environment;
// use Data\Core\Preferences;
// use Shared\Log;
// class AuthController extends BaseController
// {
// #[Route('/login', name: 'login')]
// public function login(?string $username, ?string $password ,IRequest $request): Response {
// // if user is already logged in, don't display the login page again
// if ($user) {
// return $this->redirectToRoute('blog_index');
// }
// // this statement solves an edge-case: if you change the locale in the login
// // page, after a successful login you are redirected to a page in the previous
// // locale. This code regenerates the referrer URL whenever the login page is
// // browsed, to ensure that its locale is always the current one.
// $this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index'));
// return $this->render('security/login.html.twig', [
// // last username entered by the user (if any)
// 'last_username' => $helper->getLastUsername(),
// // last authentication error (if any)
// 'error' => $helper->getLastAuthenticationError(),
// ]);
// }
// #[Route('/login', name: 'login')]
// public function login(?string $username, ?string $password ,IRequest $request): Response {
// // if user is already logged in, don't display the login page again
// if ($user) {
// return $this->redirectToRoute('blog_index');
// }
// // this statement solves an edge-case: if you change the locale in the login
// // page, after a successful login you are redirected to a page in the previous
// // locale. This code regenerates the referrer URL whenever the login page is
// // browsed, to ensure that its locale is always the current one.
// $this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index'));
// return $this->render('security/login.html.twig', [
// // last username entered by the user (if any)
// 'last_username' => $helper->getLastUsername(),
// // last authentication error (if any)
// 'error' => $helper->getLastAuthenticationError(),
// ]);
// }
// function inscription() {
// $model = new ModelVisitor();
// $log=Validation::clean_string($_POST['pseudo']);
// $mdp=Validation::clean_string($_POST['password']);
// if($model->createAUser($log,$mdp)){
// if(ModelUser::login($log, $mdp)){
// UserControler::displayView();
// }
// }
// }
// function login() {
// $model = new ModelVisitor();
// if(!isset($_POST['pseudo']) || !isset($_POST['password'])) throw new Exception(" some wrong with credentials !!!!!");
// $log=Validation::clean_string($_POST['pseudo']);
// $mdp=Validation::clean_string($_POST['password']);
// if(ModelUser::login($log, $mdp)){
// UserControler::displayView();
// }
// }
// }
?>

@ -0,0 +1,72 @@
<?php
namespace App\Controller;
use App\Container;
use App\Router\Response\RedirectResponse;
use App\Router\Response\Response;
use Psr\Container\ContainerInterface;
abstract class BaseController
{
protected ContainerInterface $container;
public function setContainer(ContainerInterface $container)
{
$this->container = $container;
}
protected function renderView(string $view, array $parameters = []): string
{
if (!$this->container->has(\Twig\Environment::class)) {
throw new \LogicException('You cannot use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
}
return $this->container->get(\Twig\Environment::class)->render($view, $parameters);
}
/**
* Renders a view.
*
* If an invalid form is found in the list of parameters, a 422 status code is returned.
* Forms found in parameters are auto-cast to form views.
*/
protected function render(string $view, array $parameters = [], Response $response = null): Response
{
$content = $this->renderView($view, $parameters);
$response ??= new Response();
/* if (200 === $response->getStatusCode()) {
foreach ($parameters as $v) {
if ($v instanceof FormInterface && $v->isSubmitted() && !$v->isValid()) {
$response->setStatusCode(422);
break;
}
}
}*/
$response->setContent($content);
return $response;
}
protected function redirect(string $url, int $status = 302): RedirectResponse
{
return new RedirectResponse($url, $status);
}
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
{
return $this->redirect($this->generateUrl($route, $parameters), $status);
}
/*
* TODO : Should hanle ierror if the route is not existing
* */
protected function generateUrl(string $route, array $parameters = []): string
{
return $this->container->get(\App\Router\Router::class)->generate($route, $parameters);
}
}

@ -0,0 +1,128 @@
<?php
// namespace App\Controller;
// use App\Container;
// use App\Router\Request\IRequest;
// use App\Router\Response\Response;
// use App\Router\Response\IResponse;
// use Shared\Attributes\Route;
// use Twig\Environment;
// use Data\Core\Preferences;
// use Shared\Log;
// #[Route(path: '/coach', name: 'coach')]
// class CoachController extends BaseController
// {
// private ICoachManager $coachManager;
// private $security;
// public function __construct(DataManager $dataManager, Security $security)
// {
// $this->coachManager = $dataManager->coachMgr;
// $this->security = $security;
// }
// #[Route(path: '/', name: 'home', methods: ['GET'])]
// public function index(): Response
// {
// return $this->render('./page/home.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// #[Route('/global-stats', name: 'coach_global_stats', methods: ['GET'])]
// public function globalStats(): Response
// {
// // Add logic to fetch and process global stats
// return $this->render('coach/global_stats.html.twig');
// }
// #[Route(path: '/exercice', name: 'exercice', methods: ['GET'])] // 8
// public function exercice(): Response
// {
// return $this->render('./page/exercice.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// #[Route(path: '/coaching', name: 'coaching', methods: ['GET'])]
// public function coaching(): Response
// {
// return $this->render('./page/coaching.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// #[Route('/list-athletes', name: 'coach_list_athletes')]
// public function listAthletes(): Response
// {
// $coach = $this->security->getUser();
// $athletes = $this->coachManager->getAthletesForCoach($coach);
// return $this->render('coach/list_athletes.html.twig', [
// 'athletes' => $athletes,
// ]);
// }
// #[Route('/athlete-analysis/{athleteId}', name: 'coach_athlete_analysis', methods: ['GET'])]
// public function athleteAnalysis($athleteId): Response
// {
// // Fetch and process data specific to the athlete
// return $this->render('coach/athlete_analysis.html.twig', [
// 'athleteId' => $athleteId,
// ]);
// }
// #[Route('/add-athlete/{athleteId}', name: 'coach_add_athlete', methods: ['POST'])]
// public function addAthlete(IRequest $request, $athleteId): IResponse
// {
// // Implement logic to add athlete
// // ...
// return $this->redirectToRoute('coach_list_athletes');
// }
// // #[Route('/remove-athlete', name: 'coach_remove_athlete', methods: ['POST'])]
// // public function removeAthlete(int $athleteId, IRequest $request): IResponse
// // {
// // return $this->redirectToRoute("/athletes");
// // }
// }

@ -0,0 +1,718 @@
<?php
namespace App\Controller;
use App\Container;
use App\Router\Request\IRequest;
use App\Router\Response\Response;
use Shared\Attributes\Route;
use Twig\Environment;
use Data\Core\Preferences;
use Shared\Log;
// TODO : Remove this BaseClass
class Controller extends BaseController
{
private Environment $twig;
private Preferences $preference;
public function __construct()
{
session_start();
$this->preference = new Preferences();
}
#[Route(path: '/', name: 'home', methods: ['GET'])]
public function index(): Response
{
return $this->render('./page/index.html',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/analyses', name: 'analyses', methods: ['GET'])]
public function analyses(): Response
{
return $this->render('./page/analyze.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/activity', name: 'activity', methods: ['GET'])]
public function activity(): Response
{
return $this->render('./page/activity.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/exercice', name: 'exercice', methods: ['GET'])] // 8
public function exercice(): Response
{
return $this->render('./page/exercice.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/exercices', name: 'exercices', methods: ['POST'])] // 8
public function exercices(String $type, String $intensite, String $date, IRequest $req): Response
{
$exercicesArray = [
[
'date' => $date,
'type' => $type,
'intensite' => $intensite,
'status' => 'A venur',
]
];
return $this->render('./page/exercice.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => $exercicesArray,
'member' => []
]);
}
#[Route(path: '/search-user', name: 'search-user', methods: ['GET'])]
public function searchUser(string $username, IRequest $req): Response
{
$taberror = [];
// FILTER
$utiliArray = [
[
'nom' => 'John',
'prenom' => 'Doe',
'img' => 'john_doe',
'username' => 'johndoe',
],
[
'nom' => 'Alice',
'prenom' => 'Smith',
'img' => 'alice_smith',
'username' => 'alicesmith',
],
];
// if(!Validation::val_string($name)){
try {
//code...
// $model->userMgr->addFriend($name);
return $this->render('./page/addfriend.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => $utiliArray,
'infoUser' => [],
'exos' => [],
'member' => [],
'responce' => "Notification d'ajout envoyée à $username"
]);
} catch (\Throwable $th) {
//throw $th;
// return $this->render("addfriend.html.twig", ['tabError' => $taberror ]);
}
// }
}
#[Route(path: '/search-member', name: 'search-member', methods: ['GET'])]
public function searchMember(string $username, IRequest $req): Response
{
$taberror = [];
// FILTER
$utiliArray = [
[
'nom' => 'John',
'prenom' => 'Doe',
'img' => 'john_doe',
'username' => 'johndoe',
],
[
'nom' => 'Alice',
'prenom' => 'Smith',
'img' => 'alice_smith',
'username' => 'alicesmith',
],
];
// if(!Validation::val_string($name)){
try {
//code...
// $model->userMgr->addFriend($name);
return $this->render('./page/addmember.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => $utiliArray,
'infoUser' => [],
'exos' => [],
'member' => [],
'responce' => "Notification d'ajout envoyée à $username"
]);
} catch (\Throwable $th) {
//throw $th;
// return $this->render("addfriend.html.twig", ['tabError' => $taberror ]);
}
// }
}
#[Route(path: '/add-member', name: 'add-member', methods: ['POST'])]
public function addmember(string $username, IRequest $req): Response
{
$taberror = [];
$utiliArray = [
[
'nom' => 'John',
'prenom' => 'Doe',
'img' => 'john_doe',
'username' => 'johndoe',
],
[
'nom' => 'Alice',
'prenom' => 'Smith',
'img' => 'alice_smith',
'username' => 'alicesmith',
],
];
// if(!Validation::val_string($name)){
try {
//code...
// $model->userMgr->addFriend($name);
return $this->render('./page/addmember.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => $utiliArray,
'infoUser' => [],
'exos' => [],
'member' => [],
'responce' => "Notification d'ajout envoyée à $username"
]);
} catch (\Throwable $th) {
//throw $th;
// return $this->render("addfriend.html.twig", ['tabError' => $taberror ]);
}
// }
}
#[Route(path: '/member', name: 'member', methods: ['GET'])]
public function member(): Response
{
$utiliArray = [
[
'nom' => 'John',
'prenom' => 'Doe',
'img' => 'john_doe',
'username' => 'johndoe',
],
[
'nom' => 'Alice',
'prenom' => 'Smith',
'img' => 'alice_smith',
'username' => 'alicesmith',
],
];
return $this->render('./page/addmember.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => $utiliArray,
'infoUser' => [],
'exos' => [],
'member' => [],
]);
}
#[Route(path: '/add-friend', name: 'add-friend', methods: ['POST'])]
public function addFriend(string $username, IRequest $req): Response
{
$taberror = [];
$utiliArray = [
[
'nom' => 'John',
'prenom' => 'Doe',
'img' => 'john_doe',
'username' => 'johndoe',
],
[
'nom' => 'Alice',
'prenom' => 'Smith',
'img' => 'alice_smith',
'username' => 'alicesmith',
],
];
// if(!Validation::val_string($name)){
try {
//code...
// $model->userMgr->addFriend($name);
return $this->render('./page/addfriend.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => $utiliArray,
'infoUser' => [],
'exos' => [],
'member' => [],
'responce' => "Notification d'ajout envoyée à $username"
]);
} catch (\Throwable $th) {
//throw $th;
// return $this->render("addfriend.html.twig", ['tabError' => $taberror ]);
}
// }
}
#[Route(path: '/friend', name: 'friend', methods: ['GET'])]
public function friend(): Response
{
$utiliArray = [
[
'nom' => 'John',
'prenom' => 'Doe',
'img' => 'john_doe',
'username' => 'johndoe',
],
[
'nom' => 'Alice',
'prenom' => 'Smith',
'img' => 'alice_smith',
'username' => 'alicesmith',
],
];
return $this->render('./page/addfriend.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => $utiliArray,
'infoUser' => [],
'exos' => [],
'member' => [],
]);
}
#[Route(path: '/friendlist', name: 'friendlist', methods: ['POST'])]
public function friendlist(string $username, IRequest $req): Response
{
$utiliArray = [
[
'nom' => 'John',
'prenom' => 'Doe',
'img' => 'john_doe',
'username' => 'johndoe',
],
[
'nom' => 'Alice',
'prenom' => 'Smith',
'img' => 'alice_smith',
'username' => 'alicesmith',
],
];
/* TODO */
// -> Enlever ou bloquer un utilisateur en fonction de son username
return $this->render('./page/friend.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => $utiliArray,
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => [],
]);
}
#[Route(path: '/friendlist', name: 'friendlist2', methods: ['GET'])]
public function friendlist2(): Response
{
$utiliArray = [
[
'nom' => 'John',
'prenom' => 'Doe',
'img' => 'test',
'status' => 'johndoe',
'username' => 'jdoe',
],
[
'nom' => 'Alice',
'prenom' => 'Smith',
'img' => 'test2',
'status' => 'alicesmith',
'username' => 'asmith',
],
];
return $this->render('./page/friend.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => $utiliArray,
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => [],
]);
}
#[Route(path: '/coaching', name: 'coaching', methods: ['GET'])]
public function coaching(): Response
{
return $this->render('./page/coaching.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/mail', name: 'mail', methods: ['GET'])]
public function mail(): Response
{
return $this->render('./page/mail.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/import', name: 'import', methods: ['GET'])]
public function import(): Response
{
return $this->render('./page/import.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/settings', name: 'settings', methods: ['GET'])]
public function settings(IRequest $req): Response
{
return $this->render('./page/settings.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/profile', name: 'profile', methods: ['GET'])]
public function profile(): Response
{
return $this->render('./page/profile.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/preferences', name: 'preferences', methods: ['POST'])]
public function preferences(string $theme, IRequest $req): Response
{
/*TODO*/
// VALIDER LES DONNEES
$this->preference->majCookie($theme);
return $this->render('./page/settings.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/psettings', name: 'psettings', methods: ['POST'])]
public function psettings(string $nom,string $prenom,string $dateNaissance,string $mail,string $tel, IRequest $req): Response
{
return $this->render('./page/settings.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => $prenom,
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/mdp', name: 'mdp', methods: ['POST'])]
public function mdp(string $ancienMotDePasse,string $nouveauMotDePasse,string $confirmerMotDePasse, IRequest $req): Response
{
// CONFIRMER LES DONNESS !!!!! IMPORTANT
return $this->render('./page/settings.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/login', name: 'login', methods: ['POST'])]
public function login(string $username,string $mdp, IRequest $req): Response
{
// CONFIRMER LES DONNESS !!!!! IMPORTANT
return $this->render('./page/home.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/log', name: 'log', methods: ['GET'])]
public function login2(): Response
{
// CONFIRMER LES DONNESS !!!!! IMPORTANT
return $this->render('./page/login.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/register', name: 'register', methods: ['POST'])]
public function register(string $username,string $mdp,string $confirmMdp,string $nom,string $prenom,string $dateNaissance,string $sexe,string $taille,string $poids, IRequest $req): Response
{
// CONFIRMER LES DONNESS !!!!! IMPORTANT
return $this->render('./page/home.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/regist', name: 'regist', methods: ['GET'])]
public function register2(): Response
{
// CONFIRMER LES DONNESS !!!!! IMPORTANT
return $this->render('./page/register.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/pass', name: 'pass', methods: ['GET'])]
public function pass(): Response
{
// CONFIRMER LES DONNESS !!!!! IMPORTANT
return $this->render('./page/password.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
#[Route(path: '/password', name: 'password', methods: ['POST'])]
public function password(string $email, IRequest $req): Response
{
// CONFIRMER LES DONNESS !!!!! IMPORTANT
return $this->render('./page/login.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
}
}

@ -0,0 +1,74 @@
<?php
namespace App\Controller;
use App\Container;
use App\Router\Request\IRequest;
use App\Router\Response\Response;
use App\Router\Router;
use Shared\Exception\NotFoundHttpException;
use Shared\Exception\NotImplementedException;
use Shared\IArgumentResolver;
use Shared\Log;
class FrontController {
private Router $router;
private Container $container;
public function __construct(Router $router, Container $container) {
$this->router = $router;
$this->container = $container;
}
public function dispatch(IRequest $request) {
try {
$match = $this->router->match($request);
if (!is_null($match)) {
$method = $match['target'];
$controller = $this->getController($match['target']);
$callable = array($controller,$method[1]);
$request->addToBody($match['params']);
if (!is_callable($callable)){
throw new NotImplementedException('Controller target is not callable' .'Handle when route target is not a callable : not handle');
}
$argumentResolver = $this->container->get(IArgumentResolver::class);
$arguments = $argumentResolver->getArguments($request, $callable);
// check role
$response = call_user_func_array($callable, $arguments);
// should handle response properly like if it's a HTML, STING, JSON,....
$response->send();
} else {
$this->handleError(404, "Page not found");
}
} catch (NotFoundHttpException $e) {
$this->handleError(404, $e->getMessage());
}
}
private function getController($controllerSpec) {
if (is_array($controllerSpec)) {
$controllerName = $controllerSpec[0];
} else {
$controllerName = $controllerSpec;
}
return $this->container->get($controllerName);
}
// TODO : Don't work need Antoine help
private function handleError(int $statusCode, $message) : void {
if (!$this->container->has(\Twig\Environment::class)) {
throw new \LogicException('You cannot use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
}
$response = new Response($this->container->get(\Twig\Environment::class)->render('./error/error.html.twig',['title'=> $message , "code" => $statusCode, "name" => $message, "descr" => $message ]),$statusCode);
$response->send();
}
}
?>

@ -0,0 +1,36 @@
<?php
// namespace App\Controller;
// use App\Container;
// use App\Router\Request\IRequest;
// use App\Router\Response\Response;
// use Shared\Attributes\Route;
// use Twig\Environment;
// use Data\Core\Preferences;
// use Shared\Log;
// class HeartRateController extends BaseController
// {
// #[Route(path: '/import', name: 'import', methods: ['GET'])]
// public function import(): Response
// {
// return $this->render('./page/import.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// }

@ -0,0 +1,17 @@
<!-- #[Route(path: '/mail', name: 'mail', methods: ['GET'])]
public function mail(): Response
{
return $this->render('./page/mail.html.twig',[
'css' => $this->preference->getCookie(),
'pp' => "test2",
'user' => "Doe",
'role' => "Athlète",
'friendship' => [],
'analyzes' => [],
'mails' => [],
'users' => [],
'infoUser' => [],
'exos' => [],
'member' => []
]);
} -->

@ -0,0 +1,80 @@
<?php
// namespace App\Controller;
// use App\Container;
// use App\Router\Request\IRequest;
// use App\Router\Response\Response;
// use Shared\Attributes\Route;
// use Twig\Environment;
// use Data\Core\Preferences;
// use Shared\Log;
// class UserController extends BaseController
// {
// #[Route(path: '/', name: 'home', methods: ['GET'])]
// public function index(): Response
// {
// return $this->render('./page/home.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// #[Route(path: '/settings', name: 'settings', methods: ['GET'])]
// public function settings(IRequest $req): Response
// {
// return $this->render('./page/settings.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// #[Route(path: '/preferences', name: 'preferences', methods: ['POST'])]
// public function preferences(string $theme, IRequest $req): Response
// {
// /*TODO*/
// // VALIDER LES DONNEES
// $this->preference->majCookie($theme);
// return $this->render('./page/settings.html.twig',[
// 'css' => $this->preference->getCookie(),
// 'pp' => "test2",
// 'user' => "Doe",
// 'role' => "Athlète",
// 'friendship' => [],
// 'analyzes' => [],
// 'mails' => [],
// 'users' => [],
// 'infoUser' => [],
// 'exos' => [],
// 'member' => []
// ]);
// }
// }

@ -0,0 +1,94 @@
<?php
namespace App\Router;
/**
* Represents a single route in the application.
*/
class Route
{
/**
* The name of the route.
*
* @var string|null
*/
private ?string $name;
/**
* The path for the route.
*
* @var string
*/
private string $path;
/**
* The callable to be executed when the route is matched.
*
* @var callable
*/
private $callable;
/**
* Constructor for the Route.
*
* @param string $path The path for the route.
* @param callable $callable The callable to be executed for this route.
* @param array|null $params Optional parameters for the route.
* @param string|null $name Optional name for the route.
*/
public function __construct(string $path, callable $callable, array $params = null, string $name = null)
{
$this->path = $path;
$this->callable = $callable;
$this->name = $name;
}
/**
* Gets the name of the route.
*
* @return string|null The name of the route.
*/
public function getName(): ?string
{
return $this->name;
}
/**
* Sets the name of the route.
*
* @param string|null $name The name to set.
*/
public function setName(?string $name): void
{
$this->name = $name;
}
/**
* Gets the callable associated with the route.
*
* @return callable The callable for this route.
*/
public function getCallable()
{
return $this->callable;
}
/**
* Gets the path for the route.
*
* @return string The path for the route.
*/
public function getPath(): string
{
return $this->path;
}
/**
* Sets the callable for the route.
*
* @param callable $callable The callable to set for this route.
*/
public function setCallable(callable $callable)
{
$this->callable = $callable;
}
}

@ -0,0 +1,116 @@
<?php
namespace App\Router;
use App\Router\Request\IRequest;
/**
* Router class to manage a collection of routes in the application.
* It provides functionalities to add routes and check if a given URL matches any of the defined routes.
*/
class Router {
/**
* The base path for routing.
*
* @var string
*/
private string $path;
/**
* Collection of routes.
*
* @var \AltoRouter
*/
private \AltoRouter $routes;
/**
* Supported HTTP verbs.
*
* @var string[]
*/
public static $verbs = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'];
/**
* Constructor for Router.
*
* @param string $path The base path for the router.
*/
public function __construct(string $path = "/PHP/project/index.php") {
$this->path = $path;
$this->routes = new \AltoRouter();
}
/**
* Adds a new Route to the collection.
*
* @param string $method The HTTP method.
* @param Route $route The route object.
* @throws \InvalidArgumentException If method is not supported.
*/
public function add(string $method, Route $route) {
if (!in_array($method, self::$verbs)) {
throw new \InvalidArgumentException("Method not supported");
}
$this->routes->map($method, $route->getPath(), $route->getCallable(), $route->getName());
}
/**
* Adds a route for a controller action.
*
* @param string $method The HTTP method.
* @param string $path The path for the route.
* @param mixed $controller The controller object.
* @param string $action The action method in the controller.
* @param string $name (Optional) The name of the route.
* @throws \InvalidArgumentException If method is not supported.
*/
public function addControllerRoute(string $method, string $path, $controller, string $action, string $name = '') {
if (!in_array($method, self::$verbs)) {
throw new \InvalidArgumentException("Method not supported");
}
$this->routes->map($method, $path, [$controller, $action], $name);
}
// TODO: Implement the extractParams method.
// public function extractParams(string $path) {}
/**
* Adds a GET route.
*
* @param string $path The path for the route.
* @param callable $callable The callback function.
* @param string $name The name of the route.
*/
public function get(string $path, callable $callable, $name) {
$this->routes->map('GET', $path, $callable, $name);
}
// Similar methods for post, put, etc. can be added here.
/**
* Checks if the request can be processed.
*
* @param IRequest $request The request object.
* @return array|null The matched route or null if no match.
*/
public function match(IRequest $request): ?array {
return $this->routes->match($request->getRequestUri(), $request->getMethod()) ?: null;
}
/**
* Returns all routes.
*
* @return array The array of routes.
*/
public function getRoutes() {
return []; // TODO: Implement the actual logic to return routes.
}
public function generate (string $routeName, array $params = array()): string
{
return $this->routes->generate($routeName,$params);
}
}
?>

@ -0,0 +1,121 @@
<?php
/*
Use the static method getInstance to get the object.
*/
namespace App\Router;
class Session
{
const SESSION_STARTED = TRUE;
const SESSION_NOT_STARTED = FALSE;
// The state of the session
private $sessionState = self::SESSION_NOT_STARTED;
// THE only instance of the class
private static $instance;
private function __construct() {}
/**
* Returns THE instance of 'Session'.
* The session is automatically initialized if it wasn't.
*
* @return object
**/
public static function getInstance()
{
if ( !isset(self::$instance))
{
self::$instance = new self;
}
self::$instance->startSession();
return self::$instance;
}
/**
* (Re)starts the session.
*
* @return bool TRUE if the session has been initialized, else FALSE.
**/
private function startSession()
{
if ( $this->sessionState == self::SESSION_NOT_STARTED )
{
$this->sessionState = session_start();
}
return $this->sessionState;
}
/**
* Stores datas in the session.
* Example: $instance->foo = 'bar';
*
* @param name Name of the datas.
* @param value Your datas.
* @return void
**/
public function __set( $name , $value )
{
$_SESSION[$name] = $value;
}
/**
* Gets datas from the session.
* Example: echo $instance->foo;
*
* @param name Name of the datas to get.
* @return mixed Datas stored in session.
**/
public function __get( string $name )
{
if ( isset($_SESSION[$name]))
{
return $_SESSION[$name];
}
}
public function __isset( $name )
{
return isset($_SESSION[$name]);
}
public function __unset( $name )
{
unset( $_SESSION[$name] );
}
/**
* Destroys the current session.
*
* @return bool TRUE is session has been deleted, else FALSE.
**/
public function destroy()
{
if ( $this->sessionState == self::SESSION_STARTED )
{
$this->sessionState = !session_destroy();
unset( $_SESSION );
return !$this->sessionState;
}
return FALSE;
}
}

@ -0,0 +1,39 @@
<?php
namespace App\Router\Middleware;
use App\Router\Request\IRequest;
use Shared\Validation\Validator;
class RequestValidationMiddleware extends Middleware {
private $validator;
private $rules;
public function __construct(Validator $validator, array $rules) {
$this->validator = $validator;
$this->rules = $rules;
}
public function handle(IRequest $request, callable $next) {
$this->validateRequest($request);
return parent::handle($request, $next);
}
private function validateRequest(IRequest $request) {
foreach ($this->rules as $param => $ruleSet) {
foreach ($ruleSet as $rule) {
$this->validator->rule($param, $rule['callback'], $rule['message']);
}
}
$requestData = array_merge($request->getQueryParameters(), $request->getRequestParameters());
$this->validator->assert($requestData);
}
}
// $validationRules = [
// 'email' => [
// ['callback' => Validator::required(), 'message' => 'Email is required.'],
// ['callback' => Validator::email(), 'message' => 'Email must be a valid email address.']
// ],
// // Add more rules as needed
// ];

@ -0,0 +1,9 @@
<?php
namespace App\Router\Middleware;
use App\Router\Request\IRequest;
interface IHttpMiddleware {
public function handle(IRequest $request, callable $next);
}

@ -0,0 +1,12 @@
<?php
namespace App\Router\Middleware;
use App\Router\Request\IRequest;
class LoggingMiddleware extends Middleware {
public function handle(IRequest $request, callable $next) {
// Logique de journalisation
echo "LoggingMiddleware: Log request - Method: {$request->getMethod()}, URI: {$request->getRequestUri()}\n";
return parent::handle($request, $next);
}
}

@ -0,0 +1,20 @@
<?php
namespace App\Router\Middleware;
use App\Router\Request\IRequest;
abstract class Middleware implements IHttpMiddleware {
protected $next;
public function setNext(IHttpMiddleware $nextMiddleware) {
$this->next = $nextMiddleware;
}
public function handle(IRequest $request, callable $next) {
if ($this->next !== null) {
return $this->next->handle($request, $next);
}
return $next($request);
}
}

@ -0,0 +1,6 @@
<?php
namespace App\Router\Request;
interface ContentStrategy {
public function getContent(): array;
}

@ -0,0 +1,23 @@
<?php
namespace App\Router\Request;
// should maybe change this
class ContentStrategyFactory {
private static $strategyMap = [
'application/json' => JsonContentStrategy::class,
// Format...
];
public static function createContentStrategy(string $contentType, string $requestMethod): ContentStrategy {
foreach (self::$strategyMap as $type => $className) {
if ($contentType === $type || in_array($requestMethod, ['PUT', 'PATCH', 'DELETE'])) {
return new $className();
}
}
return new FormContentStrategy();
}
public static function registerStrategy(string $contentType, string $className): void {
self::$strategyMap[$contentType] = $className;
}
}

@ -0,0 +1,9 @@
<?php
namespace App\Router\Request;
class FormContentStrategy implements ContentStrategy {
public function getContent(): array {
return $_POST;
}
}

@ -0,0 +1,55 @@
<?php
namespace App\Router\Request;
class HttpRequest implements IRequest {
private $queryParameters;
private $requestParameters;
private $method;
private $requestUri;
private $headers;
private array $body;
public function __construct(
array $query,
array $server,
array $headers,
ContentStrategy $contentStrategy,
array $body
) {
$this->queryParameters = $query;
$this->requestUri = $server['REQUEST_URI'] ?? '';
$this->method = strtoupper($server['REQUEST_METHOD'] ?? 'GET');
$this->headers = $headers;
$this->requestParameters = $contentStrategy->getContent();
$this->body = $body;
}
public function getQueryParameters(): array {
return $this->queryParameters;
}
public function getRequestParameters(): array {
return $this->requestParameters;
}
public function getMethod(): string {
return $this->method;
}
public function getRequestUri(): string {
return $this->requestUri;
}
public function getHeaders(): array {
return $this->headers;
}
public function getBody(): array{
return $this->body;
}
public function addToBody(string|array $attributes){
$this->body[] = $attributes;
}
}

@ -0,0 +1,16 @@
<?php
namespace App\Router\Request;
interface IRequest
{
public function getRequestUri();
public function getBody();
public function addToBody(string|array $attributes);
public function getHeaders();
public function getMethod();
public function getQueryParameters(): array;
public function getRequestParameters(): array;
}

@ -0,0 +1,9 @@
<?php
namespace App\Router\Request;
class JsonContentStrategy implements ContentStrategy {
public function getContent(): array {
$rawContent = file_get_contents('php://input');
return json_decode($rawContent, true) ?? [];
}
}

@ -0,0 +1,27 @@
<?php
namespace App\Router\Request;
class RequestFactory {
public static function createFromGlobals(): IRequest {
$query = $_GET;
$server = $_SERVER;
$headers = self::getRequestHeaders();
$contentType = $headers['Content-Type'] ?? '';
$contentStrategy = ContentStrategyFactory::createContentStrategy($contentType, $server['REQUEST_METHOD']);
return new HttpRequest($query, $server, $headers, $contentStrategy,[]);
}
// should not be heare
private static function getRequestHeaders(): array {
$headers = [];
foreach ($_SERVER as $key => $value) {
if (substr($key, 0, 5) === 'HTTP_') {
$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
$headers[$header] = $value;
}
}
return $headers;
}
}

@ -0,0 +1,12 @@
<?php
namespace App\Router\Response;
interface IResponse {
public function getContent(): string;
public function setContent(string $content): void;
public function getStatusCode(): int;
public function setStatusCode(int $statusCode): void;
public function getHeaders(): array;
public function setHeader(string $key, string $value): void;
public function send(): void;
}

@ -0,0 +1,65 @@
<?php
namespace App\Router\Response;
class RedirectResponse implements IResponse
{
private $content;
private $statusCode;
private $headers;
private $url;
public function __construct(string $url, int $statusCode = 302, array $headers = [])
{
$this->url = $url;
$this->statusCode = $statusCode;
$this->headers = $headers;
$this->content = '';
}
public function getContent(): string
{
return $this->content;
}
public function setContent(string $content): void
{
$this->content = $content;
}
public function getStatusCode(): int
{
return $this->statusCode;
}
public function setStatusCode(int $statusCode): void
{
$this->statusCode = $statusCode;
}
public function getHeaders(): array
{
return $this->headers;
}
public function setHeader(string $key, string $value): void
{
$this->headers[$key] = $value;
}
public function send(): void
{
http_response_code($this->statusCode);
foreach ($this->headers as $name => $value) {
header("$name: $value");
}
header("Location: " . $this->url);
// Optionally echo content if any
echo $this->content;
exit();
}
}

@ -0,0 +1,49 @@
<?php
namespace App\Router\Response;
class Response implements IResponse {
private string $content;
private int $statusCode;
private array $headers;
public function __construct(string $content = "", int $statusCode = 200, array $headers = []) {
$this->content = $content;
$this->statusCode = $statusCode;
$this->headers = $headers;
}
public function getContent(): string {
return $this->content;
}
public function setContent(string $content): void {
$this->content = $content;
}
public function getStatusCode(): int {
return $this->statusCode;
}
public function setStatusCode(int $statusCode): void {
$this->statusCode = $statusCode;
}
public function getHeaders(): array {
return $this->headers;
}
public function setHeader(string $key, string $value): void {
$this->headers[$key] = $value;
}
public function send(): void {
foreach ($this->headers as $key => $value) {
header("{$key}: {$value}");
}
http_response_code($this->statusCode);
echo $this->content;
}
}
?>

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>{% block title %}{% endblock %}</title>
<link href="/css/{% block css %}base_theme{% endblock %}.css" rel="stylesheet" />
<script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
</head>
<body class="bg-primary">
<div id="layoutAuthentication">
<div id="layoutAuthentication_content">
<main>
{% block main %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5">
<div class="card shadow-lg border-0 rounded-lg mt-5">
<div class="card-header"><h3 class="text-center font-weight-light my-4">Connexion</h3></div>
<div class="card-body">
<form>
<div class="form-floating mb-3">
<input class="form-control" id="inputEmail" type="email" placeholder="nom@exemple.com" />
<label for="inputEmail">Adresse eMail</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="inputPassword" type="password" placeholder="Mot de passe" />
<label for="inputPassword">Mot de passe</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" id="inputRememberPassword" type="checkbox" value="" />
<label class="form-check-label" for="inputRememberPassword">Mémoriser le mot de passe</label>
</div>
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
<a class="small" href="password.html">Mot de passe oublié ?</a>
<a class="btn btn-primary" href="index.html">Se connecter</a>
</div>
</form>
</div>
<div class="card-footer text-center py-3">
<div class="small"><a href="register.html">Besoin d'un compte ? Inscrivez-vous !</a></div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
</main>
</div>
<div id="layoutAuthentication_footer">
<footer class="py-4 bg-light mt-auto">
<div class="container-fluid px-4">
<div class="d-flex align-items-center justify-content-between small">
<div class="text-muted">Copyright &copy; HeartTrack 2023</div>
<div>
<a href="#">Politique de confidentialité</a>
&middot;
<a href="#">Termes &amp; Conditions d'utilisations</a>
</div>
</div>
</div>
</footer>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="js/scripts.js"></script>
</body>
</html>

@ -8,7 +8,7 @@
<meta name="author" content="PINAGOT Antoine" /> <meta name="author" content="PINAGOT Antoine" />
<title>{% block title %}{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.min.css" rel="stylesheet" /> <link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.min.css" rel="stylesheet" />
<link href="/css/styles.css" rel="stylesheet" /> <link href="/css/{% block css %}style{% endblock %}.css" rel="stylesheet" />
<script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script> <script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
</head> </head>
<body class="sb-nav-fixed"> <body class="sb-nav-fixed">
@ -32,10 +32,10 @@
<img src="/assets/img/person/{% block pp %}test{% endblock %}.png" width="30px" height="30px" class="image-ronde"></i> <img src="/assets/img/person/{% block pp %}test{% endblock %}.png" width="30px" height="30px" class="image-ronde"></i>
</a> </a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown"> <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#!">Profile</a></li> <li><a class="dropdown-item" href="/profile">Profile</a></li>
<li><a class="dropdown-item" href="#!">Paramètres</a></li> <li><a class="dropdown-item" href="/settings">Paramètres</a></li>
<li><hr class="dropdown-divider" /></li> <li><hr class="dropdown-divider" /></li>
<li><a class="dropdown-item" href="#!">Déconnexion</a></li> <li><a class="dropdown-item" href="/logout">Déconnexion</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -46,34 +46,34 @@
<div class="sb-sidenav-menu"> <div class="sb-sidenav-menu">
<div class="nav"> <div class="nav">
<div class="sb-sidenav-menu-heading">Menu</div> <div class="sb-sidenav-menu-heading">Menu</div>
<a class="nav-link" href="/home.html.twig"> <a class="nav-link" href="/">
<div class="sb-nav-link-icon"><img src="/assets/img/house.png"></div> <div class="sb-nav-link-icon"><img src="/assets/img/house.png"></div>
Accueil Accueil
</a> </a>
<div class="sb-sidenav-menu-heading">Activités</div> <div class="sb-sidenav-menu-heading">Activités</div>
<a class="nav-link" href="/exercice.html.twig"> <a class="nav-link" href="/exercice">
<div class="sb-nav-link-icon"><img src="/assets/img/sprinter.png"></div> <div class="sb-nav-link-icon"><img src="/assets/img/sprinter.png"></div>
Exercices Exercices
</a> </a>
<a class="nav-link" href="analyze.html"> <a class="nav-link" href="/analyses">
<div class="sb-nav-link-icon"><i class="fas fa-chart-area"></i></div> <div class="sb-nav-link-icon"><i class="fas fa-chart-area"></i></div>
Analyses Analyses
</a> </a>
<div class="sb-sidenav-menu-heading">Social</div> <div class="sb-sidenav-menu-heading">Social</div>
<a class="nav-link" href="/friend.html.twig"> <a class="nav-link" href="/friendlist">
<div class="sb-nav-link-icon"><img src="/assets/img/group.png"></div> <div class="sb-nav-link-icon"><img src="/assets/img/group.png"></div>
Amis Amis
</a> </a>
<a class="nav-link" href="/coaching.html.twig"> <a class="nav-link" href="/coaching">
<div class="sb-nav-link-icon"><img src="/assets/img/coaching.png"></div> <div class="sb-nav-link-icon"><img src="/assets/img/coaching.png"></div>
Coaching Coaching
</a> </a>
<a class="nav-link" href="/mail.html.twig"> <a class="nav-link" href="/mail">
<div class="sb-nav-link-icon"><img src="/assets/img/letter.png"></div> <div class="sb-nav-link-icon"><img src="/assets/img/letter.png"></div>
Messagerie Messagerie
</a> </a>
<div class="sb-sidenav-menu-heading">Gestion de données</div> <div class="sb-sidenav-menu-heading">Gestion de données</div>
<a class="nav-link" href="/import.html.twig"> <a class="nav-link" href="/import">
<div class="sb-nav-link-icon"><img src="/assets/img/upload.png"></div> <div class="sb-nav-link-icon"><img src="/assets/img/upload.png"></div>
Importer Importer
</a> </a>
@ -106,8 +106,9 @@
{% block script %} {% block script %}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="js/scripts.js"></script> <script src="js/scripts.js"></script>
{# <script src="js/preference.js"></script> #}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
<script src="assets/demo/chart-area-demo.js"></script> <script src=".assets/demo/chart-area-demo.js"></script>
<script src="assets/demo/chart-bar-demo.js"></script> <script src="assets/demo/chart-bar-demo.js"></script>
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/umd/simple-datatables.min.js" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/umd/simple-datatables.min.js" crossorigin="anonymous"></script>
<script src="js/datatables-simple-demo.js"></script> <script src="js/datatables-simple-demo.js"></script>

@ -0,0 +1,14 @@
{% extends "errorbase.html.twig" %}
{% block title %}{{code}} : {{title}}{% endblock %}
{% block nb %}
{% if code == 404 %}
<img class="mb-4 img-error" src="assets/img/error-404-monochrome.svg"/>
{% else %}
<h1 class="display-1">{{code}}</h1>
{% endif %}
{% endblock %}
{% block descr %}{{descr}}{% endblock %}

@ -18,10 +18,10 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="text-center mt-4"> <div class="text-center mt-4">
{% block nb %}{% endblock %} <h1 class="display-1">{% block nb %}{% endblock %}</h1>
<p class="lead">{% block name %}{% endblock %}</p> <p class="lead">{% block name %}{% endblock %}</p>
<p>{% block descr %}{% endblock %}</p> <p>{% block descr %}{% endblock %}</p>
<a href="home.html"> <a href="/">
<i class="fas fa-arrow-left me-1"></i> <i class="fas fa-arrow-left me-1"></i>
Retour à l'accueil Retour à l'accueil
</a> </a>

@ -0,0 +1,33 @@
{% extends "base.html.twig" %}
{% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Exercices - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %}
{% block body %}
<div class="container-fluid px-4">
<h1 class="mt-4">Exercices</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Exercices</li>
</ol>
<div class="card-body">
<div class="datatable-container">
<form method="post" action="/exercices">
Type : <input type="text" name="type"/>
Intensité : <input type="text" name="intensite"/>
Date : <input type="text" name="date"/>
<button class="btn btn-primary btn-mrg" id="btnNavbarSearch" type="submit">Ajouter l'exercice</button>
</form>
</div>
</div>
</div>
</div>
</div>
<h1>{{responce}}</h1>
{% endblock %}

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Ami - HearthTrack{% endblock %} {% block title %}Ami - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}
@ -10,7 +12,7 @@
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<h1 class="mt-4">Liste d'ami</h1> <h1 class="mt-4">Liste d'ami</h1>
<ol class="breadcrumb mb-4"> <ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="home.html">Accueil</a></li> <li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Ami</li> <li class="breadcrumb-item active">Ami</li>
</ol> </ol>
@ -25,10 +27,10 @@
<th style=" <th style="
padding-left: 42%; padding-left: 42%;
"> ">
<form class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0"> <form class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0" method="get" action="/search-user">
<div class="input-group"> <div class="input-group">
<input class="form-control" type="text" placeholder="Rechercher..." aria-label="Rechercher..." aria-describedby="btnNavbarSearch" /> <input class="form-control" name="username" type="text" placeholder="Rechercher..." aria-label="Rechercher..." aria-describedby="btnNavbarSearch" />
<button class="btn btn-primary" id="btnNavbarSearch" type="button"><i class="fas fa-search"></i></button> <button class="btn btn-primary" id="btnNavbarSearch" type="submit"><i class="fas fa-search"></i></button>
</div> </div>
</form> </form>
</th> </th>
@ -43,7 +45,11 @@
<td>{{utili.prenom}}</td> <td>{{utili.prenom}}</td>
<td style=" <td style="
padding-left: 45%;"> padding-left: 45%;">
<button class="btn btn-primary" id="btnNavbarSearch" type="button">Ajouter un ami</button> <form method="post" action="/add-friend">
<input type="hidden" name="username" value="{{ utili.username }}">
<button class="btn btn-primary" type="submit">Ajouter un ami</button>
</form>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -54,4 +60,5 @@
</div> </div>
</div> </div>
</div> </div>
<h1>{{responce}}</h1>
{% endblock %} {% endblock %}

@ -0,0 +1,64 @@
{% extends "base.html.twig" %}
{% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Coaching - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %}
{% block body %}
<div class="container-fluid px-4">
<h1 class="mt-4">Coaching</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Coaching</li>
</ol>
<div class="card-body">
<div class="datatable-container">
<table id="datatablesSimple" class="datatable-table">
<thead>
<tr>
<th></th>
<th>Nom</th>
<th>Prénom</th>
<th style="
padding-left: 42%;
">
<form class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0" method="get" action="/search-member">
<div class="input-group">
<input class="form-control" name="username" type="text" placeholder="Rechercher..." aria-label="Rechercher..." aria-describedby="btnNavbarSearch" />
<button class="btn btn-primary" id="btnNavbarSearch" type="submit"><i class="fas fa-search"></i></button>
</div>
</form>
</th>
</tr>
</thead>
<tbody>
{% for utili in users %}
<tr>
<td><style> .image-ronde{ clip-path:ellipse(50% 50%); } </style>
<img src="/assets/img/person/{{utili.img}}.png" width="35px" height="35px" class="image-ronde"></td>
<td>{{utili.nom}}</td>
<td>{{utili.prenom}}</td>
<td style="
padding-left: 45%;">
<form method="post" action="/add-member">
<input type="hidden" name="username" value="{{ utili.username }}">
<button class="btn btn-primary" type="submit">Ajouter un membre</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<h1>{{responce}}</h1>
{% endblock %}

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Analyses - HearthTrack{% endblock %} {% block title %}Analyses - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}
@ -10,7 +12,7 @@
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<h1 class="mt-4">Analyses</h1> <h1 class="mt-4">Analyses</h1>
<ol class="breadcrumb mb-4"> <ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="home.html">Accueil</a></li> <li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Analyses</li> <li class="breadcrumb-item active">Analyses</li>
</ol> </ol>
<div class="card-body"> <div class="card-body">

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Coaching - HearthTrack{% endblock %} {% block title %}Coaching - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}
@ -11,11 +13,13 @@
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<h1 class="mt-4">Coaching</h1> <h1 class="mt-4">Coaching</h1>
<ol class="breadcrumb mb-4"> <ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="home.html">Accueil</a></li> <li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Coaching</li> <li class="breadcrumb-item active">Coaching</li>
</ol> </ol>
<style>.btn-mrg{margin:15px; margin-left:83%}</style> <style>.btn-mrg{margin:15px; margin-left:83%}</style>
<button class="btn btn-primary btn-mrg" id="btnNavbarSearch" type="button">Ajouter un membre</button> <form method="get" action="/member">
<button class="btn btn-primary btn-mrg" id="btnNavbarSearch" type="submit">Ajouter un membre</button>
</form>
<div class="card-body"> <div class="card-body">
<div class="datatable-container"> <div class="datatable-container">
@ -25,7 +29,7 @@
<th></th> <th></th>
<th>Nom</th> <th>Nom</th>
<th>Prénom</th> <th>Prénom</th>
<th>Status</th> <th>Identifiant</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -38,9 +42,17 @@
<td>{{ath.prenom}}</td> <td>{{ath.prenom}}</td>
<td>{{ath.status}}</td> <td>{{ath.status}}</td>
<td> <td>
<a href="#"><img src="/assets/img/msg.png"></a> <div >
<a href="#"><img src="/assets/img/block.png"></a> <form method="get" action="/mail">
<a href="#"><img src="/assets/img/delete.png"></a> <input type="hidden" name="username" value="{{ ami.username }}"><button class="btn" type="submit"><img src="/assets/img/msg.png"></button></input>
</form>
<form method="post" action="/friendlist">
<input type="hidden" name="username" value="{{ ami.username }}"><button class="btn" type="submit"><img src="/assets/img/block.png"></button></input>
</form>
<form method="post" action="/friendlist">
<input type="hidden" name="username" value="{{ ami.username }}"><button class="btn" type="submit"><img src="/assets/img/delete.png"></button></input>
</form>
</div>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Exercices - HearthTrack{% endblock %} {% block title %}Exercices - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}
@ -10,11 +12,13 @@
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<h1 class="mt-4">Exercices</h1> <h1 class="mt-4">Exercices</h1>
<ol class="breadcrumb mb-4"> <ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="home.html">Accueil</a></li> <li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Exercices</li> <li class="breadcrumb-item active">Exercices</li>
</ol> </ol>
<style>.btn-mrg{margin:15px; margin-left:85%}</style> <style>.btn-mrg{margin:15px; margin-left:85%}</style>
<button class="btn btn-primary btn-mrg" id="btnNavbarSearch" type="button">Ajouter un exercice</button> <form method="get" action="/activity">
<button class="btn btn-primary btn-mrg" id="btnNavbarSearch" type="submit">Ajouter un exercice</button>
</form>
<div class="card-body"> <div class="card-body">
<div class="datatable-container"> <div class="datatable-container">
<table id="datatablesSimple" class="datatable-table"> <table id="datatablesSimple" class="datatable-table">
@ -24,7 +28,6 @@
<th>Type</th> <th>Type</th>
<th>Intensité prévue</th> <th>Intensité prévue</th>
<th>Status</th> <th>Status</th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -34,9 +37,6 @@
<td>{{exo.type}}</td> <td>{{exo.type}}</td>
<td>{{exo.intensite}}</td> <td>{{exo.intensite}}</td>
<td>{{exo.status}}</td> <td>{{exo.status}}</td>
<td>
<a href="#"><img src="/assets/img/delete.png"></a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Amis - HearthTrack{% endblock %} {% block title %}Amis - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}
@ -10,39 +12,54 @@
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<h1 class="mt-4">Liste d'ami</h1> <h1 class="mt-4">Liste d'ami</h1>
<ol class="breadcrumb mb-4"> <ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="home.html">Accueil</a></li> <li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Ami</li> <li class="breadcrumb-item active">Ami</li>
</ol> </ol>
<style>.btn-mrg{margin:15px; margin-left:87%}</style> <style>.btn-mrg{margin:15px; margin-left:87%}</style>
<button class="btn btn-primary btn-mrg" id="btnNavbarSearch" type="button">Ajouter un ami</button> <form method="get" action="/friend">
<button class="btn btn-primary btn-mrg" id="btnNavbarSearch" type="submit">Ajouter un ami</button>
</form>
<div class="card-body"> <div class="card-body">
<div class="datatable-container"> <div class="datatable-container">
<table id="datatablesSimple" class="datatable-table"> <table id="datatablesSimple" class="datatable-table">
{% if friendship is empty %}
<p>Vous n'avez aucun ami.</p>
{% else %}
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th>Nom</th> <th>Nom</th>
<th>Prénom</th> <th>Prénom</th>
<th>Status</th> <th>Identifiant</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for ami in friendship %} {% for ami in friendship %}
<tr> <tr>
<td><style> .image-ronde{ clip-path:ellipse(50% 50%); } </style> <td><style> .image-ronde{ clip-path:ellipse(50% 50%); } </style>
<img src="/assets/img/person/{{ami.img}}.png" width="35px" height="35px" class="image-ronde"></td> <img src="/assets/img/person/{{ami.img}}.png" width="35px" height="35px" class="image-ronde"></td>
<td>{{ami.nom}}</td> <td>{{ami.nom}}</td>
<td>{{ami.prenom}}</td> <td>{{ami.prenom}}</td>
<td>{{ami.status}}</td> <td>{{ami.status}}</td>
<td> <td>
<a href="#"><img src="/assets/img/msg.png"></a> <div >
<a href="#"><img src="/assets/img/block.png"></a> <form method="get" action="/mail">
<a href="#"><img src="/assets/img/delete.png"></a> <input type="hidden" name="username" value="{{ ami.username }}"><button class="btn" type="submit"><img src="/assets/img/msg.png"></button></input>
</td> </form>
</tr> <form method="post" action="/friendlist">
{% endfor %} <input type="hidden" name="username" value="{{ ami.username }}"><button class="btn" type="submit"><img src="/assets/img/block.png"></button></input>
</form>
<form method="post" action="/friendlist">
<input type="hidden" name="username" value="{{ ami.username }}"><button class="btn" type="submit"><img src="/assets/img/delete.png"></button></input>
</form>
</div>
</td>
</tr>
{% endfor %}
{% endif %}
</tbody> </tbody>
</table> </table>
</div> </div>

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Accueil - HearthTrack{% endblock %} {% block title %}Accueil - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Importer - HearthTrack{% endblock %} {% block title %}Importer - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}
@ -27,8 +29,10 @@
<label for="file-input"> <label for="file-input">
<img src="/assets/img/uploadW.svg"/> <img src="/assets/img/uploadW.svg"/>
</label> </label>
<form action="/analyses" method="post">
<input id="file-input" type="file" style="visibility:hidden; width:0; height:0;"/> <input id="file-input" type="file" name="fileToUpload" value=""style="visibility: hidden; width:0; height:0;"/>
<input type="submit" value="Soumettre le fichier" name="submit"/>
</form>
</div> </div>
</div> </div>
</div> </div>

@ -0,0 +1 @@
<a href="/log">Se connecter</button>

@ -0,0 +1,40 @@
{% extends "authbase.html.twig" %}
{% block css %}{{css}}{% endblock %}
{% block title %}Connexion - HearthTrack{% endblock %}
{% block main %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5">
<div class="card shadow-lg border-0 rounded-lg mt-5">
<div class="card-header"><h3 class="text-center font-weight-light my-4">Connexion</h3></div>
<div class="card-body">
<form method="post" action="/login">
<div class="form-floating mb-3">
<input class="form-control" id="username" name="username" type="text" placeholder="Nom d'utilisateur" />
<label for="username">Nom d'utilisateur</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="mdp" name="mdp" type="password" placeholder="Mot de passe" />
<label for="mdp">Mot de passe</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" id="inputRememberPassword" type="checkbox" value="" />
<label class="form-check-label" for="inputRememberPassword">Mémoriser le mot de passe</label>
</div>
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
<a class="small" href="/pass">Mot de passe oublié ?</a>
<button class="btn btn-primary" type="submit">Se connecter</a>
</div>
</form>
</div>
<div class="card-footer text-center py-3">
<div class="small"><a href="/regist">Besoin d'un compte ? Inscrivez-vous !</a></div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Messagerie - HearthTrack{% endblock %} {% block title %}Messagerie - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}

@ -0,0 +1,33 @@
{% extends "authbase.html.twig" %}
{% block css %}{{css}}{% endblock %}
{% block title %}Mot de passe oublié - HearthTrack{% endblock %}
{% block main %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5">
<div class="card shadow-lg border-0 rounded-lg mt-5">
<div class="card-header"><h3 class="text-center font-weight-light my-4">Récupération du mot de passe</h3></div>
<div class="card-body">
<div class="small mb-3 text-muted">Entrez votre adresse eMail pour recevoir un lien pour changer de mot de passe</div>
<form method="post" action="/password">
<div class="form-floating mb-3">
<input class="form-control" id="email" name="email" type="email" placeholder="name@example.com" />
<label for="email">Adresse eMail</label>
</div>
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
<a class="small" href="/log">Retour à la connexion</a>
<button class="btn btn-primary" type="submit">Réinitialiser votre mot de passe</a>
</div>
</form>
</div>
<div class="card-footer text-center py-3">
<div class="small"><a href="/regist">Besoin d'un compte ? Inscrivez-vous !</a></div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Profile - HearthTrack{% endblock %} {% block title %}Profile - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}
@ -10,7 +12,7 @@
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<h1 class="mt-4">Profile</h1> <h1 class="mt-4">Profile</h1>
<ol class="breadcrumb mb-4"> <ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="home.html">Accueil</a></li> <li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Profile</li> <li class="breadcrumb-item active">Profile</li>
</ol> </ol>
<div class="row"> <div class="row">

@ -0,0 +1,98 @@
{% extends "authbase.html.twig" %}
{% block css %}{{css}}{% endblock %}
{% block title %}Inscription - HearthTrack{% endblock %}
{% block main %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-7">
<div class="card shadow-lg border-0 rounded-lg mt-5">
<div class="card-header"><h3 class="text-center font-weight-light my-4">Créer un compte</h3></div>
<div class="card-body">
<form method="post" action="/register">
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="nom" name="nom" type="text" placeholder="Entrez votre nom" />
<label for="nom">Nom de famille</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input class="form-control" id="prenom" name="prenom" type="text" placeholder="Entrez votre prénom" />
<label for="prenom">Prénom</label>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="username" name="username" type="text" placeholder="Entrez votre pseudonyme" />
<label for="username">Nom d'utilisateur</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input class="form-control" id="sexe" name="sexe" type="hidden">
<select id="sexe" name="sexe">
<option value="male">Homme</option>
<option value="female">Femme</option>
<option value="unknown">Ne se prononce pas</option>
</select>
</input>
</div>
</div>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="mail" type="mail" placeholder="nom@exemple.com" />
<label for="mail">Adresse eMail</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="dateNaissance" name="dateNaissance" type="date" placeholder="" />
<label for="dateNaissance">Date de naissance</label>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="taille" name="taille" type="text" placeholder="Entrez votre taille" />
<label for="taille">Taille</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="poids" name="poids" type="text" placeholder="Entrez votre poids" />
<label for="poids">Poids</label>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="mdp" name="mdp" type="password" placeholder="Créez un mot de passe" />
<label for="mdp">Mot de passe</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="confirmMdp" name="confirmMdp" type="password" placeholder="Confirmez votre mot de passe" />
<label for="confirmMdp">Confirmer le mot de passe</label>
</div>
</div>
</div>
<div class="mt-4 mb-0">
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-block">Créer un compte</a>
</div>
</div>
</form>
</div>
<div class="card-footer text-center py-3">
<div class="small"><a href="/log">Avez-vous déjà un compte ? Connectez-vous ?</a></div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

@ -2,6 +2,8 @@
{% block pp %}{{pp}}{% endblock %} {% block pp %}{{pp}}{% endblock %}
{% block css %}{{css}}{% endblock %}
{% block title %}Paramètres - HearthTrack{% endblock %} {% block title %}Paramètres - HearthTrack{% endblock %}
{% block user %}{{user}} - {{role}}{% endblock %} {% block user %}{{user}} - {{role}}{% endblock %}
@ -10,7 +12,7 @@
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<h1 class="mt-4">Paramètres</h1> <h1 class="mt-4">Paramètres</h1>
<ol class="breadcrumb mb-4"> <ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="home.html">Accueil</a></li> <li class="breadcrumb-item"><a href="/">Accueil</a></li>
<li class="breadcrumb-item active">Paramètres</li> <li class="breadcrumb-item active">Paramètres</li>
</ol> </ol>
<div class="row"> <div class="row">
@ -37,10 +39,10 @@
Date de naissance : {{infoUser.dateNaiss}} Date de naissance : {{infoUser.dateNaiss}}
</div> </div>
<div style="text-align:center"> <div style="text-align:center">
Sport favori : {{infoUser.favSport}} Email : {{infoUser.favSport}}
</div> </div>
<div style="text-align:center; margin-bottom: 15px;"> <div style="text-align:center; margin-bottom: 15px;">
Coach : {{infoUser.coach}} Numéro de téléphone : {{infoUser.coach}}
</div> </div>
</div> </div>
</div> </div>
@ -53,8 +55,68 @@
Générale Générale
</div> </div>
<div class="card-body"> <div class="card-body">
<form id="preferencesForm" method="post" action="/preferences">
<div>
<label for="notif">Notifications:</label>
<input type="checkbox" id="notif" name="notifications">
</div>
<div>
<label for="theme">Thème:</label>
<select id="theme" name="theme">
<option value="base_theme">Base</option>
<option value="dark_theme">Sombre</option>
<option value="pink_theme">Rose</option>
</select>
</div>
<button type="submit" id="saveButton" class="btn btn-primary">Enregistrer</button>
</form>
<h1></h1>
<form action="/mdp" method="post">
<div>
<label for="ancienMotDePasse">Ancien mot de passe:</label>
<input type="password" id="ancienMotDePasse" name="ancienMotDePasse" required>
</div>
<div>
<label for="nouveauMotDePasse">Nouveau mot de passe:</label>
<input type="password" id="nouveauMotDePasse" name="nouveauMotDePasse" required>
</div>
<div>
<label for="confirmerMotDePasse">Confirmer le nouveau mot de passe:</label>
<input type="password" id="confirmerMotDePasse" name="confirmerMotDePasse" required>
</div>
<div>
<button type="submit" class="btn btn-primary">Enregistrer</button>
</div>
</form>
<h1></h1>
<form action="/psettings" method="post">
<div>
<label for="nom">Nom:</label>
<input type="text" id="nom" name="nom" required>
</div>
<div>
<label for="prenom">Prénom:</label>
<input type="text" id="prenom" name="prenom" required>
</div>
<div>
<label for="dateNaissance">Date de naissance:</label>
<input type="date" id="dateNaissance" name="dateNaissance" required>
</div>
<div>
<label for="email">Email:</label>
<input type="email" id="mail" name="mail" required>
</div>
<div>
<label for="numeroTelephone">Numéro de téléphone:</label>
<input type="tel" id="tel" name="tel" required>
</div>
<div>
<button type="submit" class="btn btn-primary">Modifier les informations personnelles</button>
</div>
</form>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

@ -0,0 +1,29 @@
<?php
namespace App\Views\Directives;
use App\Router\Router;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class Navigate extends AbstractExtension
{
private Router $router;
public function __construct( Router $router)
{
$this->router = $router;
}
public function getFunctions(): array
{
return [
new TwigFunction('navigate', [$this, 'getPath']),
];
}
public function getPath(string $name, array $parameters = []): string
{
return $this->router->generate($name, $parameters);
}
}

@ -0,0 +1,17 @@
document.getElementById('saveButton').addEventListener('click', function() {
var preferences = {
notifications: document.getElementById('notif').checked,
theme: document.getElementById('theme').value
};
fetch('/savePreferences', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(preferences),
})
.then(response => response.json())
.then(data => console.log(data))
.catch((error) => console.error('Error:', error));
});

@ -0,0 +1,38 @@
<?php
namespace Data\Core;
class Preferences {
private String $cookie;
private Array $theme;
public function __construct(){
if (isset($_COOKIE['preferences'])){
$this->cookie = $_COOKIE['preferences'];
} else {
$this->cookie = setcookie('preferences', 'base_theme', time()+(3600*24)*7);
}
$this->theme = array(
'base_theme',
'dark_theme',
'pink_theme'
);
}
public function majCookie(String $maj){
try{
foreach($this->theme as $t){
$this->cookie = $maj;
setcookie('preferences', $maj);
}
} catch (Exception $e){
throw new ValueError;
}
}
public function getCookie():String{
return $this->cookie;
}
}
?>

@ -0,0 +1,85 @@
<?php
namespace Shared;
use App\Router\Request\IRequest;
/**
* Responsible for resolving the arguments passed to a controller action.
*/
class ArgumentControllerResolver implements IArgumentResolver{
/**
* Resolves and returns the arguments for a given controller callable.
*
* @param IRequest $request The HTTP request object.
* @param callable $controller The controller callable.
* @return array An array of resolved arguments.
* @throws \ReflectionException If the controller method does not exist.
* @throws \InvalidArgumentException If an argument cannot be resolved.
*/
public function getArguments(IRequest $request, callable $controller): array
{
try {
// Check if $controller is an array and has two elements (class and method)
if (is_array($controller) && count($controller) === 2) {
$className = is_object($controller[0]) ? get_class($controller[0]) : $controller[0];
$methodName = $controller[1];
$reflectionMethod = new \ReflectionMethod($className, $methodName);
} else {
// Handle other types of callables if needed
throw new \InvalidArgumentException("Invalid controller callable format.");
}
} catch (\ReflectionException $e) {
throw new \InvalidArgumentException("Controller method error: " . $e->getMessage());
}
$args = [];
foreach ($reflectionMethod->getParameters() as $param) {
if (IRequest::class === $param->getType()->getName() || is_subclass_of($param->getType()->getName(), IRequest::class)) {
$args[] = $request;
continue;
}
$name = $param->getName();
$value = $this->getFromRequest($name, $request);
if ($value === null && $param->isDefaultValueAvailable()) {
$value = $param->getDefaultValue();
} elseif ($value === null) {
throw new \InvalidArgumentException("Missing argument: $name");
}
$args[] = $value;
}
return $args;
}
/**
* Extracts a value from the request based on a key.
*
* @param string $key The key to look for in the request.
* @param IRequest $req The request object.
* @return mixed The value from the request or null if not found.
*/
public function getFromRequest(string $key, IRequest $req): mixed
{
$body = $req->getBody();
if (array_key_exists($key, $body)) {
return $body[$key];
}
$queryParams = $req->getQueryParameters();
if (array_key_exists($key, $queryParams)) {
return $queryParams[$key];
}
$requestParams = $req->getRequestParameters();
if (array_key_exists($key, $requestParams)) {
return $requestParams[$key];
}
return null;
}
}

@ -0,0 +1,19 @@
<?php
namespace Shared;
use App\Router\Request\IRequest;
/**
* Interface for classes that resolve arguments for controller methods.
*/
interface IArgumentResolver
{
/**
* Resolves the arguments for a controller method based on the given request.
*
* @param IRequest $request The request object.
* @param callable $controller The controller callable.
* @return array An array of arguments resolved for the controller method.
*/
public function getArguments(IRequest $request, callable $controller): array;
}

@ -0,0 +1,60 @@
<?php
namespace Shared;
class Log {
const INFO = 'INFO';
const WARNING = 'WARNING';
const ERROR = 'ERROR';
private static int $logCount = 0;
private static array $logs = [];
private static function getLogStyle(string $level): string {
return match ($level) {
self::WARNING => "background-color: #fff3cd; color: #856404; border-color: #ffeeba",
self::ERROR => "background-color: #f8d7da; color: #721c24; border-color: #f5c6cb",
default => "background-color: #f8f8f8; color: #383d41; border-color: #ccc",
};
}
private static function addLog($something, string $level, string $label): bool|string
{
$style = self::getLogStyle($level);
ob_start();
echo "<pre style='$style; padding: 10px;'>";
echo "<strong>$label [$level] (Log " . self::$logCount . ")</strong><br>";
var_dump($something);
echo "</pre>";
$logOutput = ob_get_clean();
self::$logs[] = ['level' => $level, 'output' => $logOutput];
return $logOutput;
}
public static function dd($something, string $label = "LOGGER", string $level = self::INFO) {
echo self::addLog($something, $level, $label);
die();
}
public static function ddArray(array $array, string $label = "LOGGER", string $level = self::INFO) {
self::dd($array, $label, $level);
}
public static function log($something, string $label = "LOGGER", string $level = self::INFO) {
self::$logCount++;
echo self::addLog($something, $level, $label);
}
public static function getLogCount(): int
{
return self::$logCount;
}
public static function getLogsByLevel(string $level): array
{
return array_filter(self::$logs, function($log) use ($level) {
return $log['level'] === $level;
});
}
}

@ -0,0 +1,30 @@
<?php
namespace Shared\Attributes;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
class Route
{
public function __construct(
private string|array $path = '',
private ?string $name = null,
private array|string $methods = ['GET'],
)
{}
public function getPath(): array| string{
return $this->path;
}
public function getName(): ?string{
return $this->name;
}
public function getMethods(): array | string
{
return $this->methods;
}
}

@ -0,0 +1,34 @@
<?php
namespace Shared\Exception;
class HttpException extends \RuntimeException
{
private int $statusCode;
private array $headers;
public function __construct(int $statusCode, string $message = '', \Throwable $previous = null, array $headers = [], int $code = 0)
{
$this->statusCode = $statusCode;
$this->headers = $headers;
parent::__construct($message, $code, $previous);
}
public function getStatusCode(): int
{
return $this->statusCode;
}
public function getHeaders(): array
{
return $this->headers;
}
/**
* @return void
*/
public function setHeaders(array $headers)
{
$this->headers = $headers;
}
}

@ -0,0 +1,11 @@
<?php
namespace Shared\Exception;
class NotFoundHttpException extends HttpException
{
public function __construct(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = [])
{
parent::__construct(404, $message, $previous, $headers, $code);
}
}

@ -0,0 +1,30 @@
<?php
namespace Shared\Exception;
use Exception;
use JetBrains\PhpStorm\Pure;
class ValidationException extends Exception {
protected array $errors;
#[Pure] public function __construct(array $errors, $message = "Validation errors occurred", $code = 0, Exception $previous = null) {
parent::__construct($message, $code, $previous);
$this->errors = $errors;
}
public function getErrors(): array
{
return $this->errors;
}
public function __toString() {
return __CLASS__ . ": [{$this->code}]: {$this->message}\n" . $this->formatErrors();
}
protected function formatErrors(): string
{
return implode("\n", array_map(function ($error) {
return "- {$error}";
}, $this->errors));
}
}

@ -0,0 +1,7 @@
language: php
php:
- 5.3
- 5.4
- 5.5
script: phpunit --coverage-text ./

@ -0,0 +1,270 @@
<?php
class AltoRouter {
protected $routes = array();
protected $namedRoutes = array();
protected $basePath = '';
protected $matchTypes = array(
'i' => '[0-9]++',
'a' => '[0-9A-Za-z]++',
'h' => '[0-9A-Fa-f]++',
'*' => '.+?',
'**' => '.++',
'' => '[^/\.]++'
);
/**
* Create router in one call from config.
*
* @param array $routes
* @param string $basePath
* @param array $matchTypes
*/
public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) {
$this->addRoutes($routes);
$this->setBasePath($basePath);
$this->addMatchTypes($matchTypes);
}
/**
* Add multiple routes at once from array in the following format:
*
* $routes = array(
* array($method, $route, $target, $name)
* );
*
* @param array $routes
* @return void
* @author Koen Punt
*/
public function addRoutes($routes){
if(!is_array($routes) && !$routes instanceof Traversable) {
throw new \Exception('Routes should be an array or an instance of Traversable');
}
foreach($routes as $route) {
call_user_func_array(array($this, 'map'), $route);
}
}
/**
* Set the base path.
* Useful if you are running your application from a subdirectory.
*/
public function setBasePath($basePath) {
$this->basePath = $basePath;
}
/**
* Add named match types. It uses array_merge so keys can be overwritten.
*
* @param array $matchTypes The key is the name and the value is the regex.
*/
public function addMatchTypes($matchTypes) {
$this->matchTypes = array_merge($this->matchTypes, $matchTypes);
}
/**
* Map a route to a target
*
* @param string $method One of 4 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PUT|DELETE)
* @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id]
* @param mixed $target The target where this route should point to. Can be anything.
* @param string $name Optional name of this route. Supply if you want to reverse route this url in your application.
*/
public function map($method, $route, $target, $name = null) {
$this->routes[] = array($method, $route, $target, $name);
if($name) {
if(isset($this->namedRoutes[$name])) {
throw new \Exception("Can not redeclare route '{$name}'");
} else {
$this->namedRoutes[$name] = $route;
}
}
return;
}
/**
* Reversed routing
*
* Generate the URL for a named route. Replace regexes with supplied parameters
*
* @param string $routeName The name of the route.
* @param array @params Associative array of parameters to replace placeholders with.
* @return string The URL of the route with named parameters in place.
*/
public function generate($routeName, array $params = array()) {
// Check if named route exists
if(!isset($this->namedRoutes[$routeName])) {
throw new \Exception("Route '{$routeName}' does not exist.");
}
// Replace named parameters
$route = $this->namedRoutes[$routeName];
// prepend base path to route url again
$url = $this->basePath . $route;
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
list($block, $pre, $type, $param, $optional) = $match;
if ($pre) {
$block = substr($block, 1);
}
if(isset($params[$param])) {
$url = str_replace($block, $params[$param], $url);
} elseif ($optional) {
$url = str_replace($pre . $block, '', $url);
}
}
}
return $url;
}
/**
* Match a given Request Url against stored routes
* @param string $requestUrl
* @param string $requestMethod
* @return array|boolean Array with route information on success, false on failure (no match).
*/
public function match($requestUrl = null, $requestMethod = null) {
$params = array();
$match = false;
// set Request Url if it isn't passed as parameter
if($requestUrl === null) {
$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
}
// strip base path from request url
$requestUrl = substr($requestUrl, strlen($this->basePath));
// Strip query string (?a=b) from Request Url
if (($strpos = strpos($requestUrl, '?')) !== false) {
$requestUrl = substr($requestUrl, 0, $strpos);
}
// set Request Method if it isn't passed as a parameter
if($requestMethod === null) {
$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
}
// Force request_order to be GP
// http://www.mail-archive.com/internals@lists.php.net/msg33119.html
$_REQUEST = array_merge($_GET, $_POST);
foreach($this->routes as $handler) {
list($method, $_route, $target, $name) = $handler;
$methods = explode('|', $method);
$method_match = false;
// Check if request method matches. If not, abandon early. (CHEAP)
foreach($methods as $method) {
if (strcasecmp($requestMethod, $method) === 0) {
$method_match = true;
break;
}
}
// Method did not match, continue to next route.
if(!$method_match) continue;
// Check for a wildcard (matches all)
if ($_route === '*') {
$match = true;
} elseif (isset($_route[0]) && $_route[0] === '@') {
$match = preg_match('`' . substr($_route, 1) . '`u', $requestUrl, $params);
} else {
$route = null;
$regex = false;
$j = 0;
$n = isset($_route[0]) ? $_route[0] : null;
$i = 0;
// Find the longest non-regex substring and match it against the URI
while (true) {
if (!isset($_route[$i])) {
break;
} elseif (false === $regex) {
$c = $n;
$regex = $c === '[' || $c === '(' || $c === '.';
if (false === $regex && false !== isset($_route[$i+1])) {
$n = $_route[$i + 1];
$regex = $n === '?' || $n === '+' || $n === '*' || $n === '{';
}
if (false === $regex && $c !== '/' && (!isset($requestUrl[$j]) || $c !== $requestUrl[$j])) {
continue 2;
}
$j++;
}
$route .= $_route[$i++];
}
$regex = $this->compileRoute($route);
$match = preg_match($regex, $requestUrl, $params);
}
if(($match == true || $match > 0)) {
if($params) {
foreach($params as $key => $value) {
if(is_numeric($key)) unset($params[$key]);
}
}
return array(
'target' => $target,
'params' => $params,
'name' => $name
);
}
}
return false;
}
/**
* Compile the regex for a given route (EXPENSIVE)
*/
private function compileRoute($route) {
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
$matchTypes = $this->matchTypes;
foreach($matches as $match) {
list($block, $pre, $type, $param, $optional) = $match;
if (isset($matchTypes[$type])) {
$type = $matchTypes[$type];
}
if ($pre === '.') {
$pre = '\.';
}
//Older versions of PCRE require the 'P' in (?P<named>)
$pattern = '(?:'
. ($pre !== '' ? $pre : null)
. '('
. ($param !== '' ? "?P<$param>" : null)
. $type
. '))'
. ($optional !== '' ? '?' : null);
$route = str_replace($block, $pattern, $route);
}
}
return "`^$route$`u";
}
}

@ -0,0 +1,423 @@
<?php
require 'AltoRouter.php';
class AltoRouterDebug extends AltoRouter{
public function getNamedRoutes(){
return $this->namedRoutes;
}
public function getRoutes(){
return $this->routes;
}
public function getBasePath(){
return $this->basePath;
}
}
class SimpleTraversable implements Iterator{
protected $_position = 0;
protected $_data = array(
array('GET', '/foo', 'foo_action', null),
array('POST', '/bar', 'bar_action', 'second_route')
);
public function current(){
return $this->_data[$this->_position];
}
public function key(){
return $this->_position;
}
public function next(){
++$this->_position;
}
public function rewind(){
$this->_position = 0;
}
public function valid(){
return isset($this->_data[$this->_position]);
}
}
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-07-14 at 17:47:46.
*/
class AltoRouterTest extends PHPUnit_Framework_TestCase
{
/**
* @var AltoRouter
*/
protected $router;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->router = new AltoRouterDebug;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @covers AltoRouter::addRoutes
*/
public function testAddRoutes()
{
$method = 'POST';
$route = '/[:controller]/[:action]';
$target = function(){};
$this->router->addRoutes(array(
array($method, $route, $target),
array($method, $route, $target, 'second_route')
));
$routes = $this->router->getRoutes();
$this->assertEquals(array($method, $route, $target, null), $routes[0]);
$this->assertEquals(array($method, $route, $target, 'second_route'), $routes[1]);
}
/**
* @covers AltoRouter::addRoutes
*/
public function testAddRoutesAcceptsTraverable()
{
$traversable = new SimpleTraversable();
$this->router->addRoutes($traversable);
$traversable->rewind();
$first = $traversable->current();
$traversable->next();
$second = $traversable->current();
$routes = $this->router->getRoutes();
$this->assertEquals($first, $routes[0]);
$this->assertEquals($second, $routes[1]);
}
/**
* @covers AltoRouter::addRoutes
* @expectedException Exception
*/
public function testAddRoutesThrowsExceptionOnInvalidArgument()
{
$this->router->addRoutes(new stdClass);
}
/**
* @covers AltoRouter::setBasePath
*/
public function testSetBasePath()
{
$basePath = $this->router->setBasePath('/some/path');
$this->assertEquals('/some/path', $this->router->getBasePath());
$basePath = $this->router->setBasePath('/some/path');
$this->assertEquals('/some/path', $this->router->getBasePath());
}
/**
* @covers AltoRouter::map
*/
public function testMap()
{
$method = 'POST';
$route = '/[:controller]/[:action]';
$target = function(){};
$this->router->map($method, $route, $target);
$routes = $this->router->getRoutes();
$this->assertEquals(array($method, $route, $target, null), $routes[0]);
}
/**
* @covers AltoRouter::map
*/
public function testMapWithName()
{
$method = 'POST';
$route = '/[:controller]/[:action]';
$target = function(){};
$name = 'myroute';
$this->router->map($method, $route, $target, $name);
$routes = $this->router->getRoutes();
$this->assertEquals(array($method, $route, $target, $name), $routes[0]);
$named_routes = $this->router->getNamedRoutes();
$this->assertEquals($route, $named_routes[$name]);
try{
$this->router->map($method, $route, $target, $name);
$this->fail('Should not be able to add existing named route');
}catch(Exception $e){
$this->assertEquals("Can not redeclare route '{$name}'", $e->getMessage());
}
}
/**
* @covers AltoRouter::generate
*/
public function testGenerate()
{
$params = array(
'controller' => 'test',
'action' => 'someaction'
);
$this->router->map('GET', '/[:controller]/[:action]', function(){}, 'foo_route');
$this->assertEquals('/test/someaction',
$this->router->generate('foo_route', $params));
$params = array(
'controller' => 'test',
'action' => 'someaction',
'type' => 'json'
);
$this->assertEquals('/test/someaction',
$this->router->generate('foo_route', $params));
}
public function testGenerateWithOptionalUrlParts()
{
$this->router->map('GET', '/[:controller]/[:action].[:type]?', function(){}, 'bar_route');
$params = array(
'controller' => 'test',
'action' => 'someaction'
);
$this->assertEquals('/test/someaction',
$this->router->generate('bar_route', $params));
$params = array(
'controller' => 'test',
'action' => 'someaction',
'type' => 'json'
);
$this->assertEquals('/test/someaction.json',
$this->router->generate('bar_route', $params));
}
public function testGenerateWithNonexistingRoute()
{
try{
$this->router->generate('nonexisting_route');
$this->fail('Should trigger an exception on nonexisting named route');
}catch(Exception $e){
$this->assertEquals("Route 'nonexisting_route' does not exist.", $e->getMessage());
}
}
/**
* @covers AltoRouter::match
* @covers AltoRouter::compileRoute
*/
public function testMatch()
{
$this->router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route');
$this->assertEquals(array(
'target' => 'foo_action',
'params' => array(
'controller' => 'test',
'action' => 'do'
),
'name' => 'foo_route'
), $this->router->match('/foo/test/do', 'GET'));
$this->assertFalse($this->router->match('/foo/test/do', 'POST'));
$this->assertEquals(array(
'target' => 'foo_action',
'params' => array(
'controller' => 'test',
'action' => 'do'
),
'name' => 'foo_route'
), $this->router->match('/foo/test/do?param=value', 'GET'));
}
public function testMatchWithFixedParamValues()
{
$this->router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do');
$this->assertEquals(array(
'target' => 'usersController#doAction',
'params' => array(
'id' => 1,
'action' => 'delete'
),
'name' => 'users_do'
), $this->router->match('/users/1/delete', 'POST'));
$this->assertFalse($this->router->match('/users/1/delete', 'GET'));
$this->assertFalse($this->router->match('/users/abc/delete', 'POST'));
$this->assertFalse($this->router->match('/users/1/create', 'GET'));
}
public function testMatchWithServerVars()
{
$this->router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route');
$_SERVER['REQUEST_URI'] = '/foo/test/do';
$_SERVER['REQUEST_METHOD'] = 'GET';
$this->assertEquals(array(
'target' => 'foo_action',
'params' => array(
'controller' => 'test',
'action' => 'do'
),
'name' => 'foo_route'
), $this->router->match());
}
public function testMatchWithOptionalUrlParts()
{
$this->router->map('GET', '/bar/[:controller]/[:action].[:type]?', 'bar_action', 'bar_route');
$this->assertEquals(array(
'target' => 'bar_action',
'params' => array(
'controller' => 'test',
'action' => 'do',
'type' => 'json'
),
'name' => 'bar_route'
), $this->router->match('/bar/test/do.json', 'GET'));
}
public function testMatchWithWildcard()
{
$this->router->map('GET', '/a', 'foo_action', 'foo_route');
$this->router->map('GET', '*', 'bar_action', 'bar_route');
$this->assertEquals(array(
'target' => 'bar_action',
'params' => array(),
'name' => 'bar_route'
), $this->router->match('/everything', 'GET'));
}
public function testMatchWithCustomRegexp()
{
$this->router->map('GET', '@^/[a-z]*$', 'bar_action', 'bar_route');
$this->assertEquals(array(
'target' => 'bar_action',
'params' => array(),
'name' => 'bar_route'
), $this->router->match('/everything', 'GET'));
$this->assertFalse($this->router->match('/some-other-thing', 'GET'));
}
public function testMatchWithUnicodeRegex()
{
$pattern = '/(?<path>[^';
// Arabic characters
$pattern .= '\x{0600}-\x{06FF}';
$pattern .= '\x{FB50}-\x{FDFD}';
$pattern .= '\x{FE70}-\x{FEFF}';
$pattern .= '\x{0750}-\x{077F}';
// Alphanumeric, /, _, - and space characters
$pattern .= 'a-zA-Z0-9\/_-\s';
// 'ZERO WIDTH NON-JOINER'
$pattern .= '\x{200C}';
$pattern .= ']+)';
$this->router->map('GET', '@' . $pattern, 'unicode_action', 'unicode_route');
$this->assertEquals(array(
'target' => 'unicode_action',
'name' => 'unicode_route',
'params' => array(
'path' => '大家好'
)
), $this->router->match('/大家好', 'GET'));
$this->assertFalse($this->router->match('/﷽‎', 'GET'));
}
/**
* @covers AltoRouter::addMatchTypes
*/
public function testMatchWithCustomNamedRegex()
{
$this->router->addMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));
$this->router->map('GET', '/bar/[cId:customId]', 'bar_action', 'bar_route');
$this->assertEquals(array(
'target' => 'bar_action',
'params' => array(
'customId' => 'AB1',
),
'name' => 'bar_route'
), $this->router->match('/bar/AB1', 'GET'));
$this->assertEquals(array(
'target' => 'bar_action',
'params' => array(
'customId' => 'AB1_0123456789',
),
'name' => 'bar_route'
), $this->router->match('/bar/AB1_0123456789', 'GET'));
$this->assertFalse($this->router->match('/some-other-thing', 'GET'));
}
public function testMatchWithCustomNamedUnicodeRegex()
{
$pattern = '[^';
// Arabic characters
$pattern .= '\x{0600}-\x{06FF}';
$pattern .= '\x{FB50}-\x{FDFD}';
$pattern .= '\x{FE70}-\x{FEFF}';
$pattern .= '\x{0750}-\x{077F}';
$pattern .= ']+';
$this->router->addMatchTypes(array('nonArabic' => $pattern));
$this->router->map('GET', '/bar/[nonArabic:string]', 'non_arabic_action', 'non_arabic_route');
$this->assertEquals(array(
'target' => 'non_arabic_action',
'name' => 'non_arabic_route',
'params' => array(
'string' => 'some-path'
)
), $this->router->match('/bar/some-path', 'GET'));
$this->assertFalse($this->router->match('/﷽‎', 'GET'));
}
}

@ -0,0 +1,92 @@
# AltoRouter [![Build Status](https://api.travis-ci.org/dannyvankooten/AltoRouter.png)](http://travis-ci.org/dannyvankooten/AltoRouter)
AltoRouter is a small but powerful routing class for PHP 5.3+, heavily inspired by [klein.php](https://github.com/chriso/klein.php/).
* Dynamic routing with named parameters
* Reversed routing
* Flexible regular expression routing (inspired by [Sinatra](http://www.sinatrarb.com/))
* Custom regexes
## Getting started
1. PHP 5.3.x is required
2. Install AltoRouter using Composer or manually
2. Setup URL rewriting so that all requests are handled by **index.php**
3. Create an instance of AltoRouter, map your routes and match a request.
4. Have a look at the basic example in the `examples` directory for a better understanding on how to use AltoRouter.
## Routing
```php
$router = new AltoRouter();
$router->setBasePath('/AltoRouter'); // (optional) the subdir AltoRouter lives in
// mapping routes
$router->map('GET|POST','/', 'home#index', 'home');
$router->map('GET','/users', array('c' => 'UserController', 'a' => 'ListAction'));
$router->map('GET','/users/[i:id]', 'users#show', 'users_show');
$router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do');
// reversed routing
$router->generate('users_show', array('id' => 5));
```
**You can use the following limits on your named parameters. AltoRouter will create the correct regexes for you.**
```php
* // Match all request URIs
[i] // Match an integer
[i:id] // Match an integer as 'id'
[a:action] // Match alphanumeric characters as 'action'
[h:key] // Match hexadecimal characters as 'key'
[:action] // Match anything up to the next / or end of the URI as 'action'
[create|edit:action] // Match either 'create' or 'edit' as 'action'
[*] // Catch all (lazy, stops at the next trailing slash)
[*:trailing] // Catch all as 'trailing' (lazy)
[**:trailing] // Catch all (possessive - will match the rest of the URI)
.[:format]? // Match an optional parameter 'format' - a / or . before the block is also optional
```
**Some more complicated examples**
```php
@/(?[A-Za-z]{2}_[A-Za-z]{2})$ // custom regex, matches language codes like "en_us" etc.
/posts/[*:title][i:id] // Matches "/posts/this-is-a-title-123"
/output.[xml|json:format]? // Matches "/output", "output.xml", "output.json"
/[:controller]?/[:action]? // Matches the typical /controller/action format
```
**The character before the colon (the 'match type') is a shortcut for one of the following regular expressions**
```php
'i' => '[0-9]++'
'a' => '[0-9A-Za-z]++'
'h' => '[0-9A-Fa-f]++'
'*' => '.+?'
'**' => '.++'
'' => '[^/\.]++'
```
**New match types can be added using the `addMatchTypes()` method**
```php
$router->addMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));
```
## Contributors
- [Danny van Kooten](https://github.com/dannyvankooten)
- [Koen Punt](https://github.com/koenpunt)
- [John Long](https://github.com/adduc)
- [Niahoo Osef](https://github.com/niahoo)
## License
(MIT License)
Copyright (c) 2012-2013 Danny van Kooten <hi@dannyvankooten.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,28 @@
{
"name": "altorouter/altorouter",
"description": "A lightning fast router for PHP",
"keywords": ["router", "routing", "lightweight"],
"homepage": "https://github.com/dannyvankooten/AltoRouter",
"license": "MIT",
"authors": [
{
"name": "Danny van Kooten",
"email": "dannyvankooten@gmail.com",
"homepage": "http://dannyvankooten.com/"
},
{
"name": "Koen Punt",
"homepage": "https://github.com/koenpunt"
},
{
"name": "niahoo",
"homepage": "https://github.com/niahoo"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"classmap": ["AltoRouter.php"]
}
}

@ -0,0 +1,3 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

@ -0,0 +1,27 @@
<?php
require '../../AltoRouter.php';
$router = new AltoRouter();
$router->setBasePath('/AltoRouter/examples/basic');
$router->map('GET|POST','/', 'home#index', 'home');
$router->map('GET','/users/', array('c' => 'UserController', 'a' => 'ListAction'));
$router->map('GET','/users/[i:id]', 'users#show', 'users_show');
$router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do');
// match current request
$match = $router->match();
?>
<h1>AltoRouter</h1>
<h3>Current request: </h3>
<pre>
Target: <?php var_dump($match['target']); ?>
Params: <?php var_dump($match['params']); ?>
Name: <?php var_dump($match['name']); ?>
</pre>
<h3>Try these requests: </h3>
<p><a href="<?php echo $router->generate('home'); ?>">GET <?php echo $router->generate('home'); ?></a></p>
<p><a href="<?php echo $router->generate('users_show', array('id' => 5)); ?>">GET <?php echo $router->generate('users_show', array('id' => 5)); ?></a></p>
<p><form action="<?php echo $router->generate('users_do', array('id' => 10, 'action' => 'update')); ?>" method="post"><button type="submit"><?php echo $router->generate('users_do', array('id' => 10, 'action' => 'update')); ?></button></form></p>

@ -6,6 +6,7 @@ $vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'AltoRouter' => $vendorDir . '/altorouter/altorouter/AltoRouter.php',
'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php', 'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'PHPUnit\\Event\\Application\\Finished' => $vendorDir . '/phpunit/phpunit/src/Event/Events/Application/Finished.php', 'PHPUnit\\Event\\Application\\Finished' => $vendorDir . '/phpunit/phpunit/src/Event/Events/Application/Finished.php',

@ -12,19 +12,30 @@ return array(
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
'Stub\\' => array($baseDir . '/src/data/stub', $baseDir . '/src/data/stub/service', $baseDir . '/src/data/stub/repository'), 'Stub\\' => array($baseDir . '/src/data/stub', $baseDir . '/src/data/stub/service', $baseDir . '/src/data/stub/repository'),
'Shared\\Exception\\' => array($baseDir . '/src/shared/exception'),
'Shared\\' => array($baseDir . '/src/shared'),
'Repository\\' => array($baseDir . '/src/data/model/repository'), 'Repository\\' => array($baseDir . '/src/data/model/repository'),
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'),
'Network\\' => array($baseDir . '/src/data/core/network'), 'Network\\' => array($baseDir . '/src/data/core/network'),
'Model\\' => array($baseDir . '/src/data/model'), 'Model\\' => array($baseDir . '/src/data/model'),
'Manager\\' => array($baseDir . '/src/data/model/manager'), 'Manager\\' => array($baseDir . '/src/data/model/manager'),
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
'Data\\' => array($baseDir . '/src/data'),
'Shared\\Exception\\' => array($baseDir . '/src/shared/exception'),
'Shared\\Attributes\\' => array($baseDir . '/src/shared/attributes'),
'Shared\\' => array($baseDir . '/src/shared'),
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'),
'Hearttrack\\' => array($baseDir . '/src'), 'Hearttrack\\' => array($baseDir . '/src'),
'GrahamCampbell\\ResultType\\' => array($vendorDir . '/graham-campbell/result-type/src'), 'GrahamCampbell\\ResultType\\' => array($vendorDir . '/graham-campbell/result-type/src'),
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'), 'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'), 'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),
'Data\\' => array($baseDir . '/src/data'), 'Data\\Core\\' => array($baseDir . '/src/data/core'),
'Console\\' => array($baseDir . '/src/console'), 'Console\\' => array($baseDir . '/src/console'),
'App\\Views\\Directives\\' => array($baseDir . '/src/app/views/directives'),
'App\\Router\\Response\\' => array($baseDir . '/src/app/router/response'),
'App\\Router\\Request\\' => array($baseDir . '/src/app/router/request'),
'App\\Router\\Middleware\\' => array($baseDir . '/src/app/router/middleware'),
'App\\Router\\' => array($baseDir . '/src/app/router'),
'App\\Controller\\' => array($baseDir . '/src/app/controller'),
'App\\' => array($baseDir . '/src/app'), 'App\\' => array($baseDir . '/src/app'),
); );

@ -30,6 +30,7 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
'Symfony\\Polyfill\\Ctype\\' => 23, 'Symfony\\Polyfill\\Ctype\\' => 23,
'Stub\\' => 5, 'Stub\\' => 5,
'Shared\\Exception\\' => 17, 'Shared\\Exception\\' => 17,
'Shared\\Attributes\\' => 18,
'Shared\\' => 7, 'Shared\\' => 7,
), ),
'R' => 'R' =>
@ -38,6 +39,7 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
), ),
'P' => 'P' =>
array ( array (
'Psr\\Container\\' => 14,
'PhpParser\\' => 10, 'PhpParser\\' => 10,
'PhpOption\\' => 10, 'PhpOption\\' => 10,
), ),
@ -61,8 +63,10 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
'D' => 'D' =>
array ( array (
'Dotenv\\' => 7, 'Dotenv\\' => 7,
'DeepCopy\\' => 9,
'Data\\' => 5, 'Data\\' => 5,
'Doctrine\\Instantiator\\' => 22,
'DeepCopy\\' => 9,
'Data\\Core\\' => 10,
), ),
'C' => 'C' =>
array ( array (
@ -70,6 +74,12 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
), ),
'A' => 'A' =>
array ( array (
'App\\Views\\Directives\\' => 21,
'App\\Router\\Response\\' => 20,
'App\\Router\\Request\\' => 19,
'App\\Router\\Middleware\\' => 22,
'App\\Router\\' => 11,
'App\\Controller\\' => 15,
'App\\' => 4, 'App\\' => 4,
), ),
); );
@ -105,6 +115,10 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
0 => __DIR__ . '/../..' . '/src/shared/exception', 0 => __DIR__ . '/../..' . '/src/shared/exception',
), ),
'Shared\\Attributes\\' =>
array (
0 => __DIR__ . '/../..' . '/src/shared/attributes',
),
'Shared\\' => 'Shared\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/src/shared', 0 => __DIR__ . '/../..' . '/src/shared',
@ -113,6 +127,10 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
0 => __DIR__ . '/../..' . '/src/data/model/repository', 0 => __DIR__ . '/../..' . '/src/data/model/repository',
), ),
'Psr\\Container\\' =>
array (
0 => __DIR__ . '/..' . '/psr/container/src',
),
'PhpParser\\' => 'PhpParser\\' =>
array ( array (
0 => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser', 0 => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser',
@ -145,6 +163,14 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
0 => __DIR__ . '/..' . '/vlucas/phpdotenv/src', 0 => __DIR__ . '/..' . '/vlucas/phpdotenv/src',
), ),
'Doctrine\\Instantiator\\' =>
array (
0 => __DIR__ . '/..' . '/graham-campbell/result-type/src',
),
'Dotenv\\' =>
array (
0 => __DIR__ . '/..' . '/vlucas/phpdotenv/src',
),
'DeepCopy\\' => 'DeepCopy\\' =>
array ( array (
0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy', 0 => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy',
@ -153,10 +179,38 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
array ( array (
0 => __DIR__ . '/../..' . '/src/data', 0 => __DIR__ . '/../..' . '/src/data',
), ),
'Data\\Core\\' =>
array (
0 => __DIR__ . '/../..' . '/src/data/core',
),
'Console\\' => 'Console\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/src/console', 0 => __DIR__ . '/../..' . '/src/console',
), ),
'App\\Views\\Directives\\' =>
array (
0 => __DIR__ . '/../..' . '/src/app/views/directives',
),
'App\\Router\\Response\\' =>
array (
0 => __DIR__ . '/../..' . '/src/app/router/response',
),
'App\\Router\\Request\\' =>
array (
0 => __DIR__ . '/../..' . '/src/app/router/request',
),
'App\\Router\\Middleware\\' =>
array (
0 => __DIR__ . '/../..' . '/src/app/router/middleware',
),
'App\\Router\\' =>
array (
0 => __DIR__ . '/../..' . '/src/app/router',
),
'App\\Controller\\' =>
array (
0 => __DIR__ . '/../..' . '/src/app/controller',
),
'App\\' => 'App\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/src/app', 0 => __DIR__ . '/../..' . '/src/app',
@ -164,6 +218,7 @@ class ComposerStaticInitb084bad56d99d613841073027e5f5e7e
); );
public static $classMap = array ( public static $classMap = array (
'AltoRouter' => __DIR__ . '/..' . '/altorouter/altorouter/AltoRouter.php',
'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php', 'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'PHPUnit\\Event\\Application\\Finished' => __DIR__ . '/..' . '/phpunit/phpunit/src/Event/Events/Application/Finished.php', 'PHPUnit\\Event\\Application\\Finished' => __DIR__ . '/..' . '/phpunit/phpunit/src/Event/Events/Application/Finished.php',

@ -4,6 +4,67 @@
"name": "adriangibbons/php-fit-file-analysis", "name": "adriangibbons/php-fit-file-analysis",
"version": "v3.2.4", "version": "v3.2.4",
"version_normalized": "3.2.4.0", "version_normalized": "3.2.4.0",
"name": "altorouter/altorouter",
"version": "v1.1.0",
"version_normalized": "1.1.0.0",
"source": {
"type": "git",
"url": "https://github.com/dannyvankooten/AltoRouter.git",
"reference": "09d9d946c546bae6d22a7654cdb3b825ffda54b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dannyvankooten/AltoRouter/zipball/09d9d946c546bae6d22a7654cdb3b825ffda54b4",
"reference": "09d9d946c546bae6d22a7654cdb3b825ffda54b4",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-04-16T09:44:40+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"classmap": [
"AltoRouter.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Danny van Kooten",
"email": "dannyvankooten@gmail.com",
"homepage": "http://dannyvankooten.com/"
},
{
"name": "Koen Punt",
"homepage": "https://github.com/koenpunt"
},
{
"name": "niahoo",
"homepage": "https://github.com/niahoo"
}
],
"description": "A lightning fast router for PHP",
"homepage": "https://github.com/dannyvankooten/AltoRouter",
"keywords": [
"lightweight",
"router",
"routing"
],
"support": {
"issues": "https://github.com/dannyvankooten/AltoRouter/issues",
"source": "https://github.com/dannyvankooten/AltoRouter/tree/master"
},
"install-path": "../altorouter/altorouter"
},
{
"name": "doctrine/instantiator",
"version": "1.5.0",
"version_normalized": "1.5.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/adriangibbons/php-fit-file-analysis.git", "url": "https://github.com/adriangibbons/php-fit-file-analysis.git",
@ -106,6 +167,71 @@
], ],
"install-path": "../graham-campbell/result-type" "install-path": "../graham-campbell/result-type"
}, },
{
"name": "graham-campbell/result-type",
"version": "v1.1.2",
"version_normalized": "1.1.2.0",
"source": {
"type": "git",
"url": "https://github.com/GrahamCampbell/Result-Type.git",
"reference": "fbd48bce38f73f8a4ec8583362e732e4095e5862"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/fbd48bce38f73f8a4ec8583362e732e4095e5862",
"reference": "fbd48bce38f73f8a4ec8583362e732e4095e5862",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0",
"phpoption/phpoption": "^1.9.2"
},
"require-dev": {
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
},
"time": "2023-11-12T22:16:48+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"GrahamCampbell\\ResultType\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
}
],
"description": "An Implementation Of The Result Type",
"keywords": [
"Graham Campbell",
"GrahamCampbell",
"Result Type",
"Result-Type",
"result"
],
"support": {
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.2"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
"type": "tidelift"
}
],
"install-path": "../graham-campbell/result-type"
},
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
"version": "1.11.1", "version": "1.11.1",
@ -422,6 +548,84 @@
], ],
"install-path": "../phpoption/phpoption" "install-path": "../phpoption/phpoption"
}, },
{
"name": "phpunit/php-code-coverage",
"version": "9.2.29",
"version_normalized": "9.2.29.0",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/php-option.git",
"reference": "80735db690fe4fc5c76dfa7f9b770634285fa820"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/80735db690fe4fc5c76dfa7f9b770634285fa820",
"reference": "80735db690fe4fc5c76dfa7f9b770634285fa820",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
},
"time": "2023-11-12T21:59:55+00:00",
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
},
"branch-alias": {
"dev-master": "1.9-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"PhpOption\\": "src/PhpOption/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Johannes M. Schmitt",
"email": "schmittjoh@gmail.com",
"homepage": "https://github.com/schmittjoh"
},
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
}
],
"description": "Option Type for PHP",
"keywords": [
"language",
"option",
"php",
"type"
],
"support": {
"issues": "https://github.com/schmittjoh/php-option/issues",
"source": "https://github.com/schmittjoh/php-option/tree/1.9.2"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
"type": "tidelift"
}
],
"install-path": "../phpoption/phpoption"
},
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "10.1.9", "version": "10.1.9",
@ -862,6 +1066,62 @@
], ],
"install-path": "../phpunit/phpunit" "install-path": "../phpunit/phpunit"
}, },
{
"name": "psr/container",
"version": "2.0.2",
"version_normalized": "2.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963",
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
},
"time": "2021-11-05T16:47:00+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/2.0.2"
},
"install-path": "../psr/container"
},
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",
"version": "2.0.0", "version": "2.0.0",

@ -3,7 +3,7 @@
'name' => 'hearttrack/package', 'name' => 'hearttrack/package',
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => '15e854a5088c3bd09feb895db7d604abde12b229', 'reference' => '79311b1041e6dc02c8f58f9bc46bc20ba368ed58',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -18,6 +18,32 @@
'install_path' => __DIR__ . '/../adriangibbons/php-fit-file-analysis', 'install_path' => __DIR__ . '/../adriangibbons/php-fit-file-analysis',
'aliases' => array(), 'aliases' => array(),
'dev_requirement' => false, 'dev_requirement' => false,
'altorouter/altorouter' => array(
'pretty_version' => 'v1.1.0',
'version' => '1.1.0.0',
'reference' => '09d9d946c546bae6d22a7654cdb3b825ffda54b4',
'type' => 'library',
'install_path' => __DIR__ . '/../altorouter/altorouter',
'aliases' => array(),
'dev_requirement' => false,
),
'doctrine/instantiator' => array(
'pretty_version' => '1.5.0',
'version' => '1.5.0.0',
'reference' => '0a0fa9780f5d4e507415a065172d26a98d02047b',
'type' => 'library',
'install_path' => __DIR__ . '/../adriangibbons/php-fit-file-analysis',
'aliases' => array(),
'dev_requirement' => false,
),
'graham-campbell/result-type' => array(
'pretty_version' => 'v1.1.2',
'version' => '1.1.2.0',
'reference' => 'fbd48bce38f73f8a4ec8583362e732e4095e5862',
'type' => 'library',
'install_path' => __DIR__ . '/../graham-campbell/result-type',
'aliases' => array(),
'dev_requirement' => false,
), ),
'graham-campbell/result-type' => array( 'graham-campbell/result-type' => array(
'pretty_version' => 'v1.1.2', 'pretty_version' => 'v1.1.2',
@ -31,7 +57,7 @@
'hearttrack/package' => array( 'hearttrack/package' => array(
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => '15e854a5088c3bd09feb895db7d604abde12b229', 'reference' => '79311b1041e6dc02c8f58f9bc46bc20ba368ed58',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -136,6 +162,15 @@
'aliases' => array(), 'aliases' => array(),
'dev_requirement' => true, 'dev_requirement' => true,
), ),
'psr/container' => array(
'pretty_version' => '2.0.2',
'version' => '2.0.2.0',
'reference' => 'c71ecc56dfe541dbd90c5360474fbc405f8d5963',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/container',
'aliases' => array(),
'dev_requirement' => false,
),
'sebastian/cli-parser' => array( 'sebastian/cli-parser' => array(
'pretty_version' => '2.0.0', 'pretty_version' => '2.0.0',
'version' => '2.0.0.0', 'version' => '2.0.0.0',

@ -4,8 +4,8 @@
$issues = array(); $issues = array();
if (!(PHP_VERSION_ID >= 70205)) { if (!(PHP_VERSION_ID >= 70400)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.5". You are running ' . PHP_VERSION . '.'; $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0". You are running ' . PHP_VERSION . '.';
} }
if ($issues) { if ($issues) {

@ -0,0 +1,3 @@
composer.lock
composer.phar
/vendor/

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013-2016 container-interop
Copyright (c) 2016 PHP Framework Interoperability Group
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,13 @@
Container interface
==============
This repository holds all interfaces related to [PSR-11 (Container Interface)][psr-url].
Note that this is not a Container implementation of its own. It is merely abstractions that describe the components of a Dependency Injection Container.
The installable [package][package-url] and [implementations][implementation-url] are listed on Packagist.
[psr-url]: https://www.php-fig.org/psr/psr-11/
[package-url]: https://packagist.org/packages/psr/container
[implementation-url]: https://packagist.org/providers/psr/container-implementation

@ -0,0 +1,27 @@
{
"name": "psr/container",
"type": "library",
"description": "Common Container Interface (PHP FIG PSR-11)",
"keywords": ["psr", "psr-11", "container", "container-interop", "container-interface"],
"homepage": "https://github.com/php-fig/container",
"license": "MIT",
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"require": {
"php": ">=7.4.0"
},
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}

@ -0,0 +1,12 @@
<?php
namespace Psr\Container;
use Throwable;
/**
* Base interface representing a generic exception in a container.
*/
interface ContainerExceptionInterface extends Throwable
{
}

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Psr\Container;
/**
* Describes the interface of a container that exposes methods to read its entries.
*/
interface ContainerInterface
{
/**
* Finds an entry of the container by its identifier and returns it.
*
* @param string $id Identifier of the entry to look for.
*
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @throws ContainerExceptionInterface Error while retrieving the entry.
*
* @return mixed Entry.
*/
public function get(string $id);
/**
* Returns true if the container can return an entry for the given identifier.
* Returns false otherwise.
*
* `has($id)` returning true does not mean that `get($id)` will not throw an exception.
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
*
* @param string $id Identifier of the entry to look for.
*
* @return bool
*/
public function has(string $id): bool;
}

@ -0,0 +1,10 @@
<?php
namespace Psr\Container;
/**
* No entry was found in the container.
*/
interface NotFoundExceptionInterface extends ContainerExceptionInterface
{
}
Loading…
Cancel
Save