1. Go to this page and download the library: Download wpstarter/flow library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wpstarter / flow example snippets
namespace App\Flow\Flows;
use WpStarter\Flow\Flow;
use WpStarter\Flow\FlowRequest;
use App\Flow\Flows\OrderFlow;
class LoginFlow extends Flow{
function handle(FlowRequest $request){
// TODO: Implement handle() method.
if($this->state('is_logged_in')){
$this->redirect(OrderFlow::class);
return ['success'=>true];
}else{
if(Auth::check($request['user'],$request['pass'])){
$this->state('is_logged_in',true);
$this->redirect(OrderFlow::class);
return ['success'=>true];
}else{
return ['success'=>false,'message'=>'invalid credentials'];
}
}
}
}
$this->redirect(NextFlowClass::class)
$this->back()
$this->redirectToDefault()
class MyFlowProvider extends FlowProvider
{
public function register()
{
$this->flows->register(LoginFlow::class);
$this->flows->register(OrderFlow::class);
$this->loadRoutesFrom( __DIR__ . '/routes.php');
}
}
use \WpStarter\Flow\Support\Facades\Route;
//Run login flow when received message /login
Route::match('/login',LoginFlow::class);
//Run order flow when received message /order or /buy
Route::match(['/order','/buy'],OrderFlow::class);
use \WpStarter\Flow\Support\Facades\Route;
//Run login flow when `secret_login` is 'Abcd1234'
Route::match(function(\WpStarter\Flow\FlowRequest $request){
if($request->get('secret_login')==='Abcd1234'){
return true;
}
},LoginFlow::class);
class LoginFlow extends Flow{
protected $route='logmein';
}
Route::match('logmein',LoginFlow::class);
use WpStarter\Flow\FlowRequest;
$flowRequest=new FlowRequest([
'id'=>$request['phone_number'],
'message'=>$request->input('message'),
]);
namespace App\Http\Controllers;
use WpStarter\Flow\FlowManager;
use Illuminate\Http\Request;
class FlowController{
function index(FlowManager $flowManager, Request $request){
$flowRequest=new FlowRequest([
'id'=>Auth::id(),
'message'=>$request->input('message'),
]);
return $flowManager->run($flowRequest);
}
}
bash
php artisan vendor:publish --tag=flow-config
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.