Job
extends ExtendedObject
in package
implements
IJob
Abstract class Job
Represents a job to be executed.
Table of Contents
Interfaces
- IJob
- Interface IJob
Constants
- JsonSchema = ['type' => 'object', 'patternProperties' => ['.*' => ['type' => ['number', 'string', 'boolean', 'object', 'array', 'null']]]]
- Data validation schema.
Properties
- $attempts : int
- $class : string
- $headers : array<string|int, mixed>
- $id : int|null
- $parallel : bool
- $payload : ExtendedObject
- $payload_class : string
- $queue : string
- $_changed : bool|null
- Object change indicator.
- $_changeKeyCase : bool|null
- Change case on object keys
- $_data : mixed
- Object data, properties.
- $_original : mixed
- Contains data received during initialization.
- $_prefix : string|null
- Prefix for properties, to ensure proper operation with storages.
- $_validationResult : ValidationResult
- Validation results
- $maxAttempts : int
- Maximum number of attempts for executing the job.
Methods
- __construct() : mixed
- Constructor
- __destruct() : mixed
- Destructor
- __get() : mixed
- Retrieves the value of a dynamic or inaccessible property from the object.
- __isset() : bool
- Checks whether a property is set in the object.
- __set() : void
- Sets the value of a dynamic or inaccessible property within the object.
- __unset() : void
- Unsets a property in the object.
- Add() : bool
- Adds the job.
- Begin() : bool
- Begins a transaction.
- Clear() : mixed
- Cleans object
- Commit() : bool
- Commits a transaction.
- Count() : int
- Counts the number of elements in the object.
- Create() : static
- Creates a new job instance.
- Delete() : bool
- Deletes the job.
- DispatchEvent() : object|null
- Dispatches an event.
- Fail() : bool
- Marks the job as failed.
- GetData() : mixed
- Retrieves the current data of the object.
- getIterator() : ExtendedObjectIterator
- Returns an iterator for iterating over the data of the ExtendedObject.
- GetValidationData() : mixed
- Retrieves the validation data used for schema validation.
- Handle() : bool
- Handles the job.
- HandleEvent() : self
- Adds an event handler.
- IsChanged() : bool
- Checks if the object has been changed.
- IsLastAttempt() : bool
- Checks if the current attempt is the last attempt.
- IsParallel() : bool
- Checks if the job can be executed in parallel.
- IsPropertyChanged() : bool
- Checks if a specific property of the object has been changed.
- jsonSerialize() : array<string|int, mixed>
- Serializes the object to a value that can be serialized by json_encode.
- JsonUnserialize() : static
- Constructs a new object instance from a JSON-encoded string.
- offsetExists() : bool
- Checks if a value exists at the specified offset.
- offsetGet() : mixed|null
- Retrieves the value at the specified offset.
- offsetSet() : void
- Sets the value at the specified offset.
- offsetUnset() : void
- Unsets the value at the specified offset.
- Original() : object
- Returns the original data provided during object initialization.
- Prefix() : string
- Retrieves the prefix used for object properties.
- RemoveHandler() : self
- Removes an event handler.
- Rollback() : bool
- Rolls back a transaction.
- Schema() : object|string
- SetData() : void
- Sets data for the object.
- SetHeaders() : void
- Add headers to job manager
- ToArray() : array<string|int, mixed>
- Converts the job to an array.
- ToJSON() : string
- Converts the object's data to a JSON string.
- Update() : bool
- Updates the job.
- UpdateOriginal() : void
- Updates the original data with the current data of the object.
- Validate() : bool
- Validates the object's data against a JSON schema.
- _typeExchange() : mixed
- Handles the exchange of property values based on the specified mode.
- _typeToData() : mixed
- Converts data for retrieval via the GetData method.
Constants
JsonSchema
Data validation schema.
public
mixed
JsonSchema
= ['type' => 'object', 'patternProperties' => ['.*' => ['type' => ['number', 'string', 'boolean', 'object', 'array', 'null']]]]
Properties
$attempts
public
int
$attempts
The number of attempts made to execute the job.
$class
public
string
$class
The class name of the job.
$headers
public
array<string|int, mixed>
$headers
The headers payload associated with the job.
$id
public
int|null
$id
The ID of the job.
$parallel
public
bool
$parallel
Indicates if the job can be executed in parallel.
$payload
public
ExtendedObject
$payload
The payload object associated with the job.
$payload_class
public
string
$payload_class
The class name of the payload associated with the job.
$queue
public
string
$queue
The queue in which the job resides.
$_changed
Object change indicator.
protected
bool|null
$_changed
= false
$_changeKeyCase
Change case on object keys
protected
bool|null
$_changeKeyCase
= true
$_data
Object data, properties.
protected
mixed
$_data
$_original
Contains data received during initialization.
protected
mixed
$_original
$_prefix
Prefix for properties, to ensure proper operation with storages.
protected
string|null
$_prefix
= ""
$_validationResult
Validation results
protected
ValidationResult
$_validationResult
$maxAttempts
Maximum number of attempts for executing the job.
protected
static int
$maxAttempts
= 5
Methods
__construct()
Constructor
public
__construct([mixed $data = null ][, string $prefix = "" ][, bool $changeKeyCase = true ]) : mixed
Parameters
- $data : mixed = null
-
- initialization data
- $prefix : string = ""
-
- prefix
- $changeKeyCase : bool = true
-
- change key case
__destruct()
Destructor
public
__destruct() : mixed
__get()
Retrieves the value of a dynamic or inaccessible property from the object.
public
__get(string $property) : mixed
This magic method is invoked when attempting to access a property that is not accessible or does not exist within the object's scope using the arrow operator (->).
Parameters
- $property : string
-
The name of the property to retrieve.
Return values
mixed —The value of the specified property.
__isset()
Checks whether a property is set in the object.
public
__isset(string $property) : bool
This magic method is triggered when attempting to check whether a property is set in the object using isset().
Parameters
- $property : string
-
The name of the property being checked.
Return values
bool —Returns true if the property is set, false otherwise.
__set()
Sets the value of a dynamic or inaccessible property within the object.
public
__set(string $property, mixed $value) : void
This magic method is invoked when attempting to assign a value to a property that is not accessible or does not exist within the object's scope using the arrow operator (->).
Parameters
- $property : string
-
The name of the property to set.
- $value : mixed
-
The value to assign to the property.
__unset()
Unsets a property in the object.
public
__unset(string $property) : void
This magic method is triggered when attempting to unset a property in the object using unset().
Parameters
- $property : string
-
The name of the property to unset.
Add()
Adds the job.
public
Add([string|null $startDate = null ]) : bool
Parameters
- $startDate : string|null = null
-
The start date of the job.
Return values
bool —True if the job is successfully added, false otherwise.
Begin()
Begins a transaction.
public
Begin() : bool
Return values
bool —True if the transaction is successfully begun, false otherwise.
Clear()
Cleans object
public
Clear() : mixed
Commit()
Commits a transaction.
public
Commit(array<string|int, mixed>|object $result) : bool
Parameters
- $result : array<string|int, mixed>|object
-
The result of the transaction.
Return values
bool —True if the transaction is successfully committed, false otherwise.
Count()
Counts the number of elements in the object.
public
Count() : int
This method returns the number of elements in the object.
Return values
int —The number of elements in the object.
Create()
Creates a new job instance.
public
static Create(ExtendedObject $payload[, string $queue = 'default' ][, int $attempts = 0 ][, bool $parallel = false ][, int|null $id = null ]) : static
Parameters
- $payload : ExtendedObject
-
The payload object associated with the job.
- $queue : string = 'default'
-
The queue in which the job resides.
- $attempts : int = 0
-
The number of attempts made to execute the job.
- $parallel : bool = false
-
Indicates if the job can be executed in parallel.
- $id : int|null = null
-
The ID of the job.
Return values
static —The created job instance.
Delete()
Deletes the job.
public
Delete() : bool
Return values
bool —True if the job is successfully deleted, false otherwise.
DispatchEvent()
Dispatches an event.
public
DispatchEvent(string|Event $event[, mixed $args = null ][, bool $async = false ]) : object|null
Parameters
- $event : string|Event
-
The event object or its name.
- $args : mixed = null
-
Additional arguments to pass to the event handlers.
- $async : bool = false
-
Whether to dispatch the event asynchronously.
Return values
object|null —The event object with updated arguments, or null if the event does not exist.
Fail()
Marks the job as failed.
public
Fail(Throwable $exception[, bool $isLastAttempt = false ]) : bool
Parameters
- $exception : Throwable
-
The exception that caused the failure.
- $isLastAttempt : bool = false
-
Indicates if the failure is occurring on the last attempt.
Return values
bool —True if the job is marked as failed, false otherwise.
GetData()
Retrieves the current data of the object.
public
GetData([bool $type = true ]) : mixed
This method returns the current data of the object. If the $type parameter is set to true, the data is converted according to the object's type conversion rules; otherwise, the raw data is returned without conversion.
Parameters
- $type : bool = true
-
Optional. Determines whether to convert the data according to type conversion rules. Defaults to true.
Return values
mixed —The current data of the object.
getIterator()
Returns an iterator for iterating over the data of the ExtendedObject.
public
getIterator() : ExtendedObjectIterator
This method returns an iterator that allows iterating over the data of the ExtendedObject. It enables the use of foreach loops and other iterable operations on ExtendedObject instances.
Return values
ExtendedObjectIterator —An iterator for the data of the ExtendedObject.
GetValidationData()
Retrieves the validation data used for schema validation.
public
GetValidationData() : mixed
This method returns the data that is used for schema validation. It can be useful for debugging or accessing the data before validation.
Return values
mixed —The validation data used for schema validation.
Handle()
Handles the job.
public
abstract Handle(Logger $logger) : bool
Parameters
- $logger : Logger
-
The logger instance to use for logging.
Return values
bool —True if the job is handled successfully, false otherwise.
HandleEvent()
Adds an event handler.
public
HandleEvent(array<string|int, mixed>|string $ename, mixed $listener) : self
Parameters
- $ename : array<string|int, mixed>|string
-
The event name or an array of event names.
- $listener : mixed
-
The event handler.
Return values
selfIsChanged()
Checks if the object has been changed.
public
IsChanged() : bool
This method determines whether any changes have been made to the object's data since its initialization or the last update. It returns true if changes have been made, indicating that the object state is different from its original state; otherwise, it returns false.
Return values
bool —True if the object has been changed; otherwise, false.
IsLastAttempt()
Checks if the current attempt is the last attempt.
public
IsLastAttempt() : bool
Return values
bool —True if the current attempt is the last attempt, false otherwise.
IsParallel()
Checks if the job can be executed in parallel.
public
IsParallel() : bool
Return values
bool —True if the job can be executed in parallel, false otherwise.
IsPropertyChanged()
Checks if a specific property of the object has been changed.
public
IsPropertyChanged(string $property[, bool $dummy = false ]) : bool
This method determines whether a particular property of the object has been modified since its initialization or the last update. It returns true if the specified property has been changed; otherwise, it returns false.
Parameters
- $property : string
-
The name of the property to check for changes.
- $dummy : bool = false
-
Optional. A dummy parameter to maintain method signature consistency.
Return values
bool —True if the specified property has been changed; otherwise, false.
jsonSerialize()
Serializes the object to a value that can be serialized by json_encode.
public
jsonSerialize() : array<string|int, mixed>
This method is called during JSON serialization of the object. It allows the object to be serialized to a JSON-serializable representation using the json_encode function.
Return values
array<string|int, mixed> —The serializable representation of the object.
JsonUnserialize()
Constructs a new object instance from a JSON-encoded string.
public
static JsonUnserialize(string $json) : static
This method creates a new instance of the class from a JSON-encoded string. It accepts a JSON string representing the object and returns a new instance of the class.
Parameters
- $json : string
-
The JSON-encoded string representing the object.
Return values
static —The new instance of the class.
offsetExists()
Checks if a value exists at the specified offset.
public
offsetExists(string|int $offset) : bool
This method checks if a value exists at the specified offset in the ExtendedObject. It allows checking the existence of values using array access syntax, e.g., isset($object['key']).
Parameters
- $offset : string|int
-
The offset to check.
Tags
Return values
bool —True if a value exists at the specified offset, false otherwise.
offsetGet()
Retrieves the value at the specified offset.
public
offsetGet(string|int $offset) : mixed|null
This method retrieves the value at the specified offset in the ExtendedObject. It allows accessing values using array access syntax, e.g., $value = $object['key'].
Parameters
- $offset : string|int
-
The offset of the value to retrieve.
Tags
Return values
mixed|null —The value at the specified offset, or null if the offset does not exist.
offsetSet()
Sets the value at the specified offset.
public
offsetSet(string|int $offset, mixed $value) : void
This method sets the value at the specified offset in the ExtendedObject. It allows setting values using array access syntax, e.g., $object['key'] = $value.
Parameters
- $offset : string|int
-
The offset at which to set the value.
- $value : mixed
-
The value to set at the specified offset.
Tags
offsetUnset()
Unsets the value at the specified offset.
public
offsetUnset(string|int $offset) : void
This method unsets the value at the specified offset in the ExtendedObject. It allows unsetting values using array access syntax, e.g., unset($object['key']).
Parameters
- $offset : string|int
-
The offset of the value to unset.
Tags
Original()
Returns the original data provided during object initialization.
public
Original() : object
This method returns the original data provided during object initialization as an object. The original data represents the state of the object before any changes.
Return values
object —An object containing the original data provided during initialization.
Prefix()
Retrieves the prefix used for object properties.
public
Prefix() : string
This method returns the prefix used for object properties. The prefix is typically set during object initialization and is useful for distinguishing properties when working with storage systems.
Return values
string —The prefix used for object properties.
RemoveHandler()
Removes an event handler.
public
RemoveHandler(string $ename, mixed $listener) : self
Parameters
- $ename : string
-
The event name.
- $listener : mixed
-
The event handler to remove.
Return values
selfRollback()
Rolls back a transaction.
public
Rollback() : bool
Return values
bool —True if the transaction is successfully rolled back, false otherwise.
Schema()
public
static Schema([bool $exportAsString = false ][, mixed $addElements = [] ]) : object|string
Parameters
- $exportAsString : bool = false
- $addElements : mixed = []
Return values
object|stringSetData()
Sets data for the object.
public
SetData(mixed $data) : void
This method allows setting data for the object. It can accept various types of data, such as arrays, objects, or ExtendedObject instances.
Parameters
- $data : mixed
-
The data to set for the object.
SetHeaders()
Add headers to job manager
public
SetHeaders() : void
Tags
ToArray()
Converts the job to an array.
public
ToArray([bool $dummy = false ][, Closure|null $callback = null ]) : array<string|int, mixed>
Parameters
- $dummy : bool = false
-
Indicates if dummy data should be included in the array.
- $callback : Closure|null = null
-
An optional callback function to manipulate the array.
Return values
array<string|int, mixed> —The array representation of the job.
ToJSON()
Converts the object's data to a JSON string.
public
ToJSON() : string
This method serializes the object's data into a JSON string representation.
Return values
string —The JSON string representing the object's data.
Update()
Updates the job.
public
Update([string|null $startDate = null ]) : bool
Parameters
- $startDate : string|null = null
-
The start date of the job.
Return values
bool —True if the job is successfully updated, false otherwise.
UpdateOriginal()
Updates the original data with the current data of the object.
public
UpdateOriginal() : void
This method updates the original data of the object with its current data. It is typically used after modifying the object's data to synchronize the original and current states.
Validate()
Validates the object's data against a JSON schema.
public
Validate([bool $throwExceptions = false ]) : bool
This method validates the object's data against a predefined JSON schema. If the validation fails, it returns false. Optionally, you can set $throwExceptions to true to throw a ValidationException upon failure.
Parameters
- $throwExceptions : bool = false
-
Whether to throw a ValidationException upon failure.
Tags
Return values
bool —True if the object's data is valid according to the schema, false otherwise.
_typeExchange()
Handles the exchange of property values based on the specified mode.
protected
_typeExchange(string $mode, string $property[, mixed $value = null ]) : mixed
This method is responsible for managing the exchange of property values based on the specified mode ('get' or 'set'). It is used internally to retrieve or assign values to object properties dynamically.
Parameters
- $mode : string
-
The mode of operation ('get' or 'set').
- $property : string
-
The name of the property to interact with.
- $value : mixed = null
-
The value to assign to the property (only applicable in 'set' mode).
Return values
mixed —The value of the property (in 'get' mode) or null (in 'set' mode).
_typeToData()
Converts data for retrieval via the GetData method.
protected
_typeToData(mixed $data) : mixed
This method is responsible for converting data to be retrieved via the GetData method. It is intended to be overridden in subclasses to customize the conversion behavior if needed.
Parameters
- $data : mixed
-
The data to be converted.
Return values
mixed —The converted data.