PHP Classes

File: src/Exceptions/WorkflowException.php

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

 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <rodolfo@chevere.org>
 *
 * 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\Exceptions;

use Chevere\Workflow\Interfaces\JobInterface;
use Exception;
use Throwable;
use function Chevere\Message\message;

/**
 * Exception thrown by a Workflow participant.
 */
abstract class WorkflowException extends Exception
{
    /**
     * The job name that thrown the exception.
     */
    public readonly string $name;

    /**
     * The job that thrown the exception.
     */
    public readonly JobInterface $job;

    /**
     * The exception thrown by the job.
     */
    public readonly Throwable $throwable;

    public function __construct(
        string $name,
        JobInterface $job,
        Throwable $throwable,
    ) {
        $message = (string) message(
            $this->template(),
            name: $name,
            message: $throwable->getMessage(),
            caller: $job->caller()
        );
        parent::__construct(message: $message, previous: $throwable);
        $this->name = $name;
        $this->job = $job;
        $this->throwable = $throwable;
        $this->file = $job->caller()->file();
        $this->line = $job->caller()->line();
    }

    protected function template(): string
    {
        return '[%name%]: %message%';
    }
}