name ) ) { throw new DomainException( 'category.name_empty', 'Category name must not be empty.' ); } if ( '' === trim( $this->slug ) ) { throw new DomainException( 'category.slug_empty', 'Category slug must not be empty.' ); } if ( null !== $this->parent_id && $this->parent_id < 1 ) { throw new DomainException( 'category.parent_id', 'parent_id must be positive when set.' ); } } /** * Database id. * * @since 0.1.0 */ public function id(): ?int { return $this->id; } /** * Public UUID. * * @since 0.1.0 */ public function uuid(): Uuid { return $this->uuid; } /** * Parent id. * * @since 0.1.0 */ public function parent_id(): ?int { return $this->parent_id; } /** * Name. * * @since 0.1.0 */ public function name(): string { return $this->name; } /** * Slug. * * @since 0.1.0 */ public function slug(): string { return $this->slug; } /** * Description. * * @since 0.1.0 */ public function description(): ?string { return $this->description; } /** * Image id. * * @since 0.1.0 */ public function image_id(): ?int { return $this->image_id; } /** * Sort order. * * @since 0.1.0 */ public function sort_order(): int { return $this->sort_order; } /** * Created at. * * @since 0.1.0 */ public function created_at(): DateTimeImmutable { return $this->created_at; } /** * Updated at. * * @since 0.1.0 */ public function updated_at(): DateTimeImmutable { return $this->updated_at; } /** * Assign the database id after insert. * * @param int $id New id. * * @throws \Bookline\Domain\Shared\DomainException When id is already set or invalid. * * @since 0.1.0 */ public function assign_id( int $id ): void { if ( null !== $this->id ) { throw new DomainException( 'category.id_assigned', 'Category id is already assigned.' ); } $this->id = $id; } }