Download the PHP package jlorente/yii2-command-handler without Composer

On this page you can find all versions of the php package jlorente/yii2-command-handler. 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 yii2-command-handler

Yii2 Command Handler

A Yii2 extension that provides the framework with the Command Design Pattern. Useful to create commands in a main process and execute them in another processes such as crons, console controllers, etc.

Installation

To install, either run

or add

to the section of your composer.json file and run the following commands from your project directory.

The last command will create the table needed to handle the command list.

Basic Usage

First at all you must include the module in your console application in order to execute the command queue processor.

./console/config/main.php

Now you can begin to create your own commands.

Example

Imagine we want multiple emails to be sent to a group of users when the admin of this group clicks a button. The process could be tedious and would increase in time the more users are in the group so our admin will have to wait until the process is finished to continue navigating over the website.

Here, we can create a command and delegate the process to an another non locking process by writting only a few lines.

Receiver

First, the Group class MUST implement \jlorente\command\base\Receiver interface and the method that will send the email to all the group users.

Command

Now we have to create the command that will execute this method. Note that the command MUST implement the \jlorente\command\base\CommandInterface or extend one of its descendants provided along with the package in order to work (\jlorente\command\base\Command for classes that extend form \yii\base\Model and \jlorente\command\db\Command for classes that implement the \yii\db\ActiveRecordInterface).

CommandMapper

Now we will create the controller action that receives the user click, creates and puts the command in the command list.

Console Controller

The console controller will process the command list and execute the commands inside it in a queue mode. You can run the console controller by using the following shell command.

Where is the name you put in the module configuration of your config file and is an optional argument to limit the number of mappers to be processed in the execution.

Maybe you want to put the execution of the action in a cronjob or something similar to be run every minute or in the interval that you want.

/etc/crontab

Advanced Usage

Behavior

Along with the package comes a behavior that can be attached to your models that creates and maps command. Continuing with the previous example, we are going to send the email to the group of users when the group changes its state property instead of having a controller action that creates and maps the command.

By doing this, the GroupSendEmailCommand will be enqueued every time the state property changes. For more configuration params see the documentation in the CommandGeneratorBehavior class.

CommandProcessor

Maybe you want to run the command queue processor by your own instead of using the provided console controller.

You can achieve this by instantiating and running the CommandProcessor class.

You can set the the way that the command processor executes the commands by selecting between queue and stack mode. By default the command processor will handle the execution in queue mode.

The run method also accept two arguments. The first one is an integer that will limit the number of commands to be processed and the second is a boolean that indicates if the erroneous commands have to be restored in the queue to be processed another time. By default the processor will try to process all the commands in the list and will restore the erroneous ones.

Further considerations

Previously I said that commands for ActiveRecord receivers have to inherit from \jlorente\command\db\Command. That's not true at all and depends of the final behavior that you want to achieve. Commands for ActiveRecord receivers could inherit from \jlorente\command\base\Command too, but the receiver of the command will store the state it had when the command was created and not the one that it has when the command will be executed. Those commands that inherit from \jlorente\command\db\Command will always fetch the ActiveRecord object from the database instead of using a copy of the object with the properties that it had when the command was created.

License

Copyright © 2015 José Lorente Martín [email protected].

Licensed under the MIT license. See LICENSE.txt for details.


All versions of yii2-command-handler with dependencies

PHP Build Version
Package Version
No informations.
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 jlorente/yii2-command-handler contains the following files

Loading the files please wait ....