|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the eav package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alex Kuperwood <[email protected]> |
|
6
|
|
|
* @copyright 2025 Alex Kuperwood |
|
7
|
|
|
* @license https://opensource.org/license/mit The MIT License |
|
8
|
|
|
*/ |
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace Kuperwood\Eav\Enum; |
|
12
|
|
|
|
|
13
|
|
|
class _RESULT |
|
14
|
|
|
{ |
|
15
|
|
|
const CREATED = 1; |
|
16
|
|
|
const UPDATED = 2; |
|
17
|
|
|
const FOUND = 3; |
|
18
|
|
|
const NOT_FOUND = 4; |
|
19
|
|
|
const NOT_ENOUGH_ARGS = 5; |
|
20
|
|
|
const NOT_ALLOWED = 6; |
|
21
|
|
|
const EMPTY = 7; |
|
22
|
|
|
const DELETED = 8; |
|
23
|
|
|
const NOT_DELETED = 9; |
|
24
|
|
|
const VALIDATION_FAILS = 10; |
|
25
|
|
|
const VALIDATION_PASSED = 11; |
|
26
|
|
|
const EXPORT_SUCCESS = 12; |
|
27
|
|
|
const EXPORT_FAILED = 13; |
|
28
|
|
|
const IMPORT_SUCCESS = 14; |
|
29
|
|
|
const IMPORT_FAILED = 15; |
|
30
|
|
|
|
|
31
|
|
|
public static function code($result) |
|
32
|
|
|
{ |
|
33
|
|
|
$validResults = [ |
|
34
|
|
|
self::CREATED, self::UPDATED, self::FOUND, self::NOT_FOUND, |
|
35
|
|
|
self::NOT_ENOUGH_ARGS, self::NOT_ALLOWED, self::EMPTY, self::DELETED, |
|
36
|
|
|
self::NOT_DELETED, self::VALIDATION_FAILS, self::VALIDATION_PASSED, |
|
37
|
|
|
self::EXPORT_SUCCESS, self::EXPORT_FAILED, self::IMPORT_SUCCESS, self::IMPORT_FAILED |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
return in_array($result, $validResults, true) ? $result : null; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
1 |
|
public static function message($result) |
|
44
|
|
|
{ |
|
45
|
1 |
|
$messages = [ |
|
46
|
1 |
|
self::CREATED => 'Created', |
|
47
|
1 |
|
self::UPDATED => 'Updated', |
|
48
|
1 |
|
self::FOUND => 'Found', |
|
49
|
1 |
|
self::NOT_FOUND => 'Not found', |
|
50
|
1 |
|
self::NOT_ENOUGH_ARGS => 'Not enough arguments', |
|
51
|
1 |
|
self::NOT_ALLOWED => 'Not allowed', |
|
52
|
1 |
|
self::EMPTY => 'Nothing to perform', |
|
53
|
1 |
|
self::DELETED => 'Deleted', |
|
54
|
1 |
|
self::NOT_DELETED => 'Not deleted', |
|
55
|
1 |
|
self::VALIDATION_FAILS => 'Validation fails', |
|
56
|
1 |
|
self::VALIDATION_PASSED => 'Validation passed', |
|
57
|
1 |
|
self::EXPORT_SUCCESS => 'Successfully exported', |
|
58
|
1 |
|
self::EXPORT_FAILED => 'Export failed', |
|
59
|
1 |
|
self::IMPORT_SUCCESS => 'Successfully imported', |
|
60
|
1 |
|
self::IMPORT_FAILED => 'Import failed', |
|
61
|
1 |
|
]; |
|
62
|
|
|
|
|
63
|
1 |
|
return $messages[$result] ?? 'Unknown result'; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|