File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php 
2+ 
3+ namespace  DHolmes \DoctrineExtras ;
4+ 
5+ use  Doctrine \DBAL \Types \Type ;
6+ use  Doctrine \DBAL \Platforms \AbstractPlatform ;
7+ use  DHolmes \LangExtra \Enumeration ;
8+ 
9+ abstract  class  EnumerationType extends  Type
10+ { 
11+  /** 
12+  * @param array $fieldDeclaration 
13+  * @param AbstractPlatform $platform 
14+  * @return string 
15+  */ 
16+  public  function  getSqlDeclaration (array  $ fieldDeclarationAbstractPlatform $ platform
17+  {
18+  return  'VARCHAR(50) ' ;
19+  }
20+  
21+  /** @return string */ 
22+  abstract  protected  function  getClass ();
23+ 
24+  /** 
25+  * @param string $value 
26+  * @param AbstractPlatform $platform 
27+  * @return Enumeration 
28+  */ 
29+  public  function  convertToPHPValue ($ valueAbstractPlatform $ platform
30+  {
31+  $ phpValuenull ;
32+  if  ($ valuenull )
33+  {
34+  $ class$ this getClass ();
35+  $ phpValue$ classget ($ value
36+  }
37+  
38+  return  $ phpValue
39+  }
40+ 
41+  /** 
42+  * @param Enumeration $value 
43+  * @param AbstractPlatform $platform 
44+  * @return string 
45+  */ 
46+  public  function  convertToDatabaseValue ($ valueAbstractPlatform $ platform
47+  {
48+  $ dbValuenull ;
49+  $ class$ this getClass ();
50+  if  ($ valueinstanceof  $ class
51+  {
52+  $ dbValue$ valuegetKey ();
53+  }
54+  else  if  ($ valuenull )
55+  {
56+  throw  new  \Exception (sprintf ('Cannot persist value of type "%s ' , get_class ($ value
57+  }
58+  
59+  return  $ dbValue
60+  }
61+ }
                         You can’t perform that action at this time. 
           
                  
0 commit comments