Skip to content

Commit 151ba7a

Browse files
committed
Deduplicate Field properties
1 parent 336695f commit 151ba7a

File tree

5 files changed

+216
-336
lines changed

5 files changed

+216
-336
lines changed

src/Field.php

+1-176
Original file line numberDiff line numberDiff line change
@@ -17,186 +17,11 @@
1717
class Field implements Expressionable
1818
{
1919
use DiContainerTrait;
20+
use Model\FieldPropertiesTrait;
2021
use Model\JoinLinkTrait;
2122
use ReadableCaptionTrait;
2223
use TrackableTrait;
2324

24-
// {{{ Properties
25-
26-
/**
27-
* Default value of field.
28-
*
29-
* @var mixed
30-
*/
31-
public $default;
32-
33-
/**
34-
* Field type.
35-
*
36-
* Values are: 'string', 'text', 'boolean', 'integer', 'money', 'float',
37-
* 'date', 'datetime', 'time', 'array', 'object'.
38-
* Can also be set to unspecified type for your own custom handling.
39-
*
40-
* @var string
41-
*/
42-
public $type;
43-
44-
/**
45-
* For several types enum can provide list of available options. ['blue', 'red'].
46-
*
47-
* @var array|null
48-
*/
49-
public $enum;
50-
51-
/**
52-
* For fields that can be selected, values can represent interpretation of the values,
53-
* for instance ['F'=>'Female', 'M'=>'Male'];.
54-
*
55-
* @var array|null
56-
*/
57-
public $values;
58-
59-
/**
60-
* If value of this field is defined by a model, this property
61-
* will contain reference link.
62-
*
63-
* @var string|null
64-
*/
65-
protected $referenceLink;
66-
67-
/**
68-
* Actual field name.
69-
*
70-
* @var string|null
71-
*/
72-
public $actual;
73-
74-
/**
75-
* Is it system field?
76-
* System fields will be always loaded and saved.
77-
*
78-
* @var bool
79-
*/
80-
public $system = false;
81-
82-
/**
83-
* Setting this to true will never actually load or store
84-
* the field in the database. It will action as normal,
85-
* but will be skipped by load/iterate/update/insert.
86-
*
87-
* @var bool
88-
*/
89-
public $never_persist = false;
90-
91-
/**
92-
* Setting this to true will never actually store
93-
* the field in the database. It will action as normal,
94-
* but will be skipped by update/insert.
95-
*
96-
* @var bool
97-
*/
98-
public $never_save = false;
99-
100-
/**
101-
* Is field read only?
102-
* Field value may not be changed. It'll never be saved.
103-
* For example, expressions are read only.
104-
*
105-
* @var bool
106-
*/
107-
public $read_only = false;
108-
109-
/**
110-
* Defines a label to go along with this field. Use getCaption() which
111-
* will always return meaningful label (even if caption is null). Set
112-
* this property to any string.
113-
*
114-
* @var string
115-
*/
116-
public $caption;
117-
118-
/**
119-
* Array with UI flags like editable, visible and hidden.
120-
*
121-
* @var array
122-
*/
123-
public $ui = [];
124-
125-
/**
126-
* Mandatory field must not be null. The value must be set, even if
127-
* it's an empty value.
128-
*
129-
* Can contain error message for UI.
130-
*
131-
* @var bool|string
132-
*/
133-
public $mandatory = false;
134-
135-
/**
136-
* Required field must have non-empty value. A null value is considered empty too.
137-
*
138-
* Can contain error message for UI.
139-
*
140-
* @var bool|string
141-
*/
142-
public $required = false;
143-
144-
/**
145-
* Should we use typecasting when saving/loading data to/from persistence.
146-
*
147-
* Value can be array [$typecast_save_callback, $typecast_load_callback].
148-
*
149-
* @var bool|array|null
150-
*/
151-
public $typecast;
152-
153-
/**
154-
* Should we use serialization when saving/loading data to/from persistence.
155-
*
156-
* Value can be array [$encode_callback, $decode_callback].
157-
*
158-
* @var bool|array|string|null
159-
*/
160-
public $serialize;
161-
162-
/**
163-
* Persisting format for type = 'date', 'datetime', 'time' fields.
164-
*
165-
* For example, for date it can be 'Y-m-d', for datetime - 'Y-m-d H:i:s.u' etc.
166-
*
167-
* @var string
168-
*/
169-
public $persist_format;
170-
171-
/**
172-
* Persisting timezone for type = 'date', 'datetime', 'time' fields.
173-
*
174-
* For example, 'IST', 'UTC', 'Europe/Riga' etc.
175-
*
176-
* @var string
177-
*/
178-
public $persist_timezone = 'UTC';
179-
180-
/**
181-
* DateTime class used for type = 'data', 'datetime', 'time' fields.
182-
*
183-
* For example, 'DateTime', 'Carbon\Carbon' etc.
184-
*
185-
* @var string
186-
*/
187-
public $dateTimeClass = \DateTime::class;
188-
189-
/**
190-
* Timezone class used for type = 'data', 'datetime', 'time' fields.
191-
*
192-
* For example, 'DateTimeZone', 'Carbon\CarbonTimeZone' etc.
193-
*
194-
* @var string
195-
*/
196-
public $dateTimeZoneClass = \DateTimeZone::class;
197-
198-
// }}}
199-
20025
// {{{ Core functionality
20126

20227
/**

src/Model/FieldPropertiesTrait.php

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Atk4\Data\Model;
6+
7+
trait FieldPropertiesTrait
8+
{
9+
/**
10+
* Field type.
11+
*
12+
* Values are: 'string', 'text', 'boolean', 'integer', 'money', 'float',
13+
* 'date', 'datetime', 'time', 'array', 'object'.
14+
* Can also be set to unspecified type for your own custom handling.
15+
*
16+
* @var string
17+
*/
18+
public $type;
19+
20+
/**
21+
* For several types enum can provide list of available options. ['blue', 'red'].
22+
*
23+
* @var array|null
24+
*/
25+
public $enum;
26+
27+
/**
28+
* For fields that can be selected, values can represent interpretation of the values,
29+
* for instance ['F' => 'Female', 'M' => 'Male'];.
30+
*
31+
* @var array|null
32+
*/
33+
public $values;
34+
35+
/**
36+
* If value of this field is defined by a model, this property
37+
* will contain reference link.
38+
*
39+
* @var string|null
40+
*/
41+
protected $referenceLink;
42+
43+
/**
44+
* Actual field name.
45+
*
46+
* @var string|null
47+
*/
48+
public $actual;
49+
50+
/**
51+
* Is it system field?
52+
* System fields will be always loaded and saved.
53+
*
54+
* @var bool
55+
*/
56+
public $system = false;
57+
58+
/**
59+
* Default value of field.
60+
*
61+
* @var mixed
62+
*/
63+
public $default;
64+
65+
/**
66+
* Setting this to true will never actually load or store
67+
* the field in the database. It will action as normal,
68+
* but will be skipped by load/iterate/update/insert.
69+
*
70+
* @var bool
71+
*/
72+
public $never_persist = false;
73+
74+
/**
75+
* Setting this to true will never actually store
76+
* the field in the database. It will action as normal,
77+
* but will be skipped by update/insert.
78+
*
79+
* @var bool
80+
*/
81+
public $never_save = false;
82+
83+
/**
84+
* Is field read only?
85+
* Field value may not be changed. It'll never be saved.
86+
* For example, expressions are read only.
87+
*
88+
* @var bool
89+
*/
90+
public $read_only = false;
91+
92+
/**
93+
* Defines a label to go along with this field. Use getCaption() which
94+
* will always return meaningful label (even if caption is null). Set
95+
* this property to any string.
96+
*
97+
* @var string
98+
*/
99+
public $caption;
100+
101+
/**
102+
* Array with UI flags like editable, visible and hidden.
103+
*
104+
* By default hasOne relation ID field should be editable in forms,
105+
* but not visible in grids. UI should respect these flags.
106+
*
107+
* @var array
108+
*/
109+
public $ui = [];
110+
111+
/**
112+
* Mandatory field must not be null. The value must be set, even if
113+
* it's an empty value.
114+
*
115+
* Can contain error message for UI.
116+
*
117+
* @var bool|string
118+
*/
119+
public $mandatory = false;
120+
121+
/**
122+
* Required field must have non-empty value. A null value is considered empty too.
123+
*
124+
* Can contain error message for UI.
125+
*
126+
* @var bool|string
127+
*/
128+
public $required = false;
129+
130+
/**
131+
* Should we use typecasting when saving/loading data to/from persistence.
132+
*
133+
* Value can be array [$typecast_save_callback, $typecast_load_callback].
134+
*
135+
* @var bool|array|null
136+
*/
137+
public $typecast;
138+
139+
/**
140+
* Should we use serialization when saving/loading data to/from persistence.
141+
*
142+
* Value can be array [$encode_callback, $decode_callback].
143+
*
144+
* @var bool|array|string|null
145+
*/
146+
public $serialize;
147+
148+
/**
149+
* Persisting format for type = 'date', 'datetime', 'time' fields.
150+
*
151+
* For example, for date it can be 'Y-m-d', for datetime - 'Y-m-d H:i:s.u' etc.
152+
*
153+
* @var string
154+
*/
155+
public $persist_format;
156+
157+
/**
158+
* Persisting timezone for type = 'date', 'datetime', 'time' fields.
159+
*
160+
* For example, 'IST', 'UTC', 'Europe/Riga' etc.
161+
*
162+
* @var string
163+
*/
164+
public $persist_timezone = 'UTC';
165+
166+
/**
167+
* DateTime class used for type = 'data', 'datetime', 'time' fields.
168+
*
169+
* For example, 'DateTime', 'Carbon\Carbon' etc.
170+
*
171+
* @var string
172+
*/
173+
public $dateTimeClass = \DateTime::class;
174+
175+
/**
176+
* Timezone class used for type = 'data', 'datetime', 'time' fields.
177+
*
178+
* For example, 'DateTimeZone', 'Carbon\CarbonTimeZone' etc.
179+
*
180+
* @var string
181+
*/
182+
public $dateTimeZoneClass = \DateTimeZone::class;
183+
}

src/Reference/HasMany.php

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
use Atk4\Data\Model;
1010
use Atk4\Data\Reference;
1111

12-
/**
13-
* Reference\HasMany class.
14-
*/
1512
class HasMany extends Reference
1613
{
1714
public function getTheirFieldName(): string

0 commit comments

Comments
 (0)