Types: Difference between revisions

From Sunhill Framework Documentation
created articles
 
+cat
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Of cause you can implement an AbstractProperty and overwrite all necessary methods. But the sunhill framework defines some predefined types and semantics.
Of cause you can implement an AbstractProperty and overwrite all necessary methods. But the sunhill framework defines some predefined types and [[semantics]].


== The difference between types and semantics ==
== The difference between types and semantics ==
Line 11: Line 11:
=== Integer ===
=== Integer ===
Take a integer number like 1, -4 or 1234.
Take a integer number like 1, -4 or 1234.
==== setMaximum(int $maximum): static ====
Sets a maximum value this property can be assiged.
==== getMaximum(): int ====
Returns the current maximum value this property can be assigned to.
==== setMinimum(int $minimum): static ====
Sets a minimum value this property can be assigned.
==== getMinimum(): int ====
Returns the current minimum value this property can be assigned to.
==== setOutOfBoundsPolicy(string $policy): static ====
When assigning a value that is lower than minimum or higher than maximum the behaviour of this property is defined by the out-of-bounds-policy:
* '''set''' = If the value is lower than minmum it is set to minimum, if higher than maximum it is set to maximum.
* '''invalid''' = If the value if lower than minimum or higher than maximum an inavlidValueException() is thrown.
==== getOutOfBoundsPolicy(): string ====
Returns the current out-of-bound-policy.


=== Float ===
=== Float ===
Takes a floating point numer like 1.2, -0.2, 3.
Takes a floating point numer like 1.2, -0.2, 3.
==== setMaximum(int $maximum): static ====
Sets a maximum value this property can be assiged.
==== getMaximum(): int ====
Returns the current maximum value this property can be assigned to.
==== setMinimum(int $minimum): static ====
Sets a minimum value this property can be assigned.
==== getMinimum(): int ====
Returns the current minimum value this property can be assigned to.
==== setOutOfBoundsPolicy(string $policy): static ====
When assigning a value that is lower than minimum or higher than maximum the behaviour of this property is defined by the out-of-bounds-policy:
* '''set''' = If the value is lower than minmum it is set to minimum, if higher than maximum it is set to maximum.
* '''invalid''' = If the value if lower than minimum or higher than maximum an inavlidValueException() is thrown.
==== getOutOfBoundsPolicy(): string ====
Returns the current out-of-bound-policy.


=== Boolean ===
=== Boolean ===
Line 40: Line 79:


== The complex types ==
== The complex types ==
[[Category:Properties]]

Latest revision as of 10:38, 30 September 2024

Of cause you can implement an AbstractProperty and overwrite all necessary methods. But the sunhill framework defines some predefined types and semantics.

The difference between types and semantics

A type is a basic format as you know from any programming language. So you have types like integer or string.

A semantic is the idea behind a value. A typical semantic is temperature or capcity. The semantic has always a type as a parent because a temperature would be always a float and a name is always a string.

Long story short: A semantic is a child of a type.

The basic types

Integer

Take a integer number like 1, -4 or 1234.

setMaximum(int $maximum): static

Sets a maximum value this property can be assiged.

getMaximum(): int

Returns the current maximum value this property can be assigned to.

setMinimum(int $minimum): static

Sets a minimum value this property can be assigned.

getMinimum(): int

Returns the current minimum value this property can be assigned to.

setOutOfBoundsPolicy(string $policy): static

When assigning a value that is lower than minimum or higher than maximum the behaviour of this property is defined by the out-of-bounds-policy:

  • set = If the value is lower than minmum it is set to minimum, if higher than maximum it is set to maximum.
  • invalid = If the value if lower than minimum or higher than maximum an inavlidValueException() is thrown.

getOutOfBoundsPolicy(): string

Returns the current out-of-bound-policy.

Float

Takes a floating point numer like 1.2, -0.2, 3.

setMaximum(int $maximum): static

Sets a maximum value this property can be assiged.

getMaximum(): int

Returns the current maximum value this property can be assigned to.

setMinimum(int $minimum): static

Sets a minimum value this property can be assigned.

getMinimum(): int

Returns the current minimum value this property can be assigned to.

setOutOfBoundsPolicy(string $policy): static

When assigning a value that is lower than minimum or higher than maximum the behaviour of this property is defined by the out-of-bounds-policy:

  • set = If the value is lower than minmum it is set to minimum, if higher than maximum it is set to maximum.
  • invalid = If the value if lower than minimum or higher than maximum an inavlidValueException() is thrown.

getOutOfBoundsPolicy(): string

Returns the current out-of-bound-policy.

Boolean

Takes only a boolean value like true or false.

Date

Takes a date as value like 2004-10-23.

DateTime

Takes a timestamp value like 2004-10-23 12:22:10.

Time

Take a time value like 12:22:10

Enum

Take one of some predefined string values.

String

Takes a sequence of characters like "Hello this is a string".

Text

The same a string besides that it can take any count of characters.

Blob

Takes a sequence of bytes (not only readable characters).

The complex types