Download the PHP package hjp1011/yii2-workflow without Composer

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

yii2-workflow

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json file.

Quick Start

Configuration

For this "Quick start Guide" we will be using default configuration settings, but remember that yii2-workflow is designed to be highly flexible so to adapt to a lot of execution contexts... well at least that was my goal.

Create A Workflow

A workflow is defined as a PHP class that implements the \hjp1011\workflow\source\file\IWorkflowDefinitionProvider interface. which declares the getDefinition() method. This method must return an array representing the workflow definition.

Let's define a very simple workflow that will be used to manage posts in a basic blog system.

Here is the PHP class that implements the definition for our workflow :

@app/models/PostWorkflow.php

Attach To The Model

Now let's have a look to our Post model: we store the status of a post in a column named status of type STRING(40).

The last step is to associate the workflow definition with posts models. To do so we must declare the SimpleWorkflowBehavior behavior in the Post model class and let the default configuration settings do the rest.

@app/models/Post.php

That's it ! We are ready to play with SimpleWorkflowBehavior.

Use It !

Now that we are all setup, we can use the SimpleWorkflowBehavior methods to set/get the status of our posts : the SimpleWorkflowBehavior will take care that the post doesn't reach a status where it is not supposed to go to, depending on the workflow definition that we have provided.

This will print the following message :

post status is : Draft

If you do the same thing but instead of draft set the status to publish and try to save it, the following exception is thrown :

Not an initial status : PostWorkflow/publish ("PostWorkflow/draft" expected)

That's because in your workflow definition the initial status is set to draft and not publish.

Ok, one more example for the fun ! This time we are not going to perform the transition when the Post is saved (like we did in the previous example), but immediately, by invoking the sendToStatus method. Our Post is going to try to reach status publish passing through deleted which is strictly forbidden by the workflow. Will it be successful in this risky attempt to break workflow rules ?

Game Over ! There is no transition between deleted and publish, and that's what SimpleWorkflow tries to explain to our fearless post object.

Workflow Exception – hjp1011\workflow\base\WorkflowException
No transition found between status PostWorkflow/deleted and PostWorkflow/publish

Yes, that's severe, but there was many ways to avoid this exception like for instance by first validating that the transition was possible.

What's Next ?

This is just one way of using the SimpleWorkflowBehavior but there's much more and hopefully enough to assist you in workflow management inside your Yii2 web app.

You may also be interested in the following projects developed around yii2-workflow :

License

yii2-workflow is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.

Yii2


All versions of yii2-workflow with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
yiisoft/yii2 Version ~2.0.13
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 hjp1011/yii2-workflow contains the following files

Loading the files please wait ....