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

#10 => done

parent 995f2bf5
......@@ -54,7 +54,7 @@ phpunit:
phpcs:
@docker run --init -it --rm --user $(UID):$(GID) \
-v $(CURDIR):/project \
-w /project jakzal/phpqa phpcs --standard=PSR2 --extensions=php -n --colors src
-w /project jakzal/phpqa phpcs --standard=PSR2 --extensions=php --colors src
init-db:
@docker-compose exec php sh ./conf-dev/metamodel_init.sh
......
......@@ -66,8 +66,12 @@ final class TokenAction
* @param Lcobucci\JWT\Builder $jwtBuilder
* @param Lcobucci\JWT\Signer $jwtSigner
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, JwtBuilder $jwtBuilder, JwtSigner $jwtSigner)
{
public function __construct(
LoggerInterface $logger,
EntityManagerInterface $em,
JwtBuilder $jwtBuilder,
JwtSigner $jwtSigner
) {
$this->logger = $logger;
$this->em = $em;
$this->jwtBuilder = $jwtBuilder;
......
......@@ -42,7 +42,10 @@ final class AttributeAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, OPTIONS');
}
$attribute = $this->em->getRepository('App\Entity\Attribute')->findOneBy(array('dataset' => $args['name'], 'id' => $args['id']));
$attribute = $this->em->getRepository('App\Entity\Attribute')->findOneBy(array(
'dataset' => $args['name'],
'id' => $args['id']
));
if (is_null($attribute)) {
return $this->dispatchHttpError(
......@@ -58,8 +61,18 @@ final class AttributeAction
if ($request->isPut()) {
$parsedBody = $request->getParsedBody();
$criteriaFamily = is_null($parsedBody['id_criteria_family']) ? null : $this->em->find('App\Entity\CriteriaFamily', $parsedBody['id_criteria_family']);
$outputCategory = is_null($parsedBody['id_output_category']) ? null : $this->em->find('App\Entity\OutputCategory', $parsedBody['id_output_category']);
if (is_null($parsedBody['id_criteria_family'])) {
$criteriaFamily = null;
} else {
$criteriaFamily = $this->em->find('App\Entity\CriteriaFamily', $parsedBody['id_criteria_family']);
}
if (is_null($parsedBody['id_output_category'])) {
$outputCategory = null;
} else {
$outputCategory = $this->em->find('App\Entity\OutputCategory', $parsedBody['id_output_category']);
}
$this->editAttribute($attribute, $parsedBody, $criteriaFamily, $outputCategory);
$this->em->flush();
......@@ -70,8 +83,12 @@ final class AttributeAction
return $newResponse;
}
private function editAttribute(Attribute $attribute, array $parsedBody, CriteriaFamily $criteriaFamily = null, OutputCategory $outputCategory = null): void
{
private function editAttribute(
Attribute $attribute,
array $parsedBody,
CriteriaFamily $criteriaFamily = null,
OutputCategory $outputCategory = null
): void {
$attribute->setLabel($parsedBody['label']);
$attribute->setFormLabel($parsedBody['form_label']);
$attribute->setDescription($parsedBody['description']);
......
......@@ -37,8 +37,12 @@ final class DatasetListAction
*/
private $encryptionKey;
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, DBALConnectionFactory $dcf, string $encryptionKey)
{
public function __construct(
LoggerInterface $logger,
EntityManagerInterface $em,
DBALConnectionFactory $dcf,
string $encryptionKey
) {
$this->logger = $logger;
$this->em = $em;
$this->dcf = $dcf;
......@@ -62,7 +66,19 @@ final class DatasetListAction
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
foreach (array('name', 'table_ref', 'label', 'description', 'display', 'count', 'vo', 'data_path', 'project_name', 'id_dataset_family') as $a) {
$fields = array(
'name',
'table_ref',
'label',
'description',
'display',
'count',
'vo',
'data_path',
'project_name',
'id_dataset_family'
);
foreach ($fields as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
$response,
......
......@@ -98,7 +98,7 @@ final class FamilyAction
{
if ($family instanceof \App\Entity\DatasetFamily) {
return 'dataset';
} else if ($family instanceof \App\Entity\CriteriaFamily) {
} elseif ($family instanceof \App\Entity\CriteriaFamily) {
return 'criteria';
} else {
return 'output';
......
......@@ -92,8 +92,11 @@ final class OutputCategoryAction
return $newResponse;
}
private function editOutputCategory(OutputCategory $outputCategory, array $parsedBody, OutputFamily $outputFamily): void
{
private function editOutputCategory(
OutputCategory $outputCategory,
array $parsedBody,
OutputFamily $outputFamily
): void {
$outputCategory->setLabel($parsedBody['label']);
$outputCategory->setDisplay($parsedBody['display']);
$outputCategory->setOutputFamily($outputFamily);
......
......@@ -34,8 +34,12 @@ final class TableListAction
*/
private $encryptionKey;
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, DBALConnectionFactory $dcf, string $encryptionKey)
{
public function __construct(
LoggerInterface $logger,
EntityManagerInterface $em,
DBALConnectionFactory $dcf,
string $encryptionKey
) {
$this->logger = $logger;
$this->em = $em;
$this->dcf = $dcf;
......
......@@ -158,7 +158,7 @@ final class SearchAction
}
$result = $this->fetchAll($queryBuilder, $attributes);
} else if ($searchType === 'meta') {
} elseif ($searchType === 'meta') {
$queryBuilder->select('COUNT(*) as nb');
$stmt = $queryBuilder->execute();
$count = $stmt->fetchAll();
......@@ -223,7 +223,13 @@ final class SearchAction
} else {
$values = array();
}
$operator = $this->operatorFactory->create($params[1], $queryBuilder->expr(), $column, $columnType, $values);
$operator = $this->operatorFactory->create(
$params[1],
$queryBuilder->expr(),
$column,
$columnType,
$values
);
$expressions[] = $operator->getExpression();
}
$queryBuilder->where(new CompositeExpression(CompositeExpression::TYPE_AND, $expressions));
......@@ -239,7 +245,7 @@ final class SearchAction
$attribute = $this->getAttribute($dataset, (int) $o[0]);
if ($o[1] === 'a') {
$aord = 'ASC';
} else if ($o[1] === 'd') {
} elseif ($o[1] === 'd') {
$aord = 'DESC';
} else {
throw SearchException::typeOfOrderDoesNotExist($o[1]);
......@@ -280,9 +286,9 @@ final class SearchAction
private function getAttributesOfTypeJson(array $attributes): array
{
return array_map(function($attribute) {
return array_map(function ($attribute) {
return $attribute->getLabel();
}, array_filter($attributes, function($attribute) {
}, array_filter($attributes, function ($attribute) {
return $attribute->getType() === 'json';
}));
}
......
......@@ -19,9 +19,10 @@ class CorsMiddleware
public function __invoke(Request $req, Response $res, $next)
{
if ($req->isOptions()) {
$acah = 'X-Requested-With, Content-Type, Accept, Origin, Authorization';
$response = $res
->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization');
->withHeader('Access-Control-Allow-Headers', $acah);
} else {
$response = $res
->withHeader('Access-Control-Allow-Origin', '*')
......
......@@ -39,7 +39,8 @@ trait ActionTrait
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
// Encrypt the data using AES 256 encryption in CBC mode using our encryption key and initialization vector.
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $this->encryptionKey, 0, $iv);
// The $iv is just as important as the key for decrypting, so save it with our encrypted data using a unique separator (::)
// The $iv is just as important as the key for decrypting
// So save it with our encrypted data using a unique separator (::)
return base64_encode($encrypted . '::' . $iv);
}
......
......@@ -18,8 +18,13 @@ class Between extends Operator
private $value1;
private $value2;
public function __construct(ExpressionBuilder $expr, string $column, string $columnType, string $value1, string $value2)
{
public function __construct(
ExpressionBuilder $expr,
string $column,
string $columnType,
string $value1,
string $value2
) {
parent::__construct($expr, $column, $columnType);
$this->verifyTypeCompatibility($value1);
$this->verifyTypeCompatibility($value2);
......
......@@ -14,5 +14,11 @@ use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
interface IOperatorFactory
{
public function create(string $type, ExpressionBuilder $expr, string $column, string $columnType, array $parameters): IOperator;
public function create(
string $type,
ExpressionBuilder $expr,
string $column,
string $columnType,
array $parameters
): IOperator;
}
......@@ -11,6 +11,7 @@
namespace App\Utils\Operator;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\Expression\CompositeExpression;
class JsonPostgres extends Operator
{
......@@ -18,8 +19,14 @@ class JsonPostgres extends Operator
private $operator;
private $value;
public function __construct(ExpressionBuilder $expr, string $column, string $columnType, string $path, string $operator, string $value)
{
public function __construct(
ExpressionBuilder $expr,
string $column,
string $columnType,
string $path,
string $operator,
string $value
) {
parent::__construct($expr, $column, $columnType);
$this->path = explode(',', $path);
$this->operator = $operator;
......@@ -35,6 +42,15 @@ class JsonPostgres extends Operator
case 'gt':
return $this->expr->gt($this->getColumn(), $this->getValue());
break;
case 'gte':
return $this->expr->gte($this->getColumn(), $this->getValue());
break;
case 'lt':
return $this->expr->lt($this->getColumn(), $this->getValue());
break;
case 'lte':
return $this->expr->lte($this->getColumn(), $this->getValue());
break;
}
}
......@@ -45,10 +61,16 @@ class JsonPostgres extends Operator
private function getValue()
{
if ($this->value === 'true' || $this->value === 'false') {
return $this->getSqlValue($this->value);
if (is_numeric($this->value)) {
$newValue = 1 * $this->value;
} elseif ($this->value === 'true') {
$newValue = true;
} elseif ($this->value === 'false') {
$newValue = false;
} else {
return $this->getSqlValue(json_encode($this->value));
$newValue = $this->value;
}
return $this->getSqlValue(json_encode($newValue));
}
}
......@@ -23,8 +23,13 @@ class OperatorFactory implements IOperatorFactory
$this->databasePlatform = $databasePlatform;
}
public function create(string $type, ExpressionBuilder $expr, string $column, string $columnType, array $parameters): IOperator
{
public function create(
string $type,
ExpressionBuilder $expr,
string $column,
string $columnType,
array $parameters
): IOperator {
switch ($type) {
case 'bw':
if (count($parameters) != 2) {
......
......@@ -14,7 +14,11 @@ $container = $app->getContainer();
// Anis Error Handler
$container['errorHandler'] = function ($c) {
return new App\Utils\AnisErrorHandler($c->get('logger'), $c->get('mailer'), (bool) $c->get('settings')['displayErrorDetails']);
return new App\Utils\AnisErrorHandler(
$c->get('logger'),
$c->get('mailer'),
(bool) $c->get('settings')['displayErrorDetails']
);
};
// Metamodel database Doctrine 2 Entity Manager
......@@ -136,7 +140,12 @@ $container['App\Action\Meta\DatabaseAction'] = function ($c) {
$container['App\Action\Meta\TableListAction'] = function ($c) {
$settings = $c->get('settings');
return new App\Action\Meta\TableListAction($c->get('logger'), $c->get('em'), $c->get('dcf'), $settings['encryption_key']);
return new App\Action\Meta\TableListAction(
$c->get('logger'),
$c->get('em'),
$c->get('dcf'),
$settings['encryption_key']
);
};
$container['App\Action\Meta\ProjectListAction'] = function ($c) {
......@@ -165,7 +174,12 @@ $container['App\Action\Meta\OutputCategoryAction'] = function ($c) {
$container['App\Action\Meta\DatasetListAction'] = function ($c) {
$settings = $c->get('settings');
return new App\Action\Meta\DatasetListAction($c->get('logger'), $c->get('em'), $c->get('dcf'), $settings['encryption_key']);
return new App\Action\Meta\DatasetListAction(
$c->get('logger'),
$c->get('em'),
$c->get('dcf'),
$settings['encryption_key']
);
};
$container['App\Action\Meta\DatasetAction'] = function ($c) {
......@@ -215,5 +229,11 @@ $container['App\Action\Meta\UserAction'] = function ($c) {
// Search actions
$container['App\Action\Search\SearchAction'] = function ($c) {
$settings = $c->get('settings');
return new App\Action\Search\SearchAction($c->get('logger'), $c->get('em'), $c->get('dcf'), $c->get('of'), $settings['encryption_key']);
return new App\Action\Search\SearchAction(
$c->get('logger'),
$c->get('em'),
$c->get('dcf'),
$c->get('of'),
$settings['encryption_key']
);
};
......@@ -32,7 +32,11 @@ $app->map(['OPTIONS', 'GET', 'PUT', 'DELETE'], '/metadata/project/{name}', App\A
$app->map(['OPTIONS', 'GET', 'POST'], '/metadata/family/{type}', App\Action\Meta\FamilyListAction::class);
$app->map(['OPTIONS', 'GET', 'PUT', 'DELETE'], '/metadata/family/{type}/{id}', App\Action\Meta\FamilyAction::class);
$app->map(['OPTIONS', 'GET', 'POST'], '/metadata/output-category', App\Action\Meta\OutputCategoryListAction::class);
$app->map(['OPTIONS', 'GET', 'PUT', 'DELETE'], '/metadata/output-category/{id}', App\Action\Meta\OutputCategoryAction::class);
$app->map(
['OPTIONS', 'GET', 'PUT', 'DELETE'],
'/metadata/output-category/{id}',
App\Action\Meta\OutputCategoryAction::class
);
$app->map(['OPTIONS', 'GET', 'POST'], '/metadata/dataset', App\Action\Meta\DatasetListAction::class);
$app->map(['OPTIONS', 'GET', 'PUT', 'DELETE'], '/metadata/dataset/{name}', App\Action\Meta\DatasetAction::class);
$app->map(['OPTIONS', 'GET'], '/metadata/dataset/{name}/attribute', App\Action\Meta\AttributeListAction::class);
......
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