Download the PHP package diossystem/multicasting without Composer
On this page you can find all versions of the php package diossystem/multicasting. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package multicasting
Multicasting of attributes
This is when some attribute can have many types. Values, which have different types of data, storage in one column.
This does your models flexible, their instances can to use an appropriate entitym and those can have different methods and algorithms for handling data. Handling data can be completely different. This provides great possibilities for models and simplifies implementation and reading your code.
Where can I use it?
Use it in your models of Eloquent.
How to do this:
- add the traits to your model;
- configure variables (set values to variables);
- implement your handlers using the base interfaces or your own interfaces.
Example #1.1. Configuring the model
Example #1.2. Using instances
Installation
Install the package using Composer:
Setting model
Using the trait
To use these features you need to add the trait to your model.
Example #1
Interface type
The next step, you must choose an interface to implement your handlers for data of the attribute the model and configure the variables.
The default interface for initialization is .
Each interface has its own features.
The base interfaces for initialization:
- \Dios\System\Multicasting\Interfaces\IndependentEntity - it has no parameters.
- \Dios\System\Multicasting\Interfaces\SimpleSingleValueEntity - it has one parameter - one value of the model;
- \Dios\System\Multicasting\Interfaces\SimpleArrayEntity - it has one parameter - an array with values of the model;
- \Dios\System\Multicasting\Interfaces\RelatedEntity - it has one parameter - an instance of the model;
- \Dios\System\Multicasting\Interfaces\EntityWithModel it has one parameter - an instance of the model.
The base interfaces for filling:
-
\Dios\System\Multicasting\Interfaces\ArrayEntity- it is used for filling and getting an array with values.
-
\Dios\System\Multicasting\Interfaces\SingleValueEntity - it is used for assigning and getting a value;
-
\Dios\System\Multicasting\Interfaces\KeepsEntityType - it is used for assigning and getting an entity type.
- \Dios\System\Multicasting\Interfaces\KeepsAttributeName - it is used for assigning and getting an attribute name.
All these interfaces are extended from \Dios\System\Multicasting\Interfaces\MulticastingEntity.
When you need to use your own interface or another interface it must implement .
Assign your chosen interface type to in your model.
Example #2
If you uses not vendor interfaces you must extend or replace the base implementation of the function. This function implements choice an appropriate schema to initialize an instance of a class.
Example #3. Custom interfaces
To add atypical values to your instances during initialization you must extend or replace in your model.
Example #4. A custom interface to set values
Source of a type
The next step, you must assign a source to get the current type of entities. Types are obtained from your DB.
Use to assign your source.
Example #5. The double value
The package implements the two formats of sources of types:
- single value. It is the value to point at a source of types. The types may be in others tables and in the current table. If you will be to use its to get a type from another table, then keys of the types will not be cached.
- double value. It is the value to point at a source of types. The type must be in another table. The results will be cached.
Use single value
to set the source of a type from the current model.
Use double value
to set the source of a type that be in another table.
In the example #4 is used double value
: 'af.type|additional_field_id'
.
The first value is the source of a type. is the relation name and is a storage of types of allowable entities.
Handlers of entities
The next step, you must define handles of entities for allowable types.
Example #6
The and variables must contain handlers for entities. You can use one handler for different types.
The default handler is optional.
These handlers must implement the MulticastingEntity interface.
Property containing a value
You must define the variable. It contains a property of the model to get values for instances of entities (handlers). It is used during initialization an instances.
Often your property will be belong to the 'array' type.
You may use any type and values of the property will be passed to a new instance of the entity.
License: MIT