I18nValue.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. class I18nValue {
  3. private const STATE_DIRTY = 'dirty';
  4. private const STATE_IGNORE = 'ignore';
  5. private const STATE_TODO = 'todo';
  6. private const STATES = [
  7. self::STATE_DIRTY,
  8. self::STATE_IGNORE,
  9. self::STATE_TODO,
  10. ];
  11. private $value;
  12. private $state;
  13. public function __construct(string $data) {
  14. $data = explode(' -> ', $data);
  15. $this->value = array_shift($data);
  16. if (count($data) === 0) {
  17. return;
  18. }
  19. $state = array_shift($data);
  20. if (in_array($state, self::STATES)) {
  21. $this->state = $state;
  22. }
  23. }
  24. public function __clone() {
  25. $this->markAsTodo();
  26. }
  27. public function equal(I18nValue $value) {
  28. return $this->value === $value->getValue();
  29. }
  30. public function isIgnore() {
  31. return $this->state === self::STATE_IGNORE;
  32. }
  33. public function isTodo() {
  34. return $this->state === self::STATE_TODO;
  35. }
  36. public function markAsDirty() {
  37. $this->state = self::STATE_DIRTY;
  38. }
  39. public function markAsIgnore() {
  40. $this->state = self::STATE_IGNORE;
  41. }
  42. public function markAsTodo() {
  43. $this->state = self::STATE_TODO;
  44. }
  45. public function unmarkAsIgnore() {
  46. if ($this->state === self::STATE_IGNORE) {
  47. $this->state = null;
  48. }
  49. }
  50. public function __toString() {
  51. if ($this->state === null) {
  52. return $this->value;
  53. }
  54. return "{$this->value} -> {$this->state}";
  55. }
  56. public function getValue() {
  57. return $this->value;
  58. }
  59. }