Download the PHP package studioignis/cmd without Composer

On this page you can find all versions of the php package studioignis/cmd. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cmd

Build Status Packagist Version Packagist Downloads Packagist License

StudioIgnis Cmd

Easily implement command based architecture in your project.

Inspired by laracasts/commander

Installation

Install through composer by adding the package to your composer.json

Or using the command:

Usage

It is really simple, you just need the command bus instance, then you can start executing commands! You can bootstrap the instance manually or use included Laravel service provider.

Manual bootstrapping

You'll need an implementation of \StudioIgnis\Cmd\Support\Container and \StudioIgnis\Cmd\NameInflector.

You'll have to create your own container implementation, since this will depend on your framework. You can take a look at the included Laravel implementation to see how it can be implemented, it's extremely simple.

For the name inflector, on the other hand, you can use the one included \StudioIgnis\Cmd\DefaultNameInflector, or you can create your own.

Using Laravel

If you are using the Laravel framework, you can take advantage of the included service provider. You will need to add it to the providers array in your app/config/app.php file:

Now you can just use dependency injection to get the command bus, like so:

Handlers

Handlers are as complex as you need them to be, they just need to implement the StudioIgnis\Cmd\Handler interface.

This interface defines only one method, handle(Command $command), that as you can see, receives the corresponding command instance.

Let's see an (oversimplified) example:

Automatic handler resolving

There's no need to register handlers for commands, as the default name inflector will take care of it as long as the namespaces are predictable.

The inflector takes the command class name and replaces all occurences of "Command" with "Handler", so for example Acme\User\Command\CreateUser will result in a handler Acme\User\Handler\CreateUser.

You don't have to follow this namespace convention, since all it does is word replacement, just be aware of what would the handler counterpart of a command will end up being.

Set handlers manually

Another, less magical but sometimes preferred, way is by manually registering handlers per command:

This way you don't have to predict where would a handler end up, you just tell the bus where to find it.

As you can see in the example above, we are passing the handler's FQN string. By doing this, the command bus will use the container to resolve the handler, thus, lazy-loading it. Another way to lazy-load a handler is by passing a closure that returns a handler instance. Or you can just pass an already instantiated handler.

Commands

Command classes are simple DTOs, but they must extend from the abstract StudioIgnis\Cmd\Command. This abstract base class ease things up a bit.

Your commands should define an array of attributes that you'll be able to get automatically, without defining getters.

This base command class also ensures the command can be converted to an array and serialized to json.

Here's an example:

Now you can access the attributes like this:

Executing commands

One you have your command bus instance ready and your handlers registered (or not!), executing commands is really easy. Let's use the command we defined above.

Traits

There are two traits you can use to make command execution a little shorter. One is generic, the other one is exclusively for Laravel.

StudioIgnis\Cmd\CmdTrait

This trait adds the cmd($commandName, array $input) mehtod. It's purpose is to initialize a command a little easier by passing the command class name and an array of inputs that will be used as the command parameters:

StudioIgnis\Cmd\Laravel\CmdTrait

This trait uses the previous one so you can just add this trait.
It adds three new methods: execute($commandName, array $input = null), getInput(array $input = null) and getCommandBus().

The idea is the same, but it also executes the command by calling the other trait's cmd() method.

getInput(array $input = null) will return Laravel's Input::all() if no $input is given.

getCommandBus() will return App::make('StudioIgnis\Cmd\Bus');

Both of these methods can be overriden if you don't want to use the "facade" invocation.

License

Copyright (c) 2014 Luciano Longo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


All versions of cmd with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
illuminate/support Version >=4.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package studioignis/cmd contains the following files

Loading the files please wait ....