Skip to content
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

Merged
merged 3 commits into from Oct 19, 2016

Conversation

romaninsh
Copy link
Member

Imants, I have moved and extended "Typecasting" section. Some parts may be incomplete, but this help you with your PR.

'enum' => ['No', 'Yes']
]);

$m['is_married'] = 'Yes'; // type-casts into true
Copy link
Member

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!
Copy link
Member

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".
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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' -
Copy link
Member

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)
Copy link
Member

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.
Copy link
Member

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.

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explode(' ', $x)

@DarkSide666 DarkSide666 merged commit e72cf4f into feature/add-encode-support Oct 19, 2016
@DarkSide666 DarkSide666 deleted the feature/add-typecasting-docs branch October 19, 2016 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants