*/ public const VALID_SCOPES = [ self::SCOPE_SIGNUP, self::SCOPE_BOOKING, self::SCOPE_BOTH ]; /** Maximum length of the title, matching the `title` VARCHAR(191) column. */ public const MAX_TITLE_LENGTH = 191; /** Maximum length of the slug, matching the `slug` VARCHAR(191) column. */ public const MAX_SLUG_LENGTH = 191; public function __construct( public readonly string $title, public readonly string $slug, public readonly ?int $currentVersionId = null, public readonly string $acceptanceScope = self::SCOPE_BOOKING, public readonly ?int $id = null, ) {} public static function fromRow( \stdClass $row ): self { return new self( title: Val::string( $row->title ), slug: Val::string( $row->slug ), currentVersionId: Val::intOrNull( $row->current_version_id ), acceptanceScope: Val::string( $row->acceptance_scope ), id: Val::int( $row->id ), ); } /** * Whether this policy must be accepted in the given gate (`signup` or `booking`). */ public function appliesTo( string $scope ): bool { return $this->acceptanceScope === $scope || self::SCOPE_BOTH === $this->acceptanceScope; } /** * Returns a plain array representation of the policy. * * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'title' => $this->title, 'slug' => $this->slug, 'current_version_id' => $this->currentVersionId, 'acceptance_scope' => $this->acceptanceScope, ]; } }