PHP Classes

File: src/Traits/WorkflowTrait.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Workflow   src/Traits/WorkflowTrait.php   Download  
File: src/Traits/WorkflowTrait.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Workflow
Create and run action workflows
Author: By
Last change:
Date: 1 month ago
Size: 1,195 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace
Chevere\Workflow\Traits;

use
BadMethodCallException;
use
Chevere\Workflow\Interfaces\RunInterface;
use
Chevere\Workflow\Interfaces\WorkflowInterface;
use function
Chevere\Workflow\run;

/**
 * Provides method `execute()` to assign `$run` property.
 * Provides method `run()` to access the `$run` property.
 */
trait WorkflowTrait // @phpstan-ignore-line
{
    private
RunInterface $run;

   
/**
     * Access the `$run` property.
     *
     * ```php
     * $this->run();
     * ```
     */
   
public function run(): RunInterface
   
{
        return
$this->run
           
??= throw new BadMethodCallException();
    }

   
/**
     * Run the given workflow with the provided arguments.
     *
     * ```php
     * $this->execute($workflow, name: 'value',...);
     * ```
     */
   
private function execute(WorkflowInterface $workflow, mixed ...$argument): void
   
{
       
$this->run = run($workflow, ...$argument);
    }
}