Application
Application
This is an abstract class that implements the \jsonSerializable interface.
It serves as a base class for models in the Hazaar MVC framework.
- Full name:
\Hazaar\Warlock\Server\Struct\Application
- Parent class:
\Hazaar\Model
Properties
path
protected string $path
env
protected string $env
Inherited methods
__construct
Model constructor.
final public __construct(array $data = [], mixed $args): mixed
- This method is final.
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array | the data to initialize the model with |
$args | mixed |
__destruct
final public __destruct(): mixed
- This method is final.
__get
public __get(string $propertyName): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string |
__set
public __set(string $propertyName, mixed $propertyValue): void
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | |
$propertyValue | mixed |
__isset
Checks if a property is set.
public __isset(string $propertyName): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property to check |
Return Value:
returns true if the property is set, false otherwise
__unset
Unsets a specific property of the model.
public __unset(string $propertyName): void
This magic method is called when an unset operation is performed on an inaccessible property of the model. It allows you to unset a specific property by its name.
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property to unset |
__propertyRule__min
Applies the minimum value rule to a property.
private __propertyRule__min(string $propertyName, null|int $propertyValue, int $minValue): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | null|int | the value of the property |
$minValue | int | the minimum allowed value |
Return Value:
the property value after applying the minimum value rule
__propertyRule__max
Applies a maximum value rule to a property.
private __propertyRule__max(string $propertyName, null|int $propertyValue, int $maxValue): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | null|int | the value of the property |
$maxValue | int | the maximum allowed value |
Return Value:
the property value limited to the maximum value
__propertyRule__range
Applies a range validation rule to a property value.
private __propertyRule__range(string $propertyName, null|int $propertyValue, int $minValue, int $maxValue): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | null|int | the value of the property |
$minValue | int | the minimum allowed value |
$maxValue | int | the maximum allowed value |
Return Value:
the validated property value within the specified range
__propertyRule__required
Validates if a property is required and throws an exception if it is empty.
private __propertyRule__required(string $propertyName, mixed $propertyValue): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property being validated |
$propertyValue | mixed | the value of the property being validated |
Return Value:
the validated property value
Throws:
if the property value is empty
__propertyRule__minlength
Validates the minimum length of a property value.
private __propertyRule__minlength(string $propertyName, null|string $propertyValue, int $minLength): null|string
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property being validated |
$propertyValue | null|string | the value of the property being validated |
$minLength | int | the minimum length required for the property value |
Return Value:
the validated property value
Throws:
if the property value is shorter than the minimum length
__propertyRule__maxlength
Validates the maximum length of a property value.
private __propertyRule__maxlength(string $propertyName, null|string $propertyValue, int $maxLength): null|string
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property being validated |
$propertyValue | null|string | the value of the property being validated |
$maxLength | int | the maximum length allowed for the property value |
Return Value:
the validated property value
Throws:
if the property value exceeds the maximum length
__propertyRule__pad
Pads a string property value with spaces to a specified length.
private __propertyRule__pad(string $propertyName, null|string $propertyValue, int $padLength): null|string
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | null|string | the value of the property |
$padLength | int | the desired length of the padded string |
Return Value:
the padded string value or null if the property value is null
__propertyRule__filter
Applies a filter to a property value based on the specified filter type.
private __propertyRule__filter(string $propertyName, null|string $propertyValue, int $filterType): null|string
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | null|string | the value of the property |
$filterType | int | the filter type to apply |
Return Value:
the filtered property value
Throws:
if the property value fails the filter
See Also:
- https://www.php.net/manual/en/function.filter-var.php - The PHP filter_var() function.
__propertyRule__contains
Checks if the given property value contains the specified value.
private __propertyRule__contains(string $propertyName, null|array $propertyValue, mixed $contains): null|array
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property being validated |
$propertyValue | null|array | the value of the property being validated |
$contains | mixed | the value to check if it is contained in the property value |
Return Value:
the validated property value
Throws:
if the property value does not contain the specified value
__propertyRule__format
Formats the given property value according to the specified format.
private __propertyRule__format(string $propertyName, null|string $propertyValue, string $format): null|string
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | null|string | the value of the property |
$format | string | the format string to apply to the property value |
Return Value:
the formatted property value, or null if the original value was null
__propertyRule__custom
Applies a custom property rule to the given property.
private __propertyRule__custom(string $propertyName, mixed $propertyValue, callable $callback): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | mixed | the value of the property |
$callback | callable | the callback function to apply the custom rule |
Return Value:
the result of the callback function
Throws:
if the custom rule returns false
__propertyRule__trim
Trims the specified character from the given property value.
private __propertyRule__trim(string $propertyName, mixed $propertyValue, string $char = ' '): string
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | mixed | the value of the property |
$char | string | the character to be trimmed (default is ' ') |
Return Value:
the trimmed property value
__serialize
public __serialize(): array
__unserialize
public __unserialize(array $data): void
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array |
get
Magic method called when reading inaccessible properties.
public get(string $propertyName): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | The name of the property being accessed |
Return Value:
The value of the property
set
Sets the value of a property dynamically.
public set(string $propertyName, mixed $propertyValue): void
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | mixed | the value to set for the property |
populate
(re)Populates the model with data from an array or object.
public populate(array|object $data): void
This method is used to populate the model with data from an array or object. If the object already has data, it will be overwritten by the new data. This includes any setting properties to null if they are not present in the new data.
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array|object | the data to populate the model with |
extend
Extends the model with additional data.
public extend(array|object $data): void
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array|object | the data to extend the model with |
count
public count(): int
toArray
Converts the object to an array representation.
public toArray(bool $ignoreNullPropertyValues = false): array<string,mixed>
Parameters:
Parameter | Type | Description |
---|---|---|
$ignoreNullPropertyValues | bool |
Return Value:
the array representation of the object
jsonSerialize
Returns the object data as a JSON serializable array.
public jsonSerialize(): array<string,mixed>
Return Value:
the JSON serializable array representation of the object data
current
public current(): mixed
next
public next(): void
key
public key(): mixed
valid
public valid(): bool
rewind
public rewind(): void
toJSON
Converts the model object to a JSON string.
public toJSON(): string
Return Value:
the JSON representation of the model object
fromJSONString
Creates a new instance of the model class from a JSON string.
public static fromJSONString(string $json): static
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$json | string | the JSON string to parse |
Return Value:
the newly created instance of the model class
has
public has(string $propertyName): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string |
defineProperty
public defineProperty(string $propertyType, string $propertyName, mixed $propertyValue = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyType | string | |
$propertyName | string | |
$propertyValue | mixed |
defineEventHook
Defines an event hook for the model.
public defineEventHook(string $hookName, mixed $args): void
Parameters:
Parameter | Type | Description |
---|---|---|
$hookName | string | the name of the hook |
$args | mixed | The arguments for the hook. |
defineRule
Defines a rule for a property in the model.
public defineRule(string $rule, string[] $propertyNames, mixed $args): void
Parameters:
Parameter | Type | Description |
---|---|---|
$rule | string | the name of the rule |
$propertyNames | string[] | the name of one or more properties |
$args | mixed | Additional arguments for the rule. |
Throws:
if the specified rule does not exist
construct
protected construct(array<string,mixed>& $data): void
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array<string,mixed> |
constructed
protected constructed(array<string,mixed>& $data): void
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array<string,mixed> |
setUserProperty
private setUserProperty(string $propertyName, mixed $propertyValue): void
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | |
$propertyValue | mixed |
convertPropertyValueDataType
Converts the data type of a property value based on its reflection.
private convertPropertyValueDataType(\ReflectionProperty $reflectionProperty, mixed& $propertyValue): void
Parameters:
Parameter | Type | Description |
---|---|---|
$reflectionProperty | \ReflectionProperty | the reflection of the property |
$propertyValue | mixed | The value of the property to be converted |
Throws:
if the property type is unsupported or not a subclass of 'Hazaar\Model'
convertValueDataType
private convertValueDataType(string $propertyType, mixed& $propertyValue): void
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyType | string | |
$propertyValue | mixed |
execPropertyRules
Executes the property rules for a given property.
private execPropertyRules(string $propertyName, mixed& $propertyValue, array<int,callable|string> $rules): void
Parameters:
Parameter | Type | Description |
---|---|---|
$propertyName | string | the name of the property |
$propertyValue | mixed | The value of the property |
$rules | array<int,callable|string> | the array of rules to be applied |
Automatically generated on 2024-11-14