escolalms / templates
Escola Headless LMS templates (for eg Certificates)
Installs: 15 844
Dependents: 8
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=7.4 | >=8.0
- doctrine/dbal: ^2|^3
- escolalms/core: ^1.2
- escolalms/settings: ^0
- fakerphp/faker: ^1
- laravel/framework: >=8.0
Requires (Dev)
- escolalms/cart: ^0
- escolalms/courses: ^0
- orchestra/testbench: ^5|^6
- phpunit/phpunit: ^9.0
- dev-main
- 0.2.37
- 0.2.36
- 0.2.35
- 0.2.34
- 0.2.33
- 0.2.32
- 0.2.31
- 0.2.30
- 0.2.29
- 0.2.28
- 0.2.27
- 0.2.26
- 0.2.25
- 0.2.24
- 0.2.23
- 0.2.22
- 0.2.21
- 0.2.20
- 0.2.19
- 0.2.18
- 0.2.17
- 0.2.16
- 0.2.15
- 0.2.14
- 0.2.13
- 0.2.12
- 0.2.11
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-feature/admin-readme
- dev-feature/readme
- dev-bugfix/pagination-on-templates-list
- dev-feature/94
- dev-feature/filter-template-list-by-channel-or-event
- dev-feature/refactored-assigning-templates-to-models
This package is auto-updated.
Last update: 2024-12-22 08:03:52 UTC
README
Purpose
General purpose of this package is to store various templates in database and assigning them to Events so that content based on these templates is automatically generated and/or sent to users.
Usage
Each template is defined by
channel
: class defining how the template is handledevent
: event to which the template is assigned
For every channel & event pair a single Variables definition is registered, which contains tokens that can be used in the template and replaced with values based on the data from the Event.
Analysing these three example files in tests:
- TestChannel.php
- TestVariables.php
- TestEventWithGetters.php
and looking at the Template
facade is simplest way to understand how this package works.
Facade
There is a Template
facade declared, which is used to register Event-Channel-Variable sets and can be used in testing (as it can be replaced with a fake using Template::fake()
).
To register Event-Channel-Variable set, Template::register($eventClass, $channelClass, $variableClass)
must be called, where:
$eventClass
can be any class that is dispatched as an event in any EscolaLms package$channelClass
must be a class implementingTemplateChannelContract
interface declared in this package$variableClass
must be a class implementingTemplateVariableContract
interface declared in this package
Channels & variables
This package has no Channels or Variables defined, everything should be created in separate packages.
Event Wrapper
EscolaLms\Templates\Events\EventWrapper
is a class that wraps any event before trying to generate notification for it (and feed data from it to Template). This class contains methods for extracting necessary data from Event if that data is not available directly (for example User to which notification is being sent, and any other data that is required by registered Template).
Endpoints
All the endpoints are defined in
Tests
Run ./vendor/bin/phpunit --filter 'EscolaLms\\Templates\\Tests'
to run tests. See tests folder as it's quite good staring point as documentation appendix.
Listeners
EscolaLms\Templates\Listeners\TemplateEventListener
this listeners listens to allEscolaLms
namespace events, checks if event is registered for any Template, and passes the event wrapped inEventWrapper
to processing (so if event is registered and has corresponding Template, notification using that Template will be sent)