{"id":14966609,"url":"https://github.com/raoul2000/yii2-workflow","last_synced_at":"2025-04-05T05:08:25.188Z","repository":{"id":27792329,"uuid":"31281264","full_name":"raoul2000/yii2-workflow","owner":"raoul2000","description":"A simple workflow engine for Yii2","archived":false,"fork":false,"pushed_at":"2018-06-08T11:52:36.000Z","size":2210,"stargazers_count":172,"open_issues_count":1,"forks_count":48,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-29T04:09:59.618Z","etag":null,"topics":["php","status","transition","workflow","yii2","yii2-extension"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raoul2000.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGE.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-24T20:50:35.000Z","updated_at":"2025-03-07T23:01:56.000Z","dependencies_parsed_at":"2022-08-09T21:40:09.530Z","dependency_job_id":null,"html_url":"https://github.com/raoul2000/yii2-workflow","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raoul2000%2Fyii2-workflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raoul2000%2Fyii2-workflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raoul2000%2Fyii2-workflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raoul2000%2Fyii2-workflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raoul2000","download_url":"https://codeload.github.com/raoul2000/yii2-workflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289428,"owners_count":20914464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","status","transition","workflow","yii2","yii2-extension"],"created_at":"2024-09-24T13:36:41.070Z","updated_at":"2025-04-05T05:08:25.151Z","avatar_url":"https://github.com/raoul2000.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yii2-workflow\n\n[![Build](https://travis-ci.org/raoul2000/yii2-workflow.svg?branch=master)](https://travis-ci.org/raoul2000/yii2-workflow)\n[![Latest Stable Version](https://poser.pugx.org/raoul2000/yii2-workflow/v/stable)](https://packagist.org/packages/raoul2000/yii2-workflow)\n[![Total Downloads](https://poser.pugx.org/raoul2000/yii2-workflow/downloads)](https://packagist.org/packages/raoul2000/yii2-workflow)\n[![License](https://poser.pugx.org/raoul2000/yii2-workflow/license)](https://packagist.org/packages/raoul2000/yii2-workflow)\n\n## Installation\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist raoul2000/yii2-workflow \"*\"\n```\n\nor add\n\n```\n\"raoul2000/yii2-workflow\": \"*\"\n```\n\nto the require section of your `composer.json` file.\n\n# Quick Start\n\n## Configuration\n\nFor this \"*Quick start Guide*\" we will be using **default configuration settings**, but remember that *yii2-workflow* is designed to be highly\nflexible so to adapt to a lot of execution contexts... well at least that was my goal.\n\n## Create A Workflow\n\nA workflow is defined as a PHP class that implements the `\\raoul2000\\workflow\\source\\file\\IWorkflowDefinitionProvider` interface. which\ndeclares the *getDefinition()* method. This method must return an array representing the workflow definition.\n\nLet's define a very *simple workflow* that will be used to manage posts in a basic blog system.\n\n\u003cimg src=\"guide/docs/images/workflow1.png\"/\u003e\n\nHere is the PHP class that implements the definition for our workflow :\n\n`@app/models/PostWorkflow.php`\n```php\nnamespace app\\models;\n\nclass PostWorkflow implements \\raoul2000\\workflow\\source\\file\\IWorkflowDefinitionProvider\n{\n\tpublic function getDefinition() {\n\t\treturn [\n\t\t\t'initialStatusId' =\u003e 'draft',\n\t\t\t'status' =\u003e [\n\t\t\t\t'draft' =\u003e [\n\t\t\t\t\t'transition' =\u003e ['publish','deleted']\n\t\t\t\t],\n\t\t\t\t'publish' =\u003e [\n\t\t\t\t\t'transition' =\u003e ['draft','deleted']\n\t\t\t\t],\n\t\t\t\t'deleted' =\u003e [\n\t\t\t\t\t'transition' =\u003e ['draft']\n\t\t\t\t]\n\t\t\t]\n\t\t];\n\t}\n}\n```\n\n## Attach To The Model\n\nNow 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).\n\nThe last step is to associate the workflow definition with posts models. To do so we must declare the *SimpleWorkflowBehavior* behavior\nin the Post model class and let the default configuration settings do the rest.\n\n`@app/models/Post.php`\n```php\nnamespace app\\models;\n/**\n * @property integer $id\n * @property string $title\n * @property string $body\n * @property string $status column used to store the status of the post\n */\nclass Post extends \\yii\\db\\ActiveRecord\n{\n    public function behaviors()\n    {\n    \treturn [\n\t\t\t\\raoul2000\\workflow\\base\\SimpleWorkflowBehavior::className()\n    \t];\n    }\n    // ...\n```\n\nThat's it ! We are ready to play with *SimpleWorkflowBehavior*.\n\n## Use It !\n\nNow that we are all setup, we can use the *SimpleWorkflowBehavior* methods to set/get the status of our posts : the *SimpleWorkflowBehavior* will\ntake 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.\n\n```php\n$post = new Post();\n$post-\u003estatus = 'draft';\n$post-\u003esave();\necho 'post status is : '. $post-\u003eworkflowStatus-\u003elabel;\n```\nThis will print the following message :\n\n\tpost status is : Draft\n\nIf you do the same thing but instead of *draft* set the status to *publish* and try to save it, the following exception is thrown :\n\n\tNot an initial status : PostWorkflow/publish (\"PostWorkflow/draft\" expected)\n\nThat's because in your workflow definition the **initial status** is  set to *draft* and not *publish*.\n\nOk, 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\nexample), but immediately, by invoking the `sendToStatus` method. Our Post is going to try to reach status *publish* passing through *deleted*\nwhich is strictly forbidden by the workflow. Will it be successful in this risky attempt to break workflow rules ?   \n\n```php\n$post = new Post();\n$post-\u003esendToStatus('draft');\n$post-\u003esendToStatus('deleted');\n$post-\u003esendToStatus('publish');\t// danger zone !\n```\n\nGame Over ! There is no transition between *deleted* and *publish*, and that's what *SimpleWorkflow* tries to explain to our\nfearless post object.\n\n\tWorkflow Exception – raoul2000\\workflow\\base\\WorkflowException\n\tNo transition found between status PostWorkflow/deleted and PostWorkflow/publish\n\nYes, that's severe, but there was many ways to avoid this exception like for instance by first validating that the transition was possible.\n\n## What's Next ?\n\nThis 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.\n\nYou will find additional information there :\n\n- [yii2-workflow Usage Guide](http://raoul2000.github.io/yii2-workflow/)\n- [yii2-workflow Class Reference](http://raoul2000.github.io/yii2-workflow/class-ref/)\n- [Demo](http://raoul2000.ass-team.fr/index.php?r=workflow/status-history/update) : a simple example based on the *Post* use case.\n\nYou may also be interested in the following projects developed around yii2-workflow :\n\n- [yii2-workflow-view](https://github.com/raoul2000/yii2-workflow-view) : A Widget to display workflows ([demo](http://raoul2000.ass-team.fr/index.php?r=workflow/status-history/update))\n- [yii2-workflow-manager](https://github.com/cornernote/yii2-workflow-manager) : A Module to manage workflows\n- [yii2-wizflow](https://github.com/raoul2000/yii2-wizflow) : a proof of concept that mixes the Wizard UI pattern with workflow ([Demo](http://raoul2000.ass-team.fr/index.php?r=workflow/wizflow/init))\n- ..and more to come\n\nLicense\n-------\n\n**yii2-workflow** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.\n\n[![Yii2](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](http://www.yiiframework.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraoul2000%2Fyii2-workflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraoul2000%2Fyii2-workflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraoul2000%2Fyii2-workflow/lists"}