Documentation

Tag
in package

Tag entity representing a term tag or text tag.

Tags are used to categorize words (term tags) or texts (text tags). Both types share the same structure: ID, text, and comment.

Tags
since
3.0.0

Table of Contents

Constants

MAX_COMMENT_LENGTH  = 200
Maximum length for tag comment.
MAX_TEXT_LENGTH  = 20
Maximum length for tag text.

Properties

$comment  : string
$id  : TagId
$text  : string
$type  : TagType

Methods

comment()  : string
Get the tag comment.
create()  : self
Create a new tag.
id()  : TagId
Get the tag ID.
isNew()  : bool
Check if this is an unsaved entity.
isTermTag()  : bool
Check if this is a term tag.
isTextTag()  : bool
Check if this is a text tag.
rename()  : void
Rename the tag.
text()  : string
Get the tag text.
toArray()  : array{id: int, text: string, comment: string, type: string}
Convert to array for backward compatibility.
type()  : TagType
Get the tag type.
updateComment()  : void
Update the tag comment.
__construct()  : mixed
Private constructor - use factory methods instead.
normalizeText()  : string
Normalize tag text.
validateComment()  : void
Validate tag comment.
validateText()  : void
Validate tag text.

Constants

MAX_COMMENT_LENGTH

Maximum length for tag comment.

public mixed MAX_COMMENT_LENGTH = 200

MAX_TEXT_LENGTH

Maximum length for tag text.

public mixed MAX_TEXT_LENGTH = 20

Properties

$comment

private string $comment

$text

private string $text

Methods

comment()

Get the tag comment.

public comment() : string
Return values
string

create()

Create a new tag.

public static create(TagType $type, string $text[, string $comment = '' ]) : self
Parameters
$type : TagType

Tag type (term or text)

$text : string

Tag text (max 20 chars, no spaces/commas)

$comment : string = ''

Tag comment (max 200 chars)

Tags
throws
InvalidArgumentException

If text is empty or invalid

Return values
self

isNew()

Check if this is an unsaved entity.

public isNew() : bool
Return values
bool

isTermTag()

Check if this is a term tag.

public isTermTag() : bool
Return values
bool

isTextTag()

Check if this is a text tag.

public isTextTag() : bool
Return values
bool

rename()

Rename the tag.

public rename(string $text) : void
Parameters
$text : string

New tag text

Tags
throws
InvalidArgumentException

If text is invalid

text()

Get the tag text.

public text() : string
Return values
string

toArray()

Convert to array for backward compatibility.

public toArray() : array{id: int, text: string, comment: string, type: string}
Return values
array{id: int, text: string, comment: string, type: string}

updateComment()

Update the tag comment.

public updateComment(string $comment) : void
Parameters
$comment : string

New comment

Tags
throws
InvalidArgumentException

If comment is too long

__construct()

Private constructor - use factory methods instead.

private __construct(TagId $id, TagType $type, string $text, string $comment) : mixed
Parameters
$id : TagId

Tag ID

$type : TagType

Tag type (term or text)

$text : string

Tag text

$comment : string

Tag comment

normalizeText()

Normalize tag text.

private static normalizeText(string $text) : string

Trims whitespace and removes spaces/commas (not allowed in tags).

Parameters
$text : string

Raw tag text

Return values
string

Normalized text

validateComment()

Validate tag comment.

private static validateComment(string $comment) : void
Parameters
$comment : string

The comment to validate

Tags
throws
InvalidArgumentException

If comment is too long

validateText()

Validate tag text.

private static validateText(string $text) : void
Parameters
$text : string

The text to validate

Tags
throws
InvalidArgumentException

If text is invalid


        
On this page

Search results