New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add typecasting docs #189
Feature/add typecasting docs #189
Conversation
[ci skip] [skip ci]
'enum' => ['No', 'Yes'] | ||
]); | ||
|
||
$m['is_married'] = 'Yes'; // type-casts into true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not "type-casts into true", but "normalizes into true"
]); | ||
|
||
$m['is_married'] = 'Yes'; // type-casts into true | ||
$m['is_married'] = true; // better way! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mention why it is better - because no normalization of value is needed in this case
$m['is_married'] = 'Yes'; // type-casts into true | ||
$m['is_married'] = true; // better way! | ||
|
||
$m->save(); // stores as "Yes". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... because of type-casting
// either null or false | ||
} | ||
|
||
If type is passed with incompatible format, Agile Data will try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"If value is passed which is not compatible with field type, Agile Data will try to normalize value."
$m['age'] = '49.80'; | ||
$m['name'] = ' John'; | ||
|
||
echo $m['age']; // 49 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 49 - normalization cast value to integer
- 'string' - for storing short strings, such as name of a person. | ||
Normalize will trim the value. | ||
- 'integer' - normalize will (int) the value. | ||
- 'array' - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more types here :)
------------ | ||
|
||
UI framework such as Agile Toolkit will typically rely on type | ||
information to properly present data with views (forms and tables) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... rely on field type ...
... data in views ...
]); | ||
|
||
This is one way to store binary data. Type is unspecified but the | ||
binary value of a field will be encoded with base64 before storing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... before storing and automatically decoded when you load this value back from persistence.
|
||
This is one way to store binary data. Type is unspecified but the | ||
binary value of a field will be encoded with base64 before storing. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently AD supports following serialization algorithms:
- serialize - for storing PHP objects
- json - for storing objects and arrays
- base64 - for storing encoded strings
- [serialize_callback, unserialize_callback] - for custom serialization
} | ||
|
||
$money_dencode = function($x) { | ||
list($amount, $currency) = explode($x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explode(' ', $x)
Imants, I have moved and extended "Typecasting" section. Some parts may be incomplete, but this help you with your PR.