*/ public array $variables; /** * Describe a pattern. * * @param string $code Pattern code. * @param string $text Approved text, with the provider's placeholder syntax. * @param list $variables Variable names. * @param string $status Provider wording, e.g. `active`; empty when unknown. * @param string $title The name the store gave it in the panel, when it has one. * @param string $label The provider's own status wording for people, e.g. «رد شده». */ public function __construct( public string $code, public string $text, array $variables, public string $status = '', public string $title = '', public string $label = '' ) { $this->variables = array_values( array_unique( array_filter( $variables, static fn( string $name ): bool => '' !== $name ) ) ); } /** * Can messages be sent with it? `active` is the approved state by * convention; a driver maps its provider's wording onto it. */ public function isActive(): bool { return 'active' === $this->status; } /** * Plain data, for the admin screens' scripts. * * @return array{code: string, text: string, variables: list, status: string, title: string, label: string, active: bool} */ public function toArray(): array { return [ 'code' => $this->code, 'text' => $this->text, 'variables' => $this->variables, 'status' => $this->status, 'title' => $this->title, 'label' => $this->label, 'active' => $this->isActive(), ]; } }