This is an archived project and is no longer supported or updated by SilverStripe.
Please do not file issues or pull-requests against this repo.
If you wish to continue to develop this code yourself,
we recommend you fork it or contact the maintainers directly
(check latest commits for email addresses)., (*1)
SilverStripe Command Pattern Module
Maintainer Contact
- Rainer Spittel (Nickname: fb3rasp) - rainer (at) silverstripe (dot) com
Requirements
Documentation
The commandpattern module enables SilverStripe to decouple business logic from the MVC structure. Commands can be executed individually and have a reference to a calling controller., (*2)
To install this module, please clone this module, copy the commands folder
into the root folder of the SilverStripe installation and run a dev/build, i.e.:, (*3)
http://localhost/silverstripe/dev/build, (*4)
The module consists of a Factory-class which will be used to request command
actions. The factory class initiates the command and returns the command
object to the calling method, i.e.:, (*5)
$command = CommandFactory::get_command('Test');, (*6)
This call will return initiate a TestCommand object and returns the instance.
get_command also accepts two optional parameters:, (*7)
- first parameter is a reference to the calling controller instance (@link Controller).
- second parameter is a associated array for parameters.
Example
We want to create a command with takes two integer ('x' and 'y') values and when executing the
command, it will return the result of x * y., (*8)
First create the command class in your project folder:, (*9)
<?php
class TestCommand extends ControllerCommand {
public function execute() {
$data = $this->getParameters();
$x = $data['x'];
$y = $data['y'];
return (int)$x * (int) $y;
}
}
Installation Instructions
Add this module into your project folder (name mapping) and run a dev/build
to generate the required database schema., (*10)
Usage Overview
Implements the command pattern for SilverStripe controllers. This enables
the developers to move core business logic into a dedicated command class., (*11)
Ideal for de-coupling MVC from core business domain related logic., (*12)
Known issues
n/a, (*13)