File tree Expand file tree Collapse file tree 3 files changed +29
-13
lines changed
Infrastructure/Persistence/Doctrine/ORM/Mapping Expand file tree Collapse file tree 3 files changed +29
-13
lines changed Original file line number Diff line number Diff line change @@ -20,37 +20,33 @@ class Phone
20
20
21
21
public function __construct ($ phone )
22
22
{
23
- $ this ->phone = $ phone ? $ this ->cleanPhone ($ phone ) : '' ;
23
+ $ this ->phone = $ this ->setPhone ($ phone );
24
+ }
25
+
26
+ public function phone ()
27
+ {
28
+ return $ this ->phone ;
24
29
}
25
30
26
31
public function equals (Phone $ phone )
27
32
{
28
- return strtolower (( string ) $ this ) === strtolower (( string ) $ phone );
33
+ return $ this -> phone === $ phone-> phone ( );
29
34
}
30
35
31
36
public function __toString ()
32
37
{
33
38
return (string )$ this ->phone ;
34
39
}
35
40
36
- private function cleanPhone ($ phone )
41
+ private function setPhone ($ phone )
37
42
{
38
- $ absolute = $ phone[ 0 ] === ' + ' ;
43
+ $ phone = str_replace ( ' +34 ' , '' , $ phone ) ;
39
44
$ numbers = preg_replace ('/\D/ ' , '' , $ phone );
40
45
41
46
if (!$ numbers ) {
42
47
throw new PhoneFormatInvalidException ();
43
48
}
44
49
45
- // special logic for russian local phone notation
46
- if ($ numbers [0 ] === '8 ' && !$ absolute && strlen ($ numbers ) == 11 ) {
47
- $ numbers [0 ] = '7 ' ;
48
- }
49
-
50
- if ($ numbers [0 ] !== '7 ' || strlen ($ numbers ) != 11 ) {
51
- throw new PhoneFormatInvalidException ();
52
- }
53
-
54
50
return $ numbers ;
55
51
}
56
52
}
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <doctrine-mapping xmlns =" http://doctrine-project.org/schemas/orm/doctrine-mapping"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" http://doctrine-project.org/schemas/orm/doctrine-mapping
5
+ http://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd" >
6
+
7
+ <embeddable name =" LIN3S\SharedKernel\Domain\Model\Email" >
8
+ <field name =" email" type =" string" length =" 255" nullable =" false" />
9
+ </embeddable >
10
+ </doctrine-mapping >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <doctrine-mapping xmlns =" http://doctrine-project.org/schemas/orm/doctrine-mapping"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" http://doctrine-project.org/schemas/orm/doctrine-mapping
5
+ http://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd" >
6
+
7
+ <embeddable name =" LIN3S\SharedKernel\Domain\Model\Phone" >
8
+ <field name =" phone" type =" string" length =" 20" nullable =" false" />
9
+ </embeddable >
10
+ </doctrine-mapping >
You can’t perform that action at this time.
0 commit comments