Workflow Instance ID Validator (Support/WorkflowInstanceId.php)

workflow · src/V2/Support/WorkflowInstanceId.php · php · MIT
dev-tools, automation, crm, lang:php, tag:validation, tag:backend

PHP utility class to validate workflow instance identifiers against formatting and length rules. Use this to ensure safe URL-compatible workflow IDs.

// Source: https://github.com/durable-workflow/workflow | License: MIT | Copyright 2022 Richard McDaniel
// Provided via justclaw.it.com; keep this notice with the code.
<?php

declare(strict_types=1);

namespace Workflow\V2\Support;

use LogicException;

final class WorkflowInstanceId
{
    public const MAX_LENGTH = 191;

    private const PATTERN = '/\A[A-Za-z0-9._:-]+\z/';

    public static function assertValid(string $instanceId): void
    {
        if (! self::isValid($instanceId)) {
            throw new LogicException(self::requirementMessage());
        }
    }

    public static function isValid(string $instanceId): bool
    {
        return $instanceId !== ''
            && strlen($instanceId) <= self::MAX_LENGTH
            && preg_match(self::PATTERN, $instanceId) === 1;
    }

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key