1 | <?php |
||
21 | class TypeConverter |
||
22 | { |
||
23 | /** |
||
24 | * Converts a legacy type to the new BSON type |
||
25 | * |
||
26 | * This method handles type conversion from ext-mongo to ext-mongodb: |
||
27 | * - For all types (MongoId, MongoDate, etc.) it returns the correct BSON |
||
28 | * object instance |
||
29 | * - For arrays and objects it iterates over properties and converts each |
||
30 | * item individually |
||
31 | * - For other types it returns the value unconverted |
||
32 | * |
||
33 | * @param mixed $value |
||
34 | * @return mixed |
||
35 | */ |
||
36 | 44 | public static function convertFromLegacy($value) |
|
54 | |||
55 | /** |
||
56 | * Converts a BSON type to the legacy types |
||
57 | * |
||
58 | * This method handles type conversion from ext-mongodb to ext-mongo: |
||
59 | * - For all instances of \MongoDB\BSON\Type it returns an object of the |
||
60 | * corresponding legacy type (MongoId, MongoDate, etc.) |
||
61 | * - For arrays and objects it iterates over properties and converts each |
||
62 | * item individually |
||
63 | * - For other types it returns the value unconverted |
||
64 | * |
||
65 | * @param mixed $value |
||
66 | * @return mixed |
||
67 | */ |
||
68 | 26 | public static function convertToLegacy($value) |
|
86 | |||
87 | /** |
||
88 | * Helper method to find out if an array has numerical indexes |
||
89 | * |
||
90 | * For performance reason, this method checks the first array index only. |
||
91 | * More thorough inspection of the array might be needed. |
||
92 | * Note: Returns true for empty arrays to preserve compatibility with empty |
||
93 | * lists. |
||
94 | * |
||
95 | * @param array $array |
||
96 | * @return bool |
||
97 | */ |
||
98 | 44 | public static function isNumericArray(array $array) |
|
102 | |||
103 | /** |
||
104 | * Converter method to convert a BSON object to its legacy type |
||
105 | * |
||
106 | * @param \MongoDB\BSON\Type $value |
||
107 | * @return mixed |
||
108 | */ |
||
109 | 8 | private static function convertBSONObjectToLegacy(\MongoDB\BSON\Type $value) |
|
132 | |||
133 | /** |
||
134 | * Converts all arrays with non-numeric keys to stdClass |
||
135 | * |
||
136 | * @param array $array |
||
137 | * @return array|\stdClass |
||
138 | */ |
||
139 | 44 | private static function ensureCorrectType(array $array) |
|
154 | } |
||
155 |
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break
.To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.