Merge pull request 'feature/Connection' (#6) from feature/Connection into master
Reviewed-on: #6master
commit
b6a46d2f5f
@ -1,14 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MessDetectorOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCSFixerOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpIncludePathManager">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/vendor/composer" />
|
||||
<path value="$PROJECT_DIR$/vendor/twig/twig" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
|
||||
<path value="$PROJECT_DIR$/mvc_PSR4_twig/vendor/symfony/polyfill-mbstring" />
|
||||
<path value="$PROJECT_DIR$/mvc_PSR4_twig/vendor/symfony/polyfill-ctype" />
|
||||
<path value="$PROJECT_DIR$/mvc_PSR4_twig/vendor/composer" />
|
||||
<path value="$PROJECT_DIR$/mvc_PSR4_twig/vendor/twig/twig" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.0">
|
||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||
</component>
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/fluxRSS/DAL/ArticleGateway.php" dialect="PostgreSQL" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,3 @@
|
||||
RewriteEngine on
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule . index.php [L]
|
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/mvc_PSR4_twig.iml" filepath="$PROJECT_DIR$/.idea/mvc_PSR4_twig.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/config" isTestSource="false" packagePrefix="config\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/controleur" isTestSource="false" packagePrefix="controleur\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/metier" isTestSource="false" packagePrefix="modeles\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/twig/twig" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpIncludePathManager">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/vendor/composer" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
|
||||
<path value="$PROJECT_DIR$/vendor/twig/twig" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.0">
|
||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,304 @@
|
||||
<?php
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2012 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.
|
||||
*/
|
||||
|
||||
namespace vendor;
|
||||
|
||||
class AltoRouter
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array Array of all routes (incl. named routes).
|
||||
*/
|
||||
protected $routes = [];
|
||||
|
||||
/**
|
||||
* @var array Array of all named routes.
|
||||
*/
|
||||
protected $namedRoutes = [];
|
||||
|
||||
/**
|
||||
* @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host)
|
||||
*/
|
||||
protected $basePath = '';
|
||||
|
||||
/**
|
||||
* @var array Array of default match types (regex helpers)
|
||||
*/
|
||||
protected $matchTypes = [
|
||||
'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
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(array $routes = [], $basePath = '', array $matchTypes = [])
|
||||
{
|
||||
$this->addRoutes($routes);
|
||||
$this->setBasePath($basePath);
|
||||
$this->addMatchTypes($matchTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all routes.
|
||||
* Useful if you want to process or display routes.
|
||||
* @return array All routes.
|
||||
*/
|
||||
public function getRoutes()
|
||||
{
|
||||
return $this->routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add multiple routes at once from array in the following format:
|
||||
*
|
||||
* $routes = [
|
||||
* [$method, $route, $target, $name]
|
||||
* ];
|
||||
*
|
||||
* @param array $routes
|
||||
* @return void
|
||||
* @author Koen Punt
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addRoutes($routes)
|
||||
{
|
||||
if (!is_array($routes) && !$routes instanceof Traversable) {
|
||||
throw new RuntimeException('Routes should be an array or an instance of Traversable');
|
||||
}
|
||||
foreach ($routes as $route) {
|
||||
call_user_func_array([$this, 'map'], $route);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base path.
|
||||
* Useful if you are running your application from a subdirectory.
|
||||
* @param string $basePath
|
||||
*/
|
||||
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(array $matchTypes)
|
||||
{
|
||||
$this->matchTypes = array_merge($this->matchTypes, $matchTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a route to a target
|
||||
*
|
||||
* @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|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.
|
||||
* @throws Exception
|
||||
*/
|
||||
public function map($method, $route, $target, $name = null)
|
||||
{
|
||||
|
||||
$this->routes[] = [$method, $route, $target, $name];
|
||||
|
||||
if ($name) {
|
||||
if (isset($this->namedRoutes[$name])) {
|
||||
throw new RuntimeException("Can not redeclare route '{$name}'");
|
||||
}
|
||||
$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.
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generate($routeName, array $params = [])
|
||||
{
|
||||
|
||||
// Check if named route exists
|
||||
if (!isset($this->namedRoutes[$routeName])) {
|
||||
throw new RuntimeException("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 $index => $match) {
|
||||
list($block, $pre, $type, $param, $optional) = $match;
|
||||
|
||||
if ($pre) {
|
||||
$block = substr($block, 1);
|
||||
}
|
||||
|
||||
if (isset($params[$param])) {
|
||||
// Part is found, replace for param value
|
||||
$url = str_replace($block, $params[$param], $url);
|
||||
} elseif ($optional && $index !== 0) {
|
||||
// Only strip preceding slash if it's not at the base
|
||||
$url = str_replace($pre . $block, '', $url);
|
||||
} else {
|
||||
// Strip match block
|
||||
$url = str_replace($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 = [];
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
$lastRequestUrlChar = $requestUrl ? $requestUrl[strlen($requestUrl)-1] : '';
|
||||
|
||||
// set Request Method if it isn't passed as a parameter
|
||||
if ($requestMethod === null) {
|
||||
$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
|
||||
}
|
||||
|
||||
foreach ($this->routes as $handler) {
|
||||
list($methods, $route, $target, $name) = $handler;
|
||||
|
||||
$method_match = (stripos($methods, $requestMethod) !== false);
|
||||
|
||||
// Method did not match, continue to next route.
|
||||
if (!$method_match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($route === '*') {
|
||||
// * wildcard (matches all)
|
||||
$match = true;
|
||||
} elseif (isset($route[0]) && $route[0] === '@') {
|
||||
// @ regex delimiter
|
||||
$pattern = '`' . substr($route, 1) . '`u';
|
||||
$match = preg_match($pattern, $requestUrl, $params) === 1;
|
||||
} elseif (($position = strpos($route, '[')) === false) {
|
||||
// No params in url, do string comparison
|
||||
$match = strcmp($requestUrl, $route) === 0;
|
||||
} else {
|
||||
// Compare longest non-param string with url before moving on to regex
|
||||
// Check if last character before param is a slash, because it could be optional if param is optional too (see https://github.com/dannyvankooten/AltoRouter/issues/241)
|
||||
if (strncmp($requestUrl, $route, $position) !== 0 && ($lastRequestUrlChar === '/' || $route[$position-1] !== '/')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$regex = $this->compileRoute($route);
|
||||
$match = preg_match($regex, $requestUrl, $params) === 1;
|
||||
}
|
||||
|
||||
if ($match) {
|
||||
if ($params) {
|
||||
foreach ($params as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'target' => $target,
|
||||
'params' => $params,
|
||||
'name' => $name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the regex for a given route (EXPENSIVE)
|
||||
* @param $route
|
||||
* @return string
|
||||
*/
|
||||
protected 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 = '\.';
|
||||
}
|
||||
|
||||
$optional = $optional !== '' ? '?' : null;
|
||||
|
||||
//Older versions of PCRE require the 'P' in (?P<named>)
|
||||
$pattern = '(?:'
|
||||
. ($pre !== '' ? $pre : null)
|
||||
. '('
|
||||
. ($param !== '' ? "?P<$param>" : null)
|
||||
. $type
|
||||
. ')'
|
||||
. $optional
|
||||
. ')'
|
||||
. $optional;
|
||||
|
||||
$route = str_replace($block, $pattern, $route);
|
||||
}
|
||||
}
|
||||
return "`^$route$`u";
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace DAL;
|
||||
|
||||
use PDO;
|
||||
|
||||
class AdminGateway
|
||||
{
|
||||
private $con;
|
||||
|
||||
/**
|
||||
* @param $con
|
||||
*/
|
||||
public function __construct($con)
|
||||
{
|
||||
$this->con = $con;
|
||||
}
|
||||
|
||||
public function login(string $login):array
|
||||
{
|
||||
try{
|
||||
$query = 'SELECT password,mail FROM Admin WHERE name = :login;';
|
||||
$this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR)));
|
||||
return $this->con->getResults();
|
||||
}catch (\PDOException $e){
|
||||
throw new \Exception("PDO error");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace DAL;
|
||||
|
||||
use Exception;
|
||||
use metier\Article;
|
||||
use PDO;
|
||||
class ArticleGateway
|
||||
{
|
||||
private $con;
|
||||
|
||||
/**
|
||||
* @param $con
|
||||
*/
|
||||
public function __construct($con)
|
||||
{
|
||||
$this->con = $con;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAllArticles():array
|
||||
{
|
||||
try {
|
||||
$query = 'SELECT * FROM Article;';
|
||||
$this->con->executeQuery($query, array());
|
||||
return $this->con->getResults();
|
||||
}catch (\PDOException $e){
|
||||
throw new Exception("PDO error");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addArticle(Article $article){
|
||||
try {
|
||||
$query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);';
|
||||
$this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR),
|
||||
':title' => array($article->getTitle(), PDO::PARAM_STR),
|
||||
':date' => array($article->getDate(), PDO::PARAM_STR),
|
||||
':description' => array($article->getDescription(), PDO::PARAM_STR),
|
||||
':guid' => array($article->getGuid(), PDO::PARAM_STR),
|
||||
':link' => array($article->getLink(), PDO::PARAM_STR),
|
||||
':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR),
|
||||
':provenance' => array($article->getProvenance(), PDO::PARAM_INT)));
|
||||
}catch (\PDOException $e){
|
||||
throw new Exception("PDO error");
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAllArticleForParser(){
|
||||
try{
|
||||
$query = 'DELETE FROM Article;';
|
||||
$this->con->executeQuery($query);
|
||||
}catch(\PDOException $p){
|
||||
throw new Exception("Data is not delete.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace DAL;
|
||||
|
||||
use Exception;
|
||||
use PDO;
|
||||
use Twig\Error\Error;
|
||||
|
||||
class Connection extends PDO
|
||||
{
|
||||
private $stmt; // pas typé, car peut être faux ou statement
|
||||
|
||||
/**
|
||||
* @param string $dsn
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(string $dsn, string $username, string $password)
|
||||
{
|
||||
try{
|
||||
parent::__construct($dsn, $username, $password);
|
||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
}catch (\PDOException $e){
|
||||
throw new Exception("PDO error con");
|
||||
}
|
||||
catch (Error $e){
|
||||
throw new Error("Error PDO");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query to execute
|
||||
* @param array $parameters to bind
|
||||
* @return bool Returns `true` on success, `false` otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
public function executeQuery(string $query, array $parameters = []): bool
|
||||
{
|
||||
try{
|
||||
$this->stmt = parent::prepare($query);
|
||||
foreach ($parameters as $name => $value) {
|
||||
$this->stmt->bindValue($name, $value[0], $value[1]);
|
||||
}
|
||||
|
||||
return $this->stmt->execute();
|
||||
}catch (\PDOException $e){
|
||||
throw new Exception("PDO error");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getResults(): array
|
||||
{
|
||||
return $this->stmt->fetchall();
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace DAL;
|
||||
|
||||
use metier\Flux;
|
||||
use PDO;
|
||||
|
||||
class FluxGateway
|
||||
{
|
||||
private Connection $con;
|
||||
|
||||
public function __construct(Connection $con){
|
||||
$this->con = $con;
|
||||
}
|
||||
|
||||
public function addFlux($flux){
|
||||
try{
|
||||
$query = 'INSERT INTO Flux VALUES (:flux);';
|
||||
$this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR)));
|
||||
}catch (\PDOException $e){
|
||||
throw new \Exception("PDO error");
|
||||
}
|
||||
}
|
||||
|
||||
public function removeFlux($flux){
|
||||
try{
|
||||
$query = 'DELETE FROM Flux WHERE flux = :flux;';
|
||||
$this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR)));
|
||||
}catch (\PDOException $e){
|
||||
throw new \Exception("PDO error");
|
||||
}
|
||||
}
|
||||
|
||||
public function findAllFlux(){
|
||||
try{
|
||||
$query = 'SELECT * FROM Flux;';
|
||||
$this->con->executeQuery($query);
|
||||
return $this->con->getResults();
|
||||
}catch (\PDOException $e){
|
||||
throw new \Exception("PDO error");
|
||||
}
|
||||
}
|
||||
|
||||
public function findFlux(Flux $flux){
|
||||
return $this->findFluxBySrc($flux->getFlux());
|
||||
}
|
||||
|
||||
public function findFluxBySrc(string $flux){
|
||||
try{
|
||||
$query = 'SELECT * FROM Flux WHERE flux = :flux;';
|
||||
$this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR)));
|
||||
return $this->con->getResults();
|
||||
}catch (\PDOException $e){
|
||||
throw new \Exception("PDO error");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"require": {
|
||||
"twig/twig": "^3.0",
|
||||
"ext-pdo": "*",
|
||||
"ext-dom": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"controleur\\": "controleur/",
|
||||
"config\\": "config/",
|
||||
"model\\": "model/",
|
||||
"DAL\\": "DAL/",
|
||||
"metier\\": "metier/"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,258 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "03e1f7c6d7574f3683225067dbb2becc",
|
||||
"packages": [
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.28.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
"reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb",
|
||||
"reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.28-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"ctype",
|
||||
"polyfill",
|
||||
"portable"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2023-01-26T09:26:14+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.28.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "42292d99c55abe617799667f454222c54c60e229"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229",
|
||||
"reference": "42292d99c55abe617799667f454222c54c60e229",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.28-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2023-07-28T09:04:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v3.7.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/a0ce373a0ca3bf6c64b9e3e2124aca502ba39554",
|
||||
"reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"symfony/polyfill-ctype": "^1.8",
|
||||
"symfony/polyfill-mbstring": "^1.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"psr/container": "^1.0|^2.0",
|
||||
"symfony/phpunit-bridge": "^5.4.9|^6.3"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Twig\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com",
|
||||
"homepage": "http://fabien.potencier.org",
|
||||
"role": "Lead Developer"
|
||||
},
|
||||
{
|
||||
"name": "Twig Team",
|
||||
"role": "Contributors"
|
||||
},
|
||||
{
|
||||
"name": "Armin Ronacher",
|
||||
"email": "armin.ronacher@active-4.com",
|
||||
"role": "Project Founder"
|
||||
}
|
||||
],
|
||||
"description": "Twig, the flexible, fast, and secure template language for PHP",
|
||||
"homepage": "https://twig.symfony.com",
|
||||
"keywords": [
|
||||
"templating"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/twigphp/Twig/issues",
|
||||
"source": "https://github.com/twigphp/Twig/tree/v3.7.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/twig/twig",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2023-08-28T11:09:02+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"ext-pdo": "*",
|
||||
"ext-dom": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
@ -1,34 +1,34 @@
|
||||
<?php
|
||||
namespace config;
|
||||
|
||||
class Validation
|
||||
{
|
||||
public static function val_action($action)
|
||||
{
|
||||
if (!isset($action)) {
|
||||
throw new \Exception('pas d\'action');
|
||||
//on pourrait aussi utiliser
|
||||
//$action = $_GET['action'] ?? 'no';
|
||||
// This is equivalent to:
|
||||
//$action = if (isset($_GET['action'])) $action=$_GET['action'] else $action='no';
|
||||
}
|
||||
}
|
||||
|
||||
public static function val_form(string &$nom, string &$age, &$dVueEreur)
|
||||
{
|
||||
if (!isset($nom) || $nom == '') {
|
||||
$dVueEreur[] = 'pas de nom';
|
||||
$nom = '';
|
||||
}
|
||||
|
||||
if ( strlen(htmlspecialchars($nom, ENT_QUOTES)) != strlen($nom) ) {
|
||||
$dVueEreur[] = "testative d'injection de code (attaque sécurité)";
|
||||
$nom = '';
|
||||
}
|
||||
|
||||
if (!isset($age) || $age == '' || !filter_var($age, FILTER_VALIDATE_INT)) {
|
||||
$dVueEreur[] = "pas d'age ";
|
||||
$age = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
namespace config;
|
||||
|
||||
class Validation
|
||||
{
|
||||
public static function val_action($action)
|
||||
{
|
||||
if (!isset($action)) {
|
||||
throw new \Exception('pas d\'action');
|
||||
//on pourrait aussi utiliser
|
||||
//$action = $_GET['action'] ?? 'no';
|
||||
// This is equivalent to:
|
||||
//$action = if (isset($_GET['action'])) $action=$_GET['action'] else $action='no';
|
||||
}
|
||||
}
|
||||
|
||||
public static function val_form(string &$nom, string &$age, &$dVueEreur)
|
||||
{
|
||||
if (!isset($nom) || $nom == '') {
|
||||
$dVueEreur[] = 'pas de nom';
|
||||
$nom = '';
|
||||
}
|
||||
|
||||
if ( strlen(htmlspecialchars($nom, ENT_QUOTES)) != strlen($nom) ) {
|
||||
$dVueEreur[] = "testative d'injection de code (attaque sécurité)";
|
||||
$nom = '';
|
||||
}
|
||||
|
||||
if (!isset($age) || $age == '' || !filter_var($age, FILTER_VALIDATE_INT)) {
|
||||
$dVueEreur[] = "pas d'age ";
|
||||
$age = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,15 @@
|
||||
<?php
|
||||
|
||||
//gen
|
||||
$rep = __DIR__ . '/../';
|
||||
|
||||
// liste des modules à inclure
|
||||
|
||||
//$dConfig['includes']= array('controleur/Validation.php');
|
||||
|
||||
//BD
|
||||
|
||||
$base = 'sasa';
|
||||
$login = '';
|
||||
$mdp = '';
|
||||
<?php
|
||||
|
||||
//gen
|
||||
$rep = __DIR__ . '/../';
|
||||
|
||||
// liste des modules à inclure
|
||||
|
||||
//$dConfig['includes']= array('controleur/Validation.php');
|
||||
|
||||
//BD
|
||||
|
||||
$base = 'dbrorossetto';
|
||||
$login = 'rorossetto';
|
||||
$mdp = 'tpphp';
|
||||
$path = '~mapoint2/public_html/SAE/Php_RSS';
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace controleur;
|
||||
|
||||
use model\AdminModel;
|
||||
use model\ArticleModel;
|
||||
|
||||
class AdminControleur
|
||||
{
|
||||
public function __construct(){
|
||||
global $twig; // nécessaire pour utiliser variables globales
|
||||
//debut
|
||||
|
||||
//on initialise un tableau d'erreur
|
||||
$dVueEreur = [];
|
||||
|
||||
try {
|
||||
$action = $_REQUEST['action'] ?? null;
|
||||
|
||||
switch($action) {
|
||||
//pas d'action, on réinitialise 1er appel
|
||||
case null:
|
||||
$this->connection();
|
||||
break;
|
||||
|
||||
case 'connection':
|
||||
$this->connection();;
|
||||
break;
|
||||
case 'validationFormulaire':
|
||||
$this->ValidationFormulaire($dVueEreur);
|
||||
break;
|
||||
|
||||
case 'listArticle':
|
||||
$this->listArticle();
|
||||
break;
|
||||
//mauvaise action
|
||||
default:
|
||||
$dVueEreur[] = "Erreur d'appel php";
|
||||
echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => AdminModel::isAdmin()]);
|
||||
break;
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
//si erreur BD, pas le cas ici
|
||||
$dVueEreur[] = 'Erreur PDO : ' . $e->getMessage();
|
||||
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
|
||||
} catch (\Exception $e2) {
|
||||
$dVueEreur[] = 'Erreur : ' . $e2->getMessage();
|
||||
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
|
||||
}
|
||||
|
||||
//fin
|
||||
exit(0);
|
||||
}
|
||||
|
||||
public function listArticle()
|
||||
{
|
||||
global $twig;
|
||||
$articleModel = new ArticleModel();
|
||||
$dVue = [
|
||||
'data' => $articleModel->getArticles()
|
||||
];
|
||||
echo $twig->render('listArticle.html', [
|
||||
'dVue' => $dVue,
|
||||
'isAdmin' => AdminModel::isAdmin()
|
||||
]);
|
||||
}
|
||||
|
||||
public function connection(){
|
||||
global $twig; // nécessaire pour utiliser variables globales
|
||||
if (!AdminModel::isAdmin()){
|
||||
$this->listArticle();
|
||||
}
|
||||
else {
|
||||
echo $twig->render('Connection.html');
|
||||
if (isset($_POST['username']) && isset($_POST['password'])) {
|
||||
$this->login();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function login(){
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$adminModel = new AdminModel();
|
||||
$admin = $adminModel->connection($username, $password);
|
||||
|
||||
if ($admin != null) {
|
||||
$this->listArticle();
|
||||
}
|
||||
else{
|
||||
unset($_POST['username']);
|
||||
unset($_POST['passwords']);
|
||||
$this->connection();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace controleur;
|
||||
|
||||
use model\AdminModel;
|
||||
use vendor\AltoRouter;
|
||||
use controleur\UserControleur;
|
||||
use controleur\AdminControleur;
|
||||
require 'AltoRouter.php';
|
||||
|
||||
class FrontControleur
|
||||
{
|
||||
public function __construct(){
|
||||
|
||||
global $twig;
|
||||
$router = new AltoRouter();
|
||||
$router->setBasePath('~mapoint2/SAE/Php_RSS/fluxRSS/');
|
||||
$router->map('GET', '/[a:action]?', 'UserControleur');
|
||||
$router->map('GET|POST','/user/[a:action]?','UserControleur');
|
||||
$router->map('GET|POST','/admin/[a:action]?','AdminControleur');
|
||||
|
||||
$match = $router->match();
|
||||
if (!$match) {
|
||||
$dVueEreur[] = "Page doesn't exist";
|
||||
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
|
||||
}
|
||||
else {
|
||||
session_start();
|
||||
$controller=$match['target'] ?? null;
|
||||
$action=$match['params']['action'] ?? null;
|
||||
try {
|
||||
if($controller == "AdminControleur"){
|
||||
if (!AdminModel::isAdmin()){
|
||||
$action = "connection";
|
||||
}
|
||||
}
|
||||
$controller = '\\controleur\\' . $controller;
|
||||
$controller = new $controller;
|
||||
if (is_callable(array($controller, $action))) {
|
||||
call_user_func_array(array($controller, $action),
|
||||
array($match['params']));
|
||||
}
|
||||
}
|
||||
catch (Error $error){
|
||||
$dVueEreur[] = "Controller doesn't exist";
|
||||
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace controleur;
|
||||
|
||||
use model\AdminModel;
|
||||
use model\ArticleModel;
|
||||
use model\Parser;
|
||||
|
||||
class UserControleur
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
global $twig; // nécessaire pour utiliser variables globales
|
||||
//debut
|
||||
|
||||
//on initialise un tableau d'erreur
|
||||
$dVueEreur = [];
|
||||
|
||||
try {
|
||||
$action = $_REQUEST['action'] ?? null;
|
||||
|
||||
switch($action) {
|
||||
//pas d'action, on réinitialise 1er appel
|
||||
case 'listArticle':
|
||||
case null:
|
||||
$this->listArticle();
|
||||
break;
|
||||
|
||||
case 'connection':
|
||||
$this->connection();;
|
||||
break;
|
||||
case 'validationFormulaire':
|
||||
$this->ValidationFormulaire($dVueEreur);
|
||||
break;
|
||||
|
||||
//mauvaise action
|
||||
default:
|
||||
$dVueEreur[] = "Erreur d'appel php";
|
||||
echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur, 'isAdmin' => AdminModel::isAdmin()]);
|
||||
break;
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
//si erreur BD, pas le cas ici
|
||||
$dVueEreur[] = 'Erreur PDO : ' . $e->getMessage();
|
||||
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
|
||||
} catch (\Exception $e2) {
|
||||
$dVueEreur[] = 'Erreur : ' . $e2->getMessage();
|
||||
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
|
||||
}
|
||||
|
||||
//fin
|
||||
exit(0);
|
||||
}//fin constructeur
|
||||
|
||||
public function listArticle()
|
||||
{
|
||||
global $twig;
|
||||
$articleModel = new ArticleModel();
|
||||
$dVue = [
|
||||
'data' => $articleModel->getArticles()
|
||||
];
|
||||
echo $twig->render('listArticle.html', [
|
||||
'dVue' => $dVue,
|
||||
'isAdmin' => AdminModel::isAdmin()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Twig\Error\RuntimeError
|
||||
* @throws \Twig\Error\SyntaxError
|
||||
* @throws \Twig\Error\LoaderError
|
||||
*/
|
||||
public function connection(){
|
||||
global $twig; // nécessaire pour utiliser variables globales
|
||||
echo $twig->render('Connection.html');
|
||||
if (isset($_POST['username']) && isset($_POST['password'])) {
|
||||
$this->login();
|
||||
}
|
||||
}
|
||||
|
||||
public function login(){
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$adminModel = new AdminModel();
|
||||
$admin = $adminModel->connection($username, $password);
|
||||
|
||||
if ($admin != null) {
|
||||
$this->listArticle();
|
||||
}
|
||||
else{
|
||||
unset($_POST['username']);
|
||||
unset($_POST['passwords']);
|
||||
$this->connection();
|
||||
}
|
||||
}
|
||||
|
||||
public function ValidationFormulaire(array $dVueEreur)
|
||||
{
|
||||
global $twig; // nécessaire pour utiliser variables globales
|
||||
|
||||
//si exception, ca remonte !!!
|
||||
$nom = $_POST['txtNom']; // txtNom = nom du champ texte dans le formulaire
|
||||
$age = $_POST['txtAge'];
|
||||
\config\Validation::val_form($nom, $age, $dVueEreur);
|
||||
|
||||
/*
|
||||
$model = new \metier\Simplemodel();
|
||||
$data = $model->get_data();
|
||||
*/
|
||||
|
||||
$dVue = [
|
||||
'nom' => $nom,
|
||||
'age' => $age,
|
||||
//'data' => $data,
|
||||
];
|
||||
|
||||
echo $twig->render('Connection.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]);
|
||||
}
|
||||
}//fin class
|
@ -0,0 +1,39 @@
|
||||
name: PHP
|
||||
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-versions: [ '7.3', '7.4', '8.0', '8.1' ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
tools: composer
|
||||
|
||||
- name: Validate composer.json and composer.lock
|
||||
run: composer validate
|
||||
|
||||
- name: Get composer cache directory
|
||||
id: composer-cache
|
||||
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: ${{ runner.os }}-composer-
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.composer-cache.outputs.cache-hit != 'true'
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
- name: Run test suite
|
||||
run: composer run-script test
|
@ -0,0 +1,302 @@
|
||||
<?php
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2012 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.
|
||||
*/
|
||||
|
||||
class AltoRouter
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array Array of all routes (incl. named routes).
|
||||
*/
|
||||
protected $routes = [];
|
||||
|
||||
/**
|
||||
* @var array Array of all named routes.
|
||||
*/
|
||||
protected $namedRoutes = [];
|
||||
|
||||
/**
|
||||
* @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host)
|
||||
*/
|
||||
protected $basePath = '';
|
||||
|
||||
/**
|
||||
* @var array Array of default match types (regex helpers)
|
||||
*/
|
||||
protected $matchTypes = [
|
||||
'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
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(array $routes = [], $basePath = '', array $matchTypes = [])
|
||||
{
|
||||
$this->addRoutes($routes);
|
||||
$this->setBasePath($basePath);
|
||||
$this->addMatchTypes($matchTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all routes.
|
||||
* Useful if you want to process or display routes.
|
||||
* @return array All routes.
|
||||
*/
|
||||
public function getRoutes()
|
||||
{
|
||||
return $this->routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add multiple routes at once from array in the following format:
|
||||
*
|
||||
* $routes = [
|
||||
* [$method, $route, $target, $name]
|
||||
* ];
|
||||
*
|
||||
* @param array $routes
|
||||
* @return void
|
||||
* @author Koen Punt
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addRoutes($routes)
|
||||
{
|
||||
if (!is_array($routes) && !$routes instanceof Traversable) {
|
||||
throw new RuntimeException('Routes should be an array or an instance of Traversable');
|
||||
}
|
||||
foreach ($routes as $route) {
|
||||
call_user_func_array([$this, 'map'], $route);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base path.
|
||||
* Useful if you are running your application from a subdirectory.
|
||||
* @param string $basePath
|
||||
*/
|
||||
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(array $matchTypes)
|
||||
{
|
||||
$this->matchTypes = array_merge($this->matchTypes, $matchTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a route to a target
|
||||
*
|
||||
* @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|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.
|
||||
* @throws Exception
|
||||
*/
|
||||
public function map($method, $route, $target, $name = null)
|
||||
{
|
||||
|
||||
$this->routes[] = [$method, $route, $target, $name];
|
||||
|
||||
if ($name) {
|
||||
if (isset($this->namedRoutes[$name])) {
|
||||
throw new RuntimeException("Can not redeclare route '{$name}'");
|
||||
}
|
||||
$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.
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generate($routeName, array $params = [])
|
||||
{
|
||||
|
||||
// Check if named route exists
|
||||
if (!isset($this->namedRoutes[$routeName])) {
|
||||
throw new RuntimeException("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 $index => $match) {
|
||||
list($block, $pre, $type, $param, $optional) = $match;
|
||||
|
||||
if ($pre) {
|
||||
$block = substr($block, 1);
|
||||
}
|
||||
|
||||
if (isset($params[$param])) {
|
||||
// Part is found, replace for param value
|
||||
$url = str_replace($block, $params[$param], $url);
|
||||
} elseif ($optional && $index !== 0) {
|
||||
// Only strip preceding slash if it's not at the base
|
||||
$url = str_replace($pre . $block, '', $url);
|
||||
} else {
|
||||
// Strip match block
|
||||
$url = str_replace($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 = [];
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
$lastRequestUrlChar = $requestUrl ? $requestUrl[strlen($requestUrl)-1] : '';
|
||||
|
||||
// set Request Method if it isn't passed as a parameter
|
||||
if ($requestMethod === null) {
|
||||
$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
|
||||
}
|
||||
|
||||
foreach ($this->routes as $handler) {
|
||||
list($methods, $route, $target, $name) = $handler;
|
||||
|
||||
$method_match = (stripos($methods, $requestMethod) !== false);
|
||||
|
||||
// Method did not match, continue to next route.
|
||||
if (!$method_match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($route === '*') {
|
||||
// * wildcard (matches all)
|
||||
$match = true;
|
||||
} elseif (isset($route[0]) && $route[0] === '@') {
|
||||
// @ regex delimiter
|
||||
$pattern = '`' . substr($route, 1) . '`u';
|
||||
$match = preg_match($pattern, $requestUrl, $params) === 1;
|
||||
} elseif (($position = strpos($route, '[')) === false) {
|
||||
// No params in url, do string comparison
|
||||
$match = strcmp($requestUrl, $route) === 0;
|
||||
} else {
|
||||
// Compare longest non-param string with url before moving on to regex
|
||||
// Check if last character before param is a slash, because it could be optional if param is optional too (see https://github.com/dannyvankooten/AltoRouter/issues/241)
|
||||
if (strncmp($requestUrl, $route, $position) !== 0 && ($lastRequestUrlChar === '/' || $route[$position-1] !== '/')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$regex = $this->compileRoute($route);
|
||||
$match = preg_match($regex, $requestUrl, $params) === 1;
|
||||
}
|
||||
|
||||
if ($match) {
|
||||
if ($params) {
|
||||
foreach ($params as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'target' => $target,
|
||||
'params' => $params,
|
||||
'name' => $name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the regex for a given route (EXPENSIVE)
|
||||
* @param $route
|
||||
* @return string
|
||||
*/
|
||||
protected 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 = '\.';
|
||||
}
|
||||
|
||||
$optional = $optional !== '' ? '?' : null;
|
||||
|
||||
//Older versions of PCRE require the 'P' in (?P<named>)
|
||||
$pattern = '(?:'
|
||||
. ($pre !== '' ? $pre : null)
|
||||
. '('
|
||||
. ($param !== '' ? "?P<$param>" : null)
|
||||
. $type
|
||||
. ')'
|
||||
. $optional
|
||||
. ')'
|
||||
. $optional;
|
||||
|
||||
$route = str_replace($block, $pattern, $route);
|
||||
}
|
||||
}
|
||||
return "`^$route$`u";
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2012 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,57 @@
|
||||
# AltoRouter  [](https://packagist.org/packages/altorouter/altorouter) [](https://packagist.org/packages/altorouter/altorouter)
|
||||
|
||||
AltoRouter is a small but powerful routing class, heavily inspired by [klein.php](https://github.com/chriso/klein.php/).
|
||||
|
||||
```php
|
||||
$router = new AltoRouter();
|
||||
|
||||
// map homepage
|
||||
$router->map('GET', '/', function() {
|
||||
require __DIR__ . '/views/home.php';
|
||||
});
|
||||
|
||||
// dynamic named route
|
||||
$router->map('GET|POST', '/users/[i:id]/', function($id) {
|
||||
$user = .....
|
||||
require __DIR__ . '/views/user/details.php';
|
||||
}, 'user-details');
|
||||
|
||||
// echo URL to user-details page for ID 5
|
||||
echo $router->generate('user-details', ['id' => 5]); // Output: "/users/5"
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
* Can be used with all HTTP Methods
|
||||
* Dynamic routing with named route parameters
|
||||
* Reversed routing
|
||||
* Flexible regular expression routing (inspired by [Sinatra](http://www.sinatrarb.com/))
|
||||
* Custom regexes
|
||||
|
||||
## Getting started
|
||||
|
||||
You need PHP >= 5.6 to use AltoRouter, although we highly recommend you [use an officially supported PHP version](https://secure.php.net/supported-versions.php) that is not EOL.
|
||||
|
||||
- [Install AltoRouter](http://altorouter.com/usage/install.html)
|
||||
- [Rewrite all requests to AltoRouter](http://altorouter.com/usage/rewrite-requests.html)
|
||||
- [Map your routes](http://altorouter.com/usage/mapping-routes.html)
|
||||
- [Match requests](http://altorouter.com/usage/matching-requests.html)
|
||||
- [Process the request your preferred way](http://altorouter.com/usage/processing-requests.html)
|
||||
|
||||
## 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 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,35 @@
|
||||
{
|
||||
"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.6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "9.5.*",
|
||||
"squizlabs/php_codesniffer": "3.6.2"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": ["AltoRouter.php"]
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit"
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="rules">
|
||||
<description>rules</description>
|
||||
<rule ref="PSR2"/>
|
||||
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
|
||||
<file>tests</file>
|
||||
<file>AltoRouter.php</file>
|
||||
<file>examples/</file>
|
||||
<arg name="colors"/>
|
||||
</ruleset>
|
@ -1,16 +1,18 @@
|
||||
<?php
|
||||
|
||||
//chargement config
|
||||
require_once __DIR__ . '/config/config.php';
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use controleur\Controleur;
|
||||
|
||||
//twig
|
||||
$loader = new \Twig\Loader\FilesystemLoader('templates');
|
||||
$twig = new \Twig\Environment($loader, [
|
||||
'cache' => 'cache',
|
||||
]);
|
||||
|
||||
$cont = new Controleur();
|
||||
<?php
|
||||
|
||||
//chargement config
|
||||
require_once __DIR__ . '/config/config.php';
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use controleur\FrontControleur;
|
||||
|
||||
//twig
|
||||
$loader = new \Twig\Loader\FilesystemLoader('templates');
|
||||
$twig = new \Twig\Environment($loader, [
|
||||
'cache' => false,
|
||||
]);
|
||||
|
||||
$cont = new FrontControleur();
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace metier;
|
||||
|
||||
class Admin
|
||||
{
|
||||
private string $username;
|
||||
private string $mail;
|
||||
|
||||
public function __construct($username,$mail){
|
||||
$this->username = $username;
|
||||
$this->mail = $mail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
*/
|
||||
public function setUsername(string $username): void
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMail(): string
|
||||
{
|
||||
return $this->mail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mail
|
||||
*/
|
||||
public function setMail(string $mail): void
|
||||
{
|
||||
$this->mail = $mail;
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace metier;
|
||||
|
||||
class Article
|
||||
{
|
||||
private string $id;
|
||||
private string $title;
|
||||
private string $date;
|
||||
private string $description;
|
||||
private string $guid;
|
||||
private string $link;
|
||||
private string $mediaContent;
|
||||
private string $provenance;
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $title
|
||||
* @param string $date
|
||||
* @param string $description
|
||||
* @param string $guid
|
||||
* @param string $link
|
||||
* @param string $mediaContent
|
||||
* @param string $provenance
|
||||
*/
|
||||
public function __construct(string $id, string $title, string $date, string $description, string $guid, string $link, string $mediaContent, string $provenance)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->title = $title;
|
||||
$this->date = $date;
|
||||
$this->description = $description;
|
||||
$this->guid = $guid;
|
||||
$this->link = $link;
|
||||
$this->mediaContent = $mediaContent;
|
||||
$this->provenance = $provenance;
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): void
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getDate(): string
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(string $date): void
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function getGuid(): string
|
||||
{
|
||||
return $this->guid;
|
||||
}
|
||||
|
||||
public function setGuid(string $guid): void
|
||||
{
|
||||
$this->guid = $guid;
|
||||
}
|
||||
|
||||
public function getLink(): string
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
public function setLink(string $link): void
|
||||
{
|
||||
$this->link = $link;
|
||||
}
|
||||
|
||||
public function getMediaContent(): string
|
||||
{
|
||||
return $this->mediaContent;
|
||||
}
|
||||
|
||||
public function setMediaContent(string $mediaContent): void
|
||||
{
|
||||
$this->mediaContent = $mediaContent;
|
||||
}
|
||||
|
||||
public function getProvenance(): int
|
||||
{
|
||||
return $this->provenance;
|
||||
}
|
||||
|
||||
public function setProvenance(int $provenance): void
|
||||
{
|
||||
$this->provenance = $provenance;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->title . $this->date . $this->description;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace metier;
|
||||
|
||||
class Flux
|
||||
{
|
||||
private string $id;
|
||||
private string $flux;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFlux(): string
|
||||
{
|
||||
return $this->flux;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $flux
|
||||
*/
|
||||
public function setFlux(string $flux): void
|
||||
{
|
||||
$this->flux = $flux;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
use DAL\AdminGateway;
|
||||
use DAL\Connection;
|
||||
use metier\Admin;
|
||||
|
||||
class AdminModel
|
||||
{
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function connection (string $username, string $mdp){
|
||||
//Validation::validationLogin($username);
|
||||
//Validation::validationMdp($mdp);
|
||||
|
||||
$gwArticle = new AdminGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$lmdp = $gwArticle->login($username);
|
||||
|
||||
foreach ($lmdp as $motDePasse){
|
||||
if (password_verify($mdp,$motDePasse['password']) or $mdp == $motDePasse['password']){
|
||||
$_SESSION['role'] = 'admin';
|
||||
$_SESSION['pseudo'] = $username;
|
||||
return new Admin($username,$motDePasse['mail']);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function isAdmin(): bool
|
||||
{
|
||||
return isset($_SESSION['role']) && $_SESSION['role'] == 'admin';
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
use DAL\{ArticleGateway, Connection};
|
||||
use Exception;
|
||||
use metier\Article;
|
||||
|
||||
class ArticleModel
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getArticles() : array
|
||||
{
|
||||
$gwArticle = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$tabArticle = array();
|
||||
$res = $gwArticle->getAllArticles();
|
||||
foreach($res as $row){
|
||||
$tabArticle[] = new Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] );
|
||||
}
|
||||
return $tabArticle;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
use DAL\Connection;
|
||||
use DAL\FluxGateway;
|
||||
use metier\Flux;
|
||||
require_once "config/config.php";
|
||||
|
||||
class FluxModel
|
||||
{
|
||||
public function FindAllFlux(){
|
||||
$gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$data = array();
|
||||
$result = $gateway->findAllFlux();
|
||||
|
||||
foreach ($result as $row){
|
||||
$data[] = new Flux($row['$flux']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function addFlux(Flux $flux){
|
||||
$gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$data = $this->findFlux($flux);
|
||||
if ($data == array()) {
|
||||
$gateway->addFlux($flux);
|
||||
}
|
||||
}
|
||||
|
||||
public function addFluxBySrc(string $flux): Flux {
|
||||
$gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$newFlux = new Flux($flux);
|
||||
$gateway->addFlux($newFlux);
|
||||
return $newFlux;
|
||||
}
|
||||
|
||||
public function removeFlux(Flux $flux){
|
||||
$gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$gateway->removeFlux($flux);
|
||||
}
|
||||
|
||||
public function removeFluxBySrc(string $flux): Flux {
|
||||
$gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$newFlux = new Flux($flux);
|
||||
$gateway->removeFlux($newFlux);
|
||||
return $newFlux;
|
||||
}
|
||||
|
||||
public function findFlux(Flux $flux){
|
||||
$gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$data = array();
|
||||
$result = $gateway->findFlux($flux);
|
||||
|
||||
foreach ($result as $row){
|
||||
$data[] = new Flux($row['$flux']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function findFluxBySrc(string $flux){
|
||||
$gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$data = array();
|
||||
$result = $gateway->findFluxBySrc($flux);
|
||||
|
||||
foreach ($result as $row){
|
||||
$data[] = new Flux($row['$flux']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
use DAL\ArticleGateway;
|
||||
use DAL\Connection;
|
||||
use DAL\FluxGateway;
|
||||
use DOMDocument;
|
||||
use Exception;
|
||||
use metier\Article;
|
||||
use metier\Flux;
|
||||
|
||||
class Parser
|
||||
{
|
||||
private FluxGateway $fluxGateway;
|
||||
private ArticleGateway $articleGateway;
|
||||
|
||||
public function __construct(FluxGateway $fluxGateway, ArticleGateway $articleGateway){
|
||||
$this->fluxGateway = $fluxGateway;
|
||||
$this->articleGateway = $articleGateway;
|
||||
}
|
||||
public function parseArticles(Flux $flux): array
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$tabArticle = array();
|
||||
|
||||
if ($dom->load($flux->getFlux())){
|
||||
$items = $dom->getElementsByTagName('item');
|
||||
|
||||
foreach ($items as $item) {
|
||||
$title = $item->getElementsByTagName('title')[0]->nodeValue;
|
||||
$date = $item->getElementsByTagName('pubDate')[0]->nodeValue;
|
||||
$guid = $item->getElementsByTagName('guid')[0]->nodeValue;
|
||||
$link = $item->getElementsByTagName('link')[0]->nodeValue;
|
||||
$description = $item->getElementsByTagName('description')[0]->nodeValue;
|
||||
|
||||
$media = $item->getElementsByTagName('media:content');
|
||||
$mediaUrl = null;
|
||||
if ($media->length > 0){
|
||||
$mediaUrl = $media->item(0)->getAttribute('url');
|
||||
}
|
||||
|
||||
$tabArticle[] = new Article((int)null, $title, $date, $description, $guid, $link, $mediaUrl, $flux->getId());
|
||||
}
|
||||
return $tabArticle;
|
||||
} else {
|
||||
// En cas d'erreur lors du chargement du flux RSS, lever une exception
|
||||
throw new Exception("Erreur lors du chargement du flux RSS");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function parseAll($fluxes){
|
||||
foreach ($fluxes as $flux){
|
||||
$tabArticles[] =$this->parseArticles($flux);
|
||||
}
|
||||
return $tabArticles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addAllArticles()
|
||||
{
|
||||
$this->articleGateway->removeAllArticleForParser();
|
||||
|
||||
$allFlux = $this->fluxGateway->findAllFlux();
|
||||
$allArticles = $this->parseAll($allFlux);
|
||||
foreach ($allArticles as $article) {
|
||||
$this->articleGateway->addArticle($article);
|
||||
}
|
||||
return $allArticles;
|
||||
}
|
||||
|
||||
}
|
||||
$gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp'));
|
||||
$pars = new Parser( $gwFl,$gwArt);
|
||||
|
||||
|
||||
|
@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div align="center">
|
||||
{% if dVue is defined %}
|
||||
{% if dVueEreur is defined and dVueEreur|length >0 %}
|
||||
<h2>ERREUR !!!!!</h2>
|
||||
{% for value in dVueEreur %}
|
||||
<p>{{value}}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<h1>Login</h1>
|
||||
<form method="POST" name="myform" id="myform">
|
||||
<table>
|
||||
<tr>
|
||||
<td>Nom</td>
|
||||
<td>
|
||||
<input name="username" value="test" type="text" size="20" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password</td>
|
||||
<td>
|
||||
|
||||
<input type="password" id="password" name="password" required>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td><input type="submit" value="Envoyer" /></td>
|
||||
<td><input type="reset" value="Rétablir" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- action !!!!!!!!!! -->
|
||||
<input type="hidden" name="action" value="login" />
|
||||
</form>
|
||||
<a href="/~mapoint2/SAE/Php_RSS/fluxRSS/">Not a member? Go to Articles</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
@ -1,17 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Erreur</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>ERREUR page !!!!!</h1>
|
||||
{% if dVueEreur is defined %}
|
||||
{% for value in dVueEreur %}
|
||||
<p>{{value}}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Erreur</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>ERREUR page !!!!!</h1>
|
||||
{% if dVueEreur is defined %}
|
||||
{% for value in dVueEreur %}
|
||||
<p>{{value}}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>All Articles</title>
|
||||
</head>
|
||||
<body>
|
||||
{% for value in dVue.data %}
|
||||
<p>
|
||||
{% for article in value %}
|
||||
<p>
|
||||
{{article}}
|
||||
</p>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endfor %}
|
||||
{% if not isAdmin %}
|
||||
<a href="/~mapoint2/SAE/Php_RSS/fluxRSS/admin/">Connect</a>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue