Git Product home page Git Product logo

laravel-tactician's Introduction

Laravel Tactician

Laravel Tactician in an implementation of the Command Bus Tactician by Ross Tuck.

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

##Installation

To install this update your composer.json file to require

    "joselfonseca/laravel-tactician" : "0.2.*"

Once the dependencies have been downloaded, add the service provider to your config/app.php file

    'providers' => [
        ...
        Joselfonseca\LaravelTactician\Providers\LaravelTacticianServiceProvider::class
        ...
    ]

You are done with the installation!

##Usage

To use the command bus you can resolve the bus from the laravel container like so

    $bus = app('Joselfonseca\LaravelTactician\CommandBusInterface');

Or you can inject it into a class constructor

    
    use Joselfonseca\LaravelTactician\CommandBusInterface;
    
    class MyController extends BaseController
    {
        
        public function __construct(CommandBusInterface $bus)
        {
            $this->bus = $bus;
        }
        
    }
    

Once you have the bus instance you can add your handler for the command to be dispatched

    $bus->addHandler('SomeCommand', 'SomeHandler');

Now you can dispatch the command with the middleware.

    // 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', [], []);

For more information about the usage of the tactician command bus please visit http://tactician.thephpleague.com/

Example

Check out this example of the package implemented in a simple create order command https://gist.github.com/joselfonseca/24ee0e96666a06b16f92

##Bindings

You can configure the bindings for the locator, inflector, extractor and default bus publishing the config file like so

    php artisan vendor:publish 

Then you can modify each class name and they will be resolved from the laravel container

    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'
    ];

##Tests

To run the test in this package, navigate to the root folder of the project and run

    composer install

Then

    vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email jose at ditecnologia dot com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-tactician's People

Contributors

joselfonseca avatar

Watchers

Tim Broder avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.