PHP Classes

File: src/ResponseReference.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Workflow   src/ResponseReference.php   Download  
File: src/ResponseReference.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,247 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;

use
Chevere\Workflow\Interfaces\ResponseReferenceInterface;
use
InvalidArgumentException;

final class
ResponseReference implements ResponseReferenceInterface
{
    public function
__construct(
        private
string $job,
        private ?
string $key = null,
    ) {
       
$this->assertArgument($job, 100);
        if (
$key === null) {
            return;
        }
       
$this->assertArgument($key, 101);
    }

    public function
__toString(): string
   
{
        return
match ($this->key) {
           
null => $this->job,
            default =>
"{$this->job}:{$this->key}",
        };
    }

    public function
job(): string
   
{
        return
$this->job;
    }

    public function
key(): ?string
   
{
        return
$this->key;
    }

    private function
assertArgument(string $argument, int $code): void
   
{
        if (
ctype_space($argument) || empty($argument)) {
            throw new
InvalidArgumentException(code: $code);
        }
    }
}