22
33namespace orm \DataBase ;
44
5-
6- use orm \DataBase \fields \Number ;
75use orm \DataBase \fields \DateTime ;
8- use orm \DataBase \fields \PrimaryKey ;
96use orm \DataBase \fields \ForeignKey ;
7+ use orm \DataBase \fields \Number ;
8+ use orm \DataBase \fields \PrimaryKey ;
109use orm \DataBase \fields \StringField ;
1110
12-
1311/**
1412 * Class Field
1513 * Contains methods for describing fields and types in database
16- * for migrations and controlling types and references in database
17- * @package orm\DataBase
14+ * for migrations and controlling types and references in database.
1815 */
1916class Field
2017{
21-
2218 /**
23- * @param string $type type of number field (int, float, double)
24- * @param int $size size of field
25- * @param string $attribute attribute of field (binary, unsigned)
26- * @param bool $auto_increment, auto_increment flag
19+ * @param string $type type of number field (int, float, double)
20+ * @param int $size size of field
21+ * @param string $attribute attribute of field (binary, unsigned)
22+ * @param bool $auto_increment, auto_increment flag
23+ *
2724 * @return \orm\DataBase\fields\Number
2825 */
29- public static function number ($ type = " int " , $ size = 10 , $ attribute = "" , $ auto_increment = false )
26+ public static function number ($ type = ' int ' , $ size = 10 , $ attribute = '' , $ auto_increment = false )
3027 {
3128 $ obj = new Number ();
3229 $ obj ->type = $ type ;
3330 $ obj ->size = $ size ;
3431 $ obj ->attribute = $ attribute ;
3532 $ obj ->auto_increment = $ auto_increment ;
33+
3634 return $ obj ;
3735 }
3836
3937 /**
40- * describe PRIMARY KEY with AUTO_INCREMENT
38+ * describe PRIMARY KEY with AUTO_INCREMENT.
39+ *
4140 * @return PrimaryKey
4241 */
4342 public static function primaryKey ()
4443 {
4544 $ obj = new PrimaryKey ();
46- $ obj ->type = " int " ;
45+ $ obj ->type = ' int ' ;
4746 $ obj ->size = 10 ;
4847 $ obj ->auto_increment = true ;
4948 $ obj ->primary_key = true ;
49+
5050 return $ obj ;
5151 }
5252
5353 /**
5454 * REFERENCES:
5555 * ON DELETE (RESTRICT, CASCADE, NO ACTION, SET NULL)
56- * ON UPDATE (RESTRICT, CASCADE, NO ACTION, SET NULL)
56+ * ON UPDATE (RESTRICT, CASCADE, NO ACTION, SET NULL).
57+ *
58+ * @param string $table -- name of table for foreign key
59+ * @param string $field -- field in table for foreign key
60+ * @param array $references -- array with settings of references for foreign key.
61+ * If it not sent, will be set from default values (restrict)
5762 *
58- * @param string $table -- name of table for foreign key
59- * @param string $field -- field in table for foreign key
60- * @param array $references -- array with settings of references for foreign key.
61- * If it not sent, will be set from default values (restrict)
6263 * @return ForeignKey
6364 */
64- public static function foreignKey ($ table , $ field , $ references = [" on_delete " => " restrict " , " on_update " => " restrict " ])
65+ public static function foreignKey ($ table , $ field , $ references = [' on_delete ' => ' restrict ' , ' on_update ' => ' restrict ' ])
6566 {
6667 $ obj = new ForeignKey ();
6768 $ obj ->table = $ table ;
6869 $ obj ->field = $ field ;
69- $ obj ->on_delete = $ references ["on_delete " ];
70- $ obj ->on_update = $ references ["on_update " ];
70+ $ obj ->on_delete = $ references ['on_delete ' ];
71+ $ obj ->on_update = $ references ['on_update ' ];
72+
7173 return $ obj ;
7274 }
7375
7476 /**
75- * String field with type varchar
77+ * String field with type varchar.
78+ *
7679 * @param int $length
80+ *
7781 * @return StringField
7882 */
7983 public static function varchar ($ length = 255 )
8084 {
81- return self ::stringField (" varchar " , $ length );
85+ return self ::stringField (' varchar ' , $ length );
8286 }
8387
8488 /**
85- * String field with type varchar
89+ * String field with type varchar.
90+ *
8691 * @param int $length
92+ *
8793 * @return StringField
8894 */
8995 public static function text ($ length = 65535 )
9096 {
91- return self ::stringField (" text " , $ length );
97+ return self ::stringField (' text ' , $ length );
9298 }
9399
94100 /**
95- * datetime field
101+ * datetime field.
102+ *
96103 * @param string $format
104+ *
97105 * @return DateTime
98106 */
99- public static function dateTime ($ format = " %Y-%M-%d %h:%m:%s " )
107+ public static function dateTime ($ format = ' %Y-%M-%d %h:%m:%s ' )
100108 {
101- return self ::dateTimeUniversal (" datetime " , $ format );
109+ return self ::dateTimeUniversal (' datetime ' , $ format );
102110 }
103111
104112 /**
105- * date field
113+ * date field.
114+ *
106115 * @param string $format
116+ *
107117 * @return DateTime
108118 */
109- public static function date ($ format = " %Y-%M-%d " )
119+ public static function date ($ format = ' %Y-%M-%d ' )
110120 {
111- return self ::dateTimeUniversal (" date " , $ format );
121+ return self ::dateTimeUniversal (' date ' , $ format );
112122 }
113123
114124 /**
115- * time field
125+ * time field.
126+ *
116127 * @param string $format
128+ *
117129 * @return DateTime
118130 */
119- public static function time ($ format = " %h:%m:%s " )
131+ public static function time ($ format = ' %h:%m:%s ' )
120132 {
121- return self ::dateTimeUniversal (" time " , $ format );
133+ return self ::dateTimeUniversal (' time ' , $ format );
122134 }
123135
124136 /**
125- * describe universal field of datetime
137+ * describe universal field of datetime.
138+ *
126139 * @param $type
127140 * @param $format
141+ *
128142 * @return DateTime
129143 */
130144 private static function dateTimeUniversal ($ type , $ format )
131145 {
132146 $ obj = new DateTime ();
133147 $ obj ->type = $ type ;
134148 $ obj ->format = $ format ;
149+
135150 return $ obj ;
136151 }
137152
138153 /**
139- * describe universal string field
154+ * describe universal string field.
155+ *
140156 * @param $type
141157 * @param $size
158+ *
142159 * @return StringField
143160 */
144161 private static function stringField ($ type , $ size )
145162 {
146163 $ obj = new StringField ();
147164 $ obj ->type = $ type ;
148165 $ obj ->size = $ size ;
149- $ obj ->encoding = "utf8_general_ci " ;
166+ $ obj ->encoding = 'utf8_general_ci ' ;
167+
150168 return $ obj ;
151169 }
152-
153- }
170+ }
0 commit comments