Commit 3990b97b authored by François Agneray's avatar François Agneray
Browse files

#50 => done

parent f18dac72
Pipeline #2218 passed with stages
in 3 minutes
......@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- #42: The GET method of the InstanceListAction returns the list of available instances with **the number of dataset families** and the **number of available datasets** for each instance
- #45: New route which allows to return the distinct values ​​of an attribute for one dataset used to generate the criterion option list => **/dataset/{name}/attribute/{id}/distinct**
- #50: Middleware to log metamodel sql requests added (only for the dev mode)
### Changed
- #44: Adding the doctrine production mode (see readme)
......
......@@ -13,3 +13,4 @@ declare(strict_types=1);
$app->add(new App\Middleware\JsonBodyParserMiddleware());
$app->add(new App\Middleware\ContentTypeJsonMiddleware());
$app->add(new App\Middleware\CorsMiddleware());
$app->add(new App\Middleware\MetamodelSqlLoggerMiddleware($container->get('logger'), $container->get('em')));
<?php
/*
* This file is part of Anis Auth.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Middleware;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Log\LoggerInterface;
use Doctrine\ORM\EntityManagerInterface;
/**
* Middleware to log metamodel sql requests
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Middleware
*/
final class MetamodelSqlLoggerMiddleware implements MiddlewareInterface
{
/**
* The logger interface is the central access point to log information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality
*
* @var EntityManagerInterface
*/
protected $em;
/**
* Create the classe before call process to execute this middleware
*
* @param LoggerInterface $logger The logger interface
* @param EntityManagerInterface $em Doctrine Entity Manager Interface
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
/**
* Log metamodel doctrine sql requests
*
* @param ServerRequest $request PSR-7 request
* @param RequestHandler $handler PSR-15 request handler
*
* @return Response
*/
public function process(Request $request, RequestHandler $handler): Response
{
$response = $handler->handle($request);
$sqlLogger = $this->em->getConfiguration()->getSQLLogger();
if ($sqlLogger) {
$nbQueries = count($sqlLogger->queries);
$this->logger->info('----------- METAMODEL SQL LOGGER -----------');
$this->logger->info('Number of sql requests : ' . $nbQueries);
for ($i = 1; $i <= $nbQueries; $i++) {
$this->logger->info($i . ' : ' . json_encode($sqlLogger->queries[$i]));
}
$this->logger->info('----------- METAMODEL SQL LOGGER -----------');
}
return $response;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment