Download the PHP package salesrender/plugin-core-macros without Composer
On this page you can find all versions of the php package salesrender/plugin-core-macros. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download salesrender/plugin-core-macros
More information about salesrender/plugin-core-macros
Files in salesrender/plugin-core-macros
Package plugin-core-macros
Short Description SalesRender plugin macros core
License proprietary
Informations about the package plugin-core-macros
Plugin Core Macros
Type-specific core framework for SalesRender macros plugins
Overview
salesrender/plugin-core-macros is the core package for building MACROS type plugins on the SalesRender platform.
Macros plugins perform bulk operations on orders -- they process orders in batches, enabling mass data export, import,
field manipulation, status changes, and other automated workflows.
The key distinction of macros plugins from other types is batch processing: the ability to iterate over a set of orders (defined by filters, sort, and pagination) and apply operations to each one, tracking progress, errors, and results.
This package extends the base salesrender/plugin-core by:
- Adding batch HTTP routes (prepare, configure, run, status) via
WebAppFactory - Adding batch CLI commands (queue processing, batch handling) via
ConsoleAppFactory - Enabling CORS support by default in
WebAppFactory - Requiring the developer to implement
BatchHandlerInterfacefor order processing logic
Installation
Requirements:
- PHP >= 7.4
- Extensions:
ext-json
Dependencies:
salesrender/plugin-core^0.4.1salesrender/plugin-component-purpose^2.0
Architecture
How This Core Extends plugin-core
plugin-core-macros provides two factory classes in the SalesRender\Plugin\Core\Macros\Factories namespace:
WebAppFactory
The macros WebAppFactory automatically adds two feature sets before building:
- CORS support (
addCors()) -- enables cross-origin requests for all routes - Batch actions (
addBatchActions()) -- registers all batch-related HTTP routes
The addBatchActions() method (defined in the parent WebAppFactory) registers the following routes:
| Method | Path | Action | Description |
|---|---|---|---|
POST |
/protected/batch/prepare |
BatchPrepareAction |
Creates a new batch with filters, sort, and arguments |
GET |
/protected/forms/batch/{number} |
GetBatchFormAction |
Returns batch step form (1-10) |
PUT |
/protected/data/batch/{number} |
PutBatchOptionsAction |
Saves batch step options |
POST |
/protected/batch/run |
BatchRunAction |
Starts batch execution |
GET |
/process |
ProcessAction |
Returns batch process status |
GET |
/protected/autocomplete/{name} |
AutocompleteAction |
Autocomplete suggestions |
GET |
/protected/preview/table/{name} |
TablePreviewAction |
Table preview data |
GET |
/protected/preview/markdown/{name} |
MarkdownPreviewAction |
Markdown preview |
ConsoleAppFactory
The macros ConsoleAppFactory adds batch processing commands via addBatchCommands():
| Command | Class | Description |
|---|---|---|
batch:queue |
BatchQueueCommand |
Picks up queued batches and spawns handler processes |
batch:handle |
BatchHandleCommand |
Executes the batch handler for a specific batch |
These commands are also automatically registered as cron tasks (every minute) by the base ConsoleAppFactory when
a BatchContainer handler is configured.
Batch Processing Flow
The batch processing lifecycle in a macros plugin follows these steps:
What the Developer Must Implement
BatchHandlerInterface-- the core processing logic that iterates over orders and performs operations- Settings Form -- a class extending
Formfor plugin configuration - Batch Option Forms -- one or more
Formclasses for batch step configuration (up to 10 steps) - bootstrap.php -- configuration file wiring everything together
Getting Started: Creating a Macros Plugin
Step 1: Project Setup
Set up PSR-4 autoloading in composer.json:
Create the project directory structure:
Step 2: Bootstrap Configuration
Create bootstrap.php in the project root:
Key points:
- Plugin type must be
PluginType::MACROS - The fourth argument to
Info::config()is aPluginPurposeobject specifying the plugin class and entity BatchContainer::config()accepts a callable returning batch step forms and aBatchHandlerInterfaceimplementation- Available
MacrosPluginClassvalues:CLASS_EXPORTER,CLASS_HANDLER,CLASS_IMPORTER - Available
PluginEntityvalues:ENTITY_ORDER,ENTITY_UNSPECIFIED
Step 3: Implement BatchHandlerInterface
Create src/Components/MyHandler.php:
The BatchHandlerInterface has a single method:
Process lifecycle methods:
| Method | Description |
|---|---|
$process->initialize(?int $count) |
Set total order count (null for unknown). Transitions state to STATE_PROCESSING |
$process->handle() |
Increment the handled counter |
$process->skip() |
Increment the skipped counter |
$process->addError(Error $error) |
Record an error (increments failed counter, stores last 20 errors) |
$process->setState(string $state) |
Set process state (STATE_PROCESSING, STATE_POST_PROCESSING) |
$process->finish($value) |
Mark as complete. true = success, false = error, string = result URL |
$process->terminate(Error $error) |
Terminate with a fatal error |
$process->save() |
Persist current state to database |
Process states: STATE_SCHEDULED -> STATE_PROCESSING -> STATE_POST_PROCESSING -> STATE_ENDED
Batch provides:
| Method | Description |
|---|---|
$batch->getApiClient() |
Returns the API client for querying SalesRender |
$batch->getFsp() |
Returns Filters, Sort, Pagination configuration |
$batch->getOptions(int $number) |
Returns form data for batch step N |
Step 4: Create the Web Entry Point
Create public/index.php:
Note: Unlike integration plugins, macros plugins typically do not need to add custom routes. The WebAppFactory
automatically registers all necessary batch routes.
Step 5: Create the Console Entry Point
Create console.php:
Step 6: Create the Settings Form
Create src/Forms/SettingsForm.php:
Step 7: Create Batch Options Form
Create src/Forms/BatchOptionsForm.php:
Batch option forms are displayed before running the batch (steps 1-10). Return null from the BatchContainer::config
callable for steps that do not require configuration.
Step 8: Create the .env File
Create .env:
Step 9: Initialize and Deploy
The cron system is essential for macros plugins because batch processing runs asynchronously via the
batch:queue and batch:handle commands, which are automatically scheduled every minute.
HTTP Routes
Routes Added by Macros WebAppFactory
These routes are added by the macros WebAppFactory in addition to the base plugin-core routes:
| Method | Path | Auth | Description |
|---|---|---|---|
POST |
/protected/batch/prepare |
JWT | Create a new batch with FSP. Returns 409 if batch already exists |
GET |
/protected/forms/batch/{number} |
JWT | Get batch step form (1-10). Returns 425 if previous step incomplete |
PUT |
/protected/data/batch/{number} |
JWT | Save batch step options. Returns 400 on validation errors |
POST |
/protected/batch/run |
JWT | Start batch execution (sync in debug mode, async otherwise) |
GET |
/process |
No | Get batch process status by ?id={processId} |
Routes Inherited from Base plugin-core
| Method | Path | Auth | Description |
|---|---|---|---|
GET |
/info |
No | Plugin metadata |
PUT |
/registration |
No | Plugin registration |
GET |
/robots.txt |
No | Robots exclusion |
GET |
/protected/forms/settings |
JWT | Settings form definition |
GET |
/protected/data/settings |
JWT | Current settings data |
PUT |
/protected/data/settings |
JWT | Save settings data |
GET |
/protected/autocomplete/{name} |
JWT | Autocomplete handler |
GET |
/protected/preview/table/{name} |
JWT | Table preview |
GET |
/protected/preview/markdown/{name} |
JWT | Markdown preview |
POST |
/protected/upload |
JWT | File upload |
CORS headers are enabled on all routes by default.
CLI Commands
Commands Added by Macros ConsoleAppFactory
| Command | Description |
|---|---|
batch:queue |
Picks up queued batches and spawns handler processes (runs every minute via cron) |
batch:handle |
Executes the BatchHandlerInterface for a specific batch |
Commands Inherited from Base plugin-core
| Command | Description |
|---|---|
cron:run |
Runs all scheduled cron tasks |
directory:clean |
Cleans temporary directories |
db:create-tables |
Creates database tables |
db:clean-tables |
Cleans old database records |
lang:add |
Adds a new language |
lang:update |
Updates translations |
specialRequest:queue |
Processes special request queue |
specialRequest:handle |
Handles a special request |
Auto-registered Cron Tasks
The macros ConsoleAppFactory automatically registers these cron tasks (every minute):
batch:queue-- polls for queued batches and spawns handler processesspecialRequest:queue-- polls for queued special requests
Key Interfaces
BatchHandlerInterface
This is the central interface every macros plugin must implement. The handler receives:
Process $process-- tracks progress, errors, and result of the batch operationBatch $batch-- provides access to the API client, FSP (Filters/Sort/Pagination), and batch step options
The handler must:
- Call
$process->initialize($count)to set the total order count - Iterate over orders, calling
$process->handle(),$process->skip(), or$process->addError()for each - Call
$process->save()after processing each order to persist progress - Call
$process->finish($result)when done
Process
Batch
BatchContainer
PluginPurpose
MacrosPluginClass values:
MacrosPluginClass::CLASS_EXPORTER-- plugin exports order dataMacrosPluginClass::CLASS_HANDLER-- plugin processes/modifies ordersMacrosPluginClass::CLASS_IMPORTER-- plugin imports external data into orders
PluginEntity values:
PluginEntity::ENTITY_ORDER-- plugin operates on ordersPluginEntity::ENTITY_UNSPECIFIED-- entity type is unspecified
ActionInterface
Used for custom HTTP action handlers (not typically needed in macros plugins, but available).
Example Plugin
The plugin-macros-example is a comprehensive example demonstrating all features of a macros plugin.
Example Project Structure
How the Example Plugin's BatchHandler Works
From ExampleHandler.php:
Dependencies
| Package | Version | Purpose |
|---|---|---|
salesrender/plugin-core |
^0.4.1 | Base plugin framework (Slim 4 + Symfony Console) |
salesrender/plugin-component-purpose |
^2.0 | Plugin purpose/class/entity definitions |
All transitive dependencies (Slim, Symfony Console, Medoo, batch components, etc.) come from plugin-core.
See Also
- plugin-core -- Base framework for all SalesRender plugins
- plugin-core-integration -- Core for integration plugins
- plugin-core-logistic -- Core for logistic plugins
- plugin-core-chat -- Core for chat plugins
- plugin-core-pbx -- Core for PBX plugins
- plugin-macros-example -- Example macros plugin
- plugin-component-batch -- Batch processing components
- plugin-component-purpose -- Plugin purpose definitions
- plugin-component-form -- Form definitions and field types
- plugin-component-settings -- Settings storage
- plugin-component-db -- Database abstraction
- plugin-component-api-client -- SalesRender API client
All versions of plugin-core-macros with dependencies
ext-json Version *
salesrender/plugin-core Version ^0.4.1
salesrender/plugin-component-purpose Version ^2.0