Download the PHP package willdurand/propel-statemachine-behavior without Composer

On this page you can find all versions of the php package willdurand/propel-statemachine-behavior. 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 propel-statemachine-behavior

StateMachineBehavior

Build Status

This behavior adds a finite state machine to your model.

Configuration

The state_machine behavior requires three parameters to work:

Each transition has to follow this pattern:

STATE_1 to STATE_2 with SYMBOL

A symbol, which is part of the Finite State Machine's terminology, can be considered as an event triggered on your model object.

The timestampable option can be added to log in the_given_state_at column the date when the state is setted

 ActiveRecord API

The behavior will generate the following constants which represent the available states of your object:

You can get the current state of your object:

getState()

Or get an array with all available states:

getAvailableStates()

Most of the time, you would like to display these states. Thanks to two convenient methods, it's really easy:

getHumanizedState() // 'Draft', or 'Rejected', or 'Unpublished', or 'Published'

ObjectModel::getHumanizedStates()
// array(
//  0 => 'Draft',
//  1 => 'Rejected',
//  2 => 'Unpublished',
//  3 => 'Published',
// )

The behavior will also generate a set of issers:

isDraft()

isRejected()

isPublished()

isUnpublished()

But the most interesting part is the implemenation of the FSM itself. First you have methods to determine whether you can perform, or not a transition based on the current model's state:

canPublish()

canReject()

canUnpublish()

It will also generate a set of methods for each symbol:

publish(PropelPDO $con = null)

unpublish(PropelPDO $con = null)

reject(PropelPDO $con = null)

To handle custom logic, new hooks are created. The methods below should return a boolean value, and can act as guards (which is not part of the FSM's terminology).

prePublish(PropelPDO $con = null)

preUnpublish(PropelPDO $con = null)

preReject(PropelPDO $con = null)

The methods below should contain your own logic depending on each state, and your business.

onPublish(PropelPDO $con = null)

onUnpublish(PropelPDO $con = null)

onReject(PropelPDO $con = null)

The methods below allow to execute code once the transition is executed.

postPublish(PropelPDO $con = null)

postUnpublish(PropelPDO $con = null)

postReject(PropelPDO $con = null)

ActiveQuery API

To be defined.

Usage

Let's say we have a Post model class which represents an entry in a blog engine. When we create a new post, its initial state is draft because we don't want to publish it immediately. As a draft, you can decide to publish your new post. Its state is now published. Once published, you may want to unpublish it for some reasons. Then, its state is unpublished. The last possibily is to republish an unpublished post. The new state is published.

We have three different states (draft, published, unpublished), and three transitions:

We can define the following configuration:

Here is a workflow:

Now imagine we have authors linked to each post, and once a post is published, we notify the post's author by email. Thanks to new hooks, it's really easy to extend things:

Use case in a controller:

Known Limitations

At the moment, there is no built-in solution to handle these cases.

Combining Archivable Behavior

The Archivable behavior is useful to copy a model object to an archival table. In other words, it acts as a soft delete behavior but with better performance.

In your workflow, you may want to destroy your object for some reason. I say "destroy" because you can't use the deleted status, nor the delete symbol, but it doesn't matter. Destroying an object is fine, but instead of hard deleting it, you may want to soft delete it. That means you will rely on the archivable behavior.

Just add it to your XML schema, rebuild both SQL, and model classes, and you're done. At first glance, when you destroy your object, you will expect it to be hidden, but it's not the case. It just has the destroyed state.

Just call the delete() termination method as usual, and your object will be automatically archived. No much to do.


All versions of propel-statemachine-behavior with dependencies

PHP Build Version
Package Version
Requires php Version >=5.2.4
propel/propel1 Version ~1.6
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 willdurand/propel-statemachine-behavior contains the following files

Loading the files please wait ....