|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This part of configuration is responsible for ODM mapping options, including set of mutators |
|
4
|
|
|
* to be automatically attached to different field types. Attention, configs might include runtime |
|
5
|
|
|
* code which depended on environment values only. |
|
6
|
|
|
* |
|
7
|
|
|
* @see SchemasConfig |
|
8
|
|
|
*/ |
|
9
|
|
|
use Spiral\Models\Accessors; |
|
10
|
|
|
use Spiral\ODM\Accessors as ODMAccessors; |
|
11
|
|
|
use Spiral\ODM\ODM; |
|
12
|
|
|
|
|
13
|
|
|
return [ |
|
14
|
|
|
/* |
|
15
|
|
|
* Set of mutators to be applied for specific field types. |
|
16
|
|
|
*/ |
|
17
|
|
|
'mutators' => [ |
|
18
|
|
|
'int' => ['setter' => 'intval'], |
|
19
|
|
|
'float' => ['setter' => 'floatval'], |
|
20
|
|
|
'string' => ['setter' => 'strval'], |
|
21
|
|
|
'bool' => ['setter' => 'boolval'], |
|
22
|
|
|
|
|
23
|
|
|
//Automatic casting of mongoID |
|
24
|
|
|
'ObjectID' => ['setter' => [ODM::class, 'mongoID']], |
|
25
|
|
|
|
|
26
|
|
|
'array::string' => ['accessor' => ODMAccessors\StringArray::class], |
|
27
|
|
|
'array::objectIDs' => ['accessor' => ODMAccessors\ObjectIDsArray::class], |
|
28
|
|
|
'array::integer' => ['accessor' => ODMAccessors\IntegerArray::class], |
|
29
|
|
|
|
|
30
|
|
|
'timestamp' => ['accessor' => Accessors\UTCMongoTimestamp::class], |
|
31
|
|
|
/*{{mutators}}*/ |
|
32
|
|
|
], |
|
33
|
|
|
/* |
|
34
|
|
|
* Mutator aliases can be used to declare custom getter and setter filter methods. |
|
35
|
|
|
*/ |
|
36
|
|
|
'aliases' => [ |
|
37
|
|
|
//Id aliases |
|
38
|
|
|
'MongoId' => 'ObjectID', |
|
39
|
|
|
'objectID' => 'ObjectID', |
|
40
|
|
|
\MongoDB\BSON\ObjectID::class => 'ObjectID', |
|
41
|
|
|
|
|
42
|
|
|
//Timestamps |
|
43
|
|
|
\MongoDB\BSON\UTCDateTime::class => 'timestamp', |
|
44
|
|
|
|
|
45
|
|
|
//Scalar typ aliases |
|
46
|
|
|
'integer' => 'int', |
|
47
|
|
|
'long' => 'int', |
|
48
|
|
|
'text' => 'string', |
|
49
|
|
|
|
|
50
|
|
|
//Array aliases |
|
51
|
|
|
'array::int' => 'array::integer', |
|
52
|
|
|
'array::MongoId' => 'array::objectIDs', |
|
53
|
|
|
'array::ObjectID' => 'array::objectIDs', |
|
54
|
|
|
'array::MongoDB\BSON\ObjectID' => 'array::objectIDs' |
|
55
|
|
|
|
|
56
|
|
|
/*{{mutators.aliases}}*/ |
|
|
|
|
|
|
57
|
|
|
] |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.