Factory for producing the correct model based on the type or data within a payload
◆ getByObject()
static coarnotify\factory\COARNotifyFactory::getByObject |
( |
array | $data, |
|
|
| ... ) |
|
static |
Get an instance of a model based on the data provided.
Internally this calls getByTypes
to determine the class to instantiate, and then creates an instance of that Using the supplied args and kwargs.
If a model cannot be found that matches the data, a NotifyException is raised.
- Parameters
-
array | $data | The raw stream data to parse and instantiate around |
| mixed | ...$args Any args to pass to the object constructor |
- Returns
- NotifyPattern A NotifyPattern of the correct type, wrapping the data
- Exceptions
-
NotifyException | If a model cannot be found that matches the data |
◆ getByTypes()
static coarnotify\factory\COARNotifyFactory::getByTypes |
( |
| $incomingTypes | ) |
|
|
static |
Get the model class based on the supplied types. The returned callable is the class, not an instance.
This is achieved by inspecting all of the known types in MODELS
, and performing the following calculation:
- If the supplied types are a subset of the model types, then this is a candidate, keep a reference to it
- If the candidate fit is exact (supplied types and model types are the same), return the class
- If the class is a better fit than the last candidate, update the candidate. If the fit is exact, return the class
- Once we have run out of models to check, return the best candidate (or None if none found)
- Parameters
-
string | array | $incomingTypes | A single type or list of types. If a list is provided, ALL types must match a candidate |
- Returns
- A class representing the best fit for the supplied types, or null if no match
◆ register()
static coarnotify\factory\COARNotifyFactory::register |
( |
string | $model | ) |
|
|
static |
Register a new model class with the factory.
- Parameters
-
string | $model | The model class to register |
The documentation for this class was generated from the following file:
- src/factory/COARNotifyFactory.php