Something went wrong. Try again.
Laravel AT Protocol Client (alpha & unstable)
Something went wrong. Try again.
1.5 kB · 80 lines
PHP
at dev
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081<?php
namespace SocialDept\AtpClient\RichText;
use SocialDept\AtpClient\Builders\Concerns\BuildsRichText;
class TextBuilder{ use BuildsRichText;
/** * Create a new text builder instance */ public static function make(): self { return new self; }
/** * Build text using a callback */ public static function build(callable $callback): array { $builder = new self; $callback($builder);
return $builder->toArray(); }
/** * Build the final text and facets array */ public function toArray(): array { return $this->getTextAndFacets(); }
/** * Convert to JSON string */ public function toJson(int $options = 0): string { return json_encode($this->toArray(), $options); }
/** * Create from existing text with auto-detection */ public static function parse(string $text): array { return [ 'text' => $text, 'facets' => FacetDetector::detect($text), ]; }
/** * Get character count (for post limits) */ public function getCharacterCount(): int { return mb_strlen($this->text, 'UTF-8'); }
/** * Get byte count */ public function getByteCount(): int { return strlen($this->text); }
/** * Convert to string (returns text only) */ public function __toString(): string { return $this->text; }}