PHP code example of joselfonseca / laravel-tactician
1. Go to this page and download the library: Download joselfonseca/laravel-tactician library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Joselfonseca\LaravelTactician\CommandBusInterface;
class MyController extends BaseController
{
public function __construct(CommandBusInterface $bus)
{
$this->bus = $bus;
}
}
$bus->addHandler('SomeCommand', 'SomeHandler');
// first parameter is the class name of the command
// Second parameter is an array of input data to be mapped to the command
// Third parameter is an array of middleware class names to be added to the stack
$bus->dispatch('SomeCommand', [], []);
// Send parameters in an array of input data ...
$bus->dispatch('SomeCommand', [
'propertyOne' => 'One',
'propertyTwo' => 'Two',
'propertyThree' => 'Three',
], []);
// ... and receive them as individual parameters ...
Class SomeCommand {
public function __construct($propertyOne = 'A', $propertyTwo = 'B', $propertyThree = 'C'){
//...
}
}
// ... or receive array of input data itself
Class SomeCommand {
public function __construct(array $data = [
'propertyOne' => 'A',
'propertyTwo' => 'B',
'propertyThree' => 'C',
]){
//...
}
}
return [
// The locator to bind
'locator' => 'Joselfonseca\LaravelTactician\Locator\LaravelLocator',
// The inflector to bind
'inflector' => 'League\Tactician\Handler\MethodNameInflector\HandleInflector',
// The extractor to bind
'extractor' => 'League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor',
// The bus to bind
'bus' => 'Joselfonseca\LaravelTactician\Bus'
];
bash
php artisan vendor:publish
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.