COAR Notify
 
Loading...
Searching...
No Matches
coarnotify\factory\COARNotifyFactory Class Reference

Static Public Member Functions

static getByTypes ($incomingTypes)
 
static getByObject (array $data,... $args)
 
static register (string $model)
 

Detailed Description

Factory for producing the correct model based on the type or data within a payload

Member Function Documentation

◆ 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$dataThe 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
NotifyExceptionIf 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:

  1. If the supplied types are a subset of the model types, then this is a candidate, keep a reference to it
  2. If the candidate fit is exact (supplied types and model types are the same), return the class
  3. If the class is a better fit than the last candidate, update the candidate. If the fit is exact, return the class
  4. Once we have run out of models to check, return the best candidate (or None if none found)
Parameters
string | array$incomingTypesA 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$modelThe model class to register

The documentation for this class was generated from the following file: