namespace aw2\workflow; \aw2_library::add_service('workflow.steps.run', 'Executes workflow steps in sequence', ['func'=>'steps_run', 'namespace'=>__NAMESPACE__]); function steps_run($atts, $content=null, $shortcode) { // Validate context name is provided if(!isset($shortcode['tags_left'][0])) { throw new \InvalidArgumentException('workflow.steps.run: You must specify a context name starting with @'); } $context = $shortcode['tags_left'][0]; // Validate context starts with @ if(strpos($context, '@') !== 0) { throw new \Exception('workflow.steps.run: Context name must start with @'); } // Setup the context stack $stack_id = \aw2\call_stack\push_context('workflow', $context, $context); $call_stack = &\aw2_library::get_array_ref('call_stack', $stack_id); $call_stack['info']=array(); $info = &$call_stack['info']; $info['index'] = 0; $info['state'] = array(); $info['state']['result']=''; // Backup existing handler if any $backup_service = &\aw2_library::get_array_ref('handlers', $context); // Get workflow array using build_array $workflow = \aw2\common\build_array($atts, $content); // Validate steps exist if(!isset($workflow['steps']) || !is_array($workflow['steps'])) { throw new \Exception('workflow.steps.run: No steps defined in workflow'); } $info['steps'] = $workflow['steps']; $info['steps_count'] = count($workflow['steps']); // Execute each step $index = 0; foreach($info['steps'] as $key => &$step) { // Validate step has service if(!isset($step['service'])) { throw new \Exception("workflow.steps.run: No service defined for step $key"); } $info['index'] = $index; $info['step'] = $step; $info['key'] = $key; $service = $step['service']; $atts = array(); // Setup data for service $atts['data'] = isset($step['data']) ? $step['data'] : array(); $atts['info'] = $info; $atts['state'] = $info['state']; // Run service and update state try { $result = \aw2_library::service_run($service, $atts, null); // If service returns state, update it if(is_array($result)) { $info['state'] = $result; } } catch(\Exception $e) { throw new \Exception("workflow.steps.run: Error in step '$key' with service '$service': " . $e->getMessage()); } $index++; } \aw2\call_stack\pop_context($stack_id); // Restore existing handler if any \aw2_library::set('handlers.' . $context, $backup_service); // Return final result from state return $info['state']['@result']; } spot
Loading...
LoanTap
Bringing Dreams to Life
Instant Customized Loans for you
Apply Now

Fast and simple loans from LoanTap

Select a loan product that's best for you!

Bank of Maharashtra MSME Loan

Under the co-lending program with the Bank of Maharashtra

Medical

Medical Loan with flexible repayment to help you in difficult times

Home Renovation

Enliven your dream home with our House Owner Loan

Advance Salary

Want Salary Early? Get a Quick Loan up to 2.5x of your monthly salary

Personal / Others

Quick Approval, Minimum Documentation and Reduced outstanding every month

Rental Deposit

Let us pay the Security Deposit for you

Wedding

Marriage Loan with flexible repayment to plan your Dream Wedding

Holiday

Travel to your Dream Destination Now. Fast approval, Flexible repayment and Minimum Documentation

CreditCard TakeOver

Personal loan at half the interest rate of your Credit Card

Premium Bike

Own your Superbike with flexi-repayment Loan

Contact Us
We are happy to help you, feel free to ask your queries.
Version