Download the PHP package djsharman/state without Composer

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

Changes added by Darren Sharman

This is a State machine generator based on the work of Sebastian Bergmann (thank you Sebastian).

The intent of the State design pattern is to "allow an object to alter its behavior when its internal state changes. The object will appear to change its class". The State pattern can be used, for instance, to implement a Finite State Machine efficiently and elegantly. This approach can be useful when implementing business processes or workflows.

This version differs from the original in the following ways:

Making sure your code doesn’t get overwritten

When you modify one of the functions generated by the generator be sure to move the code between the

and

comments. For an example please see onEnterState (source) function in the StartUpState.php file in the PwrCall example folder.

Implementing the generator to work with your existing code

You need to create one or more XML file to represent your state machine(s). The full XML state machine configuration is covered below. Importantly you should set the target directory targetdir where the statemachines are to be generated. This is a path relative to where you run the generator from. Also you should set the namespace that the statemachine classes will use.

You should then create a shell script (or batch file) to call the generator and, optionally, the visualizer.

The generator and visualiser take a single parameter which is the directory containing the state machine XML definition(s).

Example: Door

Consider a class Door that represents a door. A door can be in one of three states: open, closed, locked. When a Door object receives messages (such as open(), close(), lock(), or unlock()) from other objects, it responds differently depending on its current state. For example, the effect of an open() message depends on whether the door is in its closed state or not (a locked door has to be unlocked before it can be opened, for instance). The State pattern describes how a Door object can exhibit different behavior in each state. The key idea in this pattern is to introduce classes to represent the states of the door.

DoorState

The DoorState interface (source) declares an interface common to all classes that represent different states.

AbstractDoorState

The AbstractDoorState class (source) implements the operations required by the DoorState interface in such a way that all methods raise an IllegalStateTransitionException by default.

OpenDoorState, ClosedDoorState, and LockedDoorState

OpenDoorState (source), ClosedDoorState (source), and LockedDoorState (source) are child classes of AbstractDoorState that overwrite the open(), close(), lock(), and unlock() methods appropriately to return the object that represents the new state. OpenDoorState::close() returns an instance of ClosedDoorState, for instance:

Door

The Door class (source) maintains a state object (an instance of a subclass of AbstractDoorState) that represents the current state of the door:

The Door class forwards all state-specific messages to this state object. Whenever the door changes state, the Door object changes the state object it uses.

Usage Example

The example script above yields the output below:

bool(true)
bool(true)
bool(true)

Fatal error: Uncaught exception 'IllegalStateTransitionException' in AbstractDoorState.php:25
Stack trace:
#0 Door.php(35): AbstractDoorState->lock()
#1 example.php(13): Door->lock()
#2 {main}
  thrown in AbstractDoorState.php on line 25

Generating the State Machine

Using a code generator, the code shown above can be automatically generated from an XML specification such as the one shown below:

Some parts of the state machine configuration are assumed by convention.

Visualizing the State Machine

A graphical visualization of the statemachine states and its transitions can be generated based on the state machine's XML specification.

The runViz.php (source) generates representation of the state machine as a directed graph in Dot markup.

Documenting the State Machine through Tests

Using PHPUnit's TestDox functionality we can automatically generate documentation for the state machine based on its tests:

OpenDoor
 [x] Can be closed
 [x] Cannot be opened
 [x] Cannot be locked
 [x] Cannot be unlocked

ClosedDoor
 [x] Cannot be closed
 [x] Can be opened
 [x] Can be locked
 [x] Cannot be unlocked

LockedDoor
 [x] Cannot be closed
 [x] Cannot be opened
 [x] Cannot be locked
 [x] Can be unlocked

This automatically generated checklist makes it clear which transitions are allowed between the three states of the state machine.


All versions of state with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
sebastian/finder-facade Version *
djsharman/libraries Version *
phpunit/php-token-stream Version *
theseer/fdomdocument Version *
phpunit/phpunit Version 5.0.*
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 djsharman/state contains the following files

Loading the files please wait ....