Ezcomponents are silently growing PHP Components Library. It contains many libraries with it. I’m gonna use one of the components called WorkFlow.
Workflow components are useful for creating business logics and manage business process easily. Here I’m gonna show you how to use this component step by step.
1. Firstly, Download the entire Components Library from here : https://ezcomponents.org/download.
2. Then, All you need to do is Unzip and upload it in your Server or Localhost!.
3. After you upload all the files on the server, Find a folder called “WorkflowDatabaseTiein”.
4. Inside the folder, Go to “design” and open the file called “schema_mysql.sql”.
5. Now open your PhpMyAdmin and create a database and name it as “ezflow”.
6. After creating the Database, import the “schema_mysql.sql” in the database “ezflow”.
7. You will see there 6 tables created in the database, they are
i. execution
ii. execution_state
iii. node
iv. node_connection
v . variable_handler
vi. workflow
Here the piece of code going to do the magic of WorkFlow, create this file in the root folder of ezcomponents.
<?php // include and register the autoloader require_once 'Base/src/base.php'; function __autoload($className) { ezcBase::autoload($className); } $workflow = new ezcWorkflow('AGR'); $getName = new ezcWorkflowNodeInput(array( 'name' => new ezcWorkflowConditionIsString() )); $sayHello = new ezcWorkflowNodeAction(array('class' => 'myServiceObject')); $workflow->startNode->addoutNode($getName); $getName->addOutNode($sayHello); $sayHello->addoutNode($workflow->endNode); // Set up database connection. $db = ezcDbFactory::create( 'mysql://root@localhost/ezflow' ); // Set up workflow definition storage (database). $definition = new ezcWorkflowDatabaseDefinitionStorage( $db ); // Save workflow definition to database. $definition->save( $workflow ); $execution = new ezcWorkflowDatabaseExecution($db); $execution->workflow = $workflow; $execution->start(); if ($execution->hasEnded()) echo "Execution has ended.n"; else echo "Execution has NOT ended?n"; ?>
Line no. 22 : You need to give your username, password and the hostname to run it properly
$db = ezcDbFactory::create( ‘mysql://username:password@hostname/database’ );
for instance, $db = ezcDbFactory::create( ‘mysql://root:root123@localhost/ezflow’ );
Run the above Program in a browser. This will create a workflow and store it in the database and also one execution will be created in the database. Check the Tables, Workflow, execution, execution_state to know what is happening.
Actually, the above program started an execution at the moment, and it is waiting for the input to end the execution. This is really useful to do the post programming.
This execution is stored in the database, so whenever we need to resume the execution may be after 1 week or 1 month we can do it by resuming it. Let see the below code to do the magic.
<?php require_once 'Base/src/base.php'; function __autoload($className) { ezcBase::autoload($className); } $db = ezcDbFactory::create( 'mysql://root@localhost/ezflow' ); $execution = new ezcWorkflowDatabaseExecution( $db, 1); class myServiceObject implements ezcWorkflowServiceObject { public function execute(ezcWorkflowExecution $execution) { $name = $execution->getVariable('name'); echo "Hello {$name}!n"; } public function __toString() { return __CLASS__; } } $execution->resume(array('name' => 'Superman')); if ($execution->hasEnded()) echo "Execution has ended.n"; else echo "Execution has NOT ended?n"; ?>
The above code will resume the progress. All you need to do is give the “execution_id” at the line no. 9
$execution = new ezcWorkflowDatabaseExecution( $db, 1);
Find the execution id in the table execution and give it in the above line (here it is ‘1’).
If you run this program. This will give the result “Hello Superman” and Execution Ended.
This is how the workflow is happening. Try and tell me what else is missing in this post!
Very Nice post. Rare found about EZComponents
This is wonderful and simple. Have you ever tried configuring ezcomponent workflow for approval workflow?. Kindly assist i need one.
Hey thanks, never tried. but i will try and tell you.
Thanks for the quick response. More so on database records i.e Leave item. Again i have been reading the documents but i can’t find where to configure workflow process of different stages.
I am getting this error, when I write database connection code
Fatal error: Class ‘ezcDbHandlerMysql’ not found in D:\xammp\htdocs\www\Database\src\factory.php on line 162
this is the code for database connection
$db = ezcDbFactory::create( $dsn = “mysql://root@localhost/code”);
$db = ezcDbFactory::create( $dsn );
Very good! Can you give a example workfolow in Zend Framework (ex: in controller/action) with ezComponent? Thanks a lot!
This is pretty much the only blogpost about out there about the ezComponents Workflow component. We are currently trying to implement a simple workflow, but one thing that is really hard to tell is if you load a workflow, which are the available options (input nodes…) so this can be displayed in the user-interface.
How to reject the workflow to the ex-steps ?