1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) Nate Brunette. |
4
|
|
|
* Distributed under the MIT License (http://opensource.org/licenses/MIT) |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace Tebru\Gson; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class PropertyNamingPolicy |
13
|
|
|
* |
14
|
|
|
* Represents standard strategies for converting properties names to their serialized equivalents. |
15
|
|
|
* |
16
|
|
|
* @author Nate Brunette <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
final class PropertyNamingPolicy |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Leave property name unchanged |
22
|
|
|
*/ |
23
|
|
|
public const IDENTITY = 'IDENTITY'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Convert camel case to lower case separated by dashes |
27
|
|
|
*/ |
28
|
|
|
public const LOWER_CASE_WITH_DASHES = 'LOWER_CASE_WITH_DASHES'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Convert camel case to lower case separated by underscores |
32
|
|
|
*/ |
33
|
|
|
public const LOWER_CASE_WITH_UNDERSCORES = 'LOWER_CASE_WITH_UNDERSCORES'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Convert camel case to upper case separated by dashes |
37
|
|
|
*/ |
38
|
|
|
public const UPPER_CASE_WITH_DASHES = 'UPPER_CASE_WITH_DASHES'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Convert camel case to upper case separated by underscores |
42
|
|
|
*/ |
43
|
|
|
public const UPPER_CASE_WITH_UNDERSCORES = 'UPPER_CASE_WITH_UNDERSCORES'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Capitalize the first letter of a camel case property |
47
|
|
|
*/ |
48
|
|
|
public const UPPER_CAMEL_CASE = 'UPPER_CAMEL_CASE'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Converts camel case to capitalized words |
52
|
|
|
*/ |
53
|
|
|
public const UPPER_CAMEL_CASE_WITH_SPACES = 'UPPER_CAMEL_CASE_WITH_SPACES'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* List of all allowed policies |
57
|
|
|
* |
58
|
|
|
* @var string[] |
59
|
|
|
*/ |
60
|
|
|
public static $policies = [ |
61
|
|
|
self::IDENTITY, |
62
|
|
|
self::LOWER_CASE_WITH_DASHES, |
63
|
|
|
self::LOWER_CASE_WITH_UNDERSCORES, |
64
|
|
|
self::UPPER_CASE_WITH_DASHES, |
65
|
|
|
self::UPPER_CASE_WITH_UNDERSCORES, |
66
|
|
|
self::UPPER_CASE_WITH_UNDERSCORES, |
67
|
|
|
self::UPPER_CAMEL_CASE, |
68
|
|
|
self::UPPER_CAMEL_CASE_WITH_SPACES, |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
private function __construct() {} |
72
|
|
|
} |
73
|
|
|
|