mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-18 00:29:22 +02:00
Made the magic strings of EventCommentHelper into an array
This commit is contained in:
parent
a0a7ca3c9c
commit
6df7bc5f2a
6 changed files with 62 additions and 33 deletions
|
@ -29,30 +29,16 @@ namespace App\Services\LogSystem;
|
|||
*/
|
||||
class EventCommentNeededHelper
|
||||
{
|
||||
final public const VALID_OPERATION_TYPES = [
|
||||
'part_edit',
|
||||
'part_create',
|
||||
'part_delete',
|
||||
'part_stock_operation',
|
||||
'datastructure_edit',
|
||||
'datastructure_create',
|
||||
'datastructure_delete',
|
||||
];
|
||||
|
||||
public function __construct(protected array $enforce_change_comments_for)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a log change comment is needed for the given operation type
|
||||
*/
|
||||
public function isCommentNeeded(string $comment_type): bool
|
||||
public function isCommentNeeded(EventCommentType $comment_type): bool
|
||||
{
|
||||
//Check if the comment type is valid
|
||||
if (! in_array($comment_type, self::VALID_OPERATION_TYPES, true)) {
|
||||
throw new \InvalidArgumentException('The comment type "'.$comment_type.'" is not valid!');
|
||||
}
|
||||
|
||||
return in_array($comment_type, $this->enforce_change_comments_for, true);
|
||||
}
|
||||
}
|
||||
|
|
39
src/Services/LogSystem/EventCommentType.php
Normal file
39
src/Services/LogSystem/EventCommentType.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\LogSystem;
|
||||
|
||||
/**
|
||||
* This enum represents the different types of event comments that could be required, by the system.
|
||||
* They are almost only useful when working with the EventCommentNeededHelper service.
|
||||
*/
|
||||
enum EventCommentType: string
|
||||
{
|
||||
case PART_EDIT = 'part_edit';
|
||||
case PART_CREATE = 'part_create';
|
||||
case PART_DELETE = 'part_delete';
|
||||
case PART_STOCK_OPERATION = 'part_stock_operation';
|
||||
case DATASTRUCTURE_EDIT = 'datastructure_edit';
|
||||
case DATASTRUCTURE_CREATE = 'datastructure_create';
|
||||
case DATASTRUCTURE_DELETE = 'datastructure_delete';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue