StringInterface.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace Drupal\locale;
  3. /**
  4. * Defines the locale string interface.
  5. */
  6. interface StringInterface {
  7. /**
  8. * Gets the string unique identifier.
  9. *
  10. * @return int
  11. * The string identifier.
  12. */
  13. public function getId();
  14. /**
  15. * Sets the string unique identifier.
  16. *
  17. * @param int $id
  18. * The string identifier.
  19. *
  20. * @return $this
  21. */
  22. public function setId($id);
  23. /**
  24. * Gets the string version.
  25. *
  26. * @return string
  27. * Version identifier.
  28. */
  29. public function getVersion();
  30. /**
  31. * Sets the string version.
  32. *
  33. * @param string $version
  34. * Version identifier.
  35. *
  36. * @return $this
  37. */
  38. public function setVersion($version);
  39. /**
  40. * Gets plain string contained in this object.
  41. *
  42. * @return string
  43. * The string contained in this object.
  44. */
  45. public function getString();
  46. /**
  47. * Sets the string contained in this object.
  48. *
  49. * @param string $string
  50. * String to set as value.
  51. *
  52. * @return $this
  53. */
  54. public function setString($string);
  55. /**
  56. * Splits string to work with plural values.
  57. *
  58. * @return array
  59. * Array of strings that are plural variants.
  60. */
  61. public function getPlurals();
  62. /**
  63. * Sets this string using array of plural values.
  64. *
  65. * Serializes plural variants in one string glued by
  66. * \Drupal\Component\Gettext\PoItem::DELIMITER.
  67. *
  68. * @param array $plurals
  69. * Array of strings with plural variants.
  70. *
  71. * @return $this
  72. */
  73. public function setPlurals($plurals);
  74. /**
  75. * Gets the string storage.
  76. *
  77. * @return \Drupal\locale\StringStorageInterface
  78. * The storage used for this string.
  79. */
  80. public function getStorage();
  81. /**
  82. * Sets the string storage.
  83. *
  84. * @param \Drupal\locale\StringStorageInterface $storage
  85. * The storage to use for this string.
  86. *
  87. * @return $this
  88. */
  89. public function setStorage($storage);
  90. /**
  91. * Checks whether the object is not saved to storage yet.
  92. *
  93. * @return bool
  94. * TRUE if the object exists in the storage, FALSE otherwise.
  95. */
  96. public function isNew();
  97. /**
  98. * Checks whether the object is a source string.
  99. *
  100. * @return bool
  101. * TRUE if the object is a source string, FALSE otherwise.
  102. */
  103. public function isSource();
  104. /**
  105. * Checks whether the object is a translation string.
  106. *
  107. * @return bool
  108. * TRUE if the object is a translation string, FALSE otherwise.
  109. */
  110. public function isTranslation();
  111. /**
  112. * Sets an array of values as object properties.
  113. *
  114. * @param array $values
  115. * Array with values indexed by property name.
  116. * @param bool $override
  117. * (optional) Whether to override already set fields, defaults to TRUE.
  118. *
  119. * @return $this
  120. */
  121. public function setValues(array $values, $override = TRUE);
  122. /**
  123. * Gets field values that are set for given field names.
  124. *
  125. * @param array $fields
  126. * Array of field names.
  127. *
  128. * @return array
  129. * Array of field values indexed by field name.
  130. */
  131. public function getValues(array $fields);
  132. /**
  133. * Gets location information for this string.
  134. *
  135. * Locations are arbitrary pairs of type and name strings, used to store
  136. * information about the origins of the string, like the file name it
  137. * was found on, the path on which it was discovered, etc.
  138. *
  139. * A string can have any number of locations since the same string may be
  140. * found on different places of Drupal code and configuration.
  141. *
  142. * @param bool $check_only
  143. * (optional) Set to TRUE to get only new locations added during the
  144. * current page request and not loading all existing locations.
  145. *
  146. * @return array
  147. * Location ids indexed by type and name.
  148. */
  149. public function getLocations($check_only = FALSE);
  150. /**
  151. * Adds a location for this string.
  152. *
  153. * @param string $type
  154. * Location type that may be any arbitrary string. Types used in Drupal
  155. * core are: 'javascript', 'path', 'code', 'configuration'.
  156. * @param string $name
  157. * Location name. Drupal path in case of online discovered translations,
  158. * file path in case of imported strings, configuration name for strings
  159. * that come from configuration, etc.
  160. *
  161. * @return $this
  162. */
  163. public function addLocation($type, $name);
  164. /**
  165. * Checks whether the string has a given location.
  166. *
  167. * @param string $type
  168. * Location type.
  169. * @param string $name
  170. * Location name.
  171. *
  172. * @return bool
  173. * TRUE if the string has a location with this type and name.
  174. */
  175. public function hasLocation($type, $name);
  176. /**
  177. * Saves string object to storage.
  178. *
  179. * @return $this
  180. *
  181. * @throws \Drupal\locale\StringStorageException
  182. * In case of failures, an exception is thrown.
  183. */
  184. public function save();
  185. /**
  186. * Deletes string object from storage.
  187. *
  188. * @return $this
  189. *
  190. * @throws \Drupal\locale\StringStorageException
  191. * In case of failures, an exception is thrown.
  192. */
  193. public function delete();
  194. }