StringInterface.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 LOCALE_PLURAL_DELIMITER.
  66. *
  67. * @param array $plurals
  68. * Array of strings with plural variants.
  69. *
  70. * @return $this
  71. */
  72. public function setPlurals($plurals);
  73. /**
  74. * Gets the string storage.
  75. *
  76. * @return \Drupal\locale\StringStorageInterface
  77. * The storage used for this string.
  78. */
  79. public function getStorage();
  80. /**
  81. * Sets the string storage.
  82. *
  83. * @param \Drupal\locale\StringStorageInterface $storage
  84. * The storage to use for this string.
  85. *
  86. * @return $this
  87. */
  88. public function setStorage($storage);
  89. /**
  90. * Checks whether the object is not saved to storage yet.
  91. *
  92. * @return bool
  93. * TRUE if the object exists in the storage, FALSE otherwise.
  94. */
  95. public function isNew();
  96. /**
  97. * Checks whether the object is a source string.
  98. *
  99. * @return bool
  100. * TRUE if the object is a source string, FALSE otherwise.
  101. */
  102. public function isSource();
  103. /**
  104. * Checks whether the object is a translation string.
  105. *
  106. * @return bool
  107. * TRUE if the object is a translation string, FALSE otherwise.
  108. */
  109. public function isTranslation();
  110. /**
  111. * Sets an array of values as object properties.
  112. *
  113. * @param array $values
  114. * Array with values indexed by property name.
  115. * @param bool $override
  116. * (optional) Whether to override already set fields, defaults to TRUE.
  117. *
  118. * @return $this
  119. */
  120. public function setValues(array $values, $override = TRUE);
  121. /**
  122. * Gets field values that are set for given field names.
  123. *
  124. * @param array $fields
  125. * Array of field names.
  126. *
  127. * @return array
  128. * Array of field values indexed by field name.
  129. */
  130. public function getValues(array $fields);
  131. /**
  132. * Gets location information for this string.
  133. *
  134. * Locations are arbitrary pairs of type and name strings, used to store
  135. * information about the origins of the string, like the file name it
  136. * was found on, the path on which it was discovered, etc.
  137. *
  138. * A string can have any number of locations since the same string may be
  139. * found on different places of Drupal code and configuration.
  140. *
  141. * @param bool $check_only
  142. * (optional) Set to TRUE to get only new locations added during the
  143. * current page request and not loading all existing locations.
  144. *
  145. * @return array
  146. * Location ids indexed by type and name.
  147. */
  148. public function getLocations($check_only = FALSE);
  149. /**
  150. * Adds a location for this string.
  151. *
  152. * @param string $type
  153. * Location type that may be any arbitrary string. Types used in Drupal
  154. * core are: 'javascript', 'path', 'code', 'configuration'.
  155. * @param string $name
  156. * Location name. Drupal path in case of online discovered translations,
  157. * file path in case of imported strings, configuration name for strings
  158. * that come from configuration, etc.
  159. *
  160. * @return $this
  161. */
  162. public function addLocation($type, $name);
  163. /**
  164. * Checks whether the string has a given location.
  165. *
  166. * @param string $type
  167. * Location type.
  168. * @param string $name
  169. * Location name.
  170. *
  171. * @return bool
  172. * TRUE if the string has a location with this type and name.
  173. */
  174. public function hasLocation($type, $name);
  175. /**
  176. * Saves string object to storage.
  177. *
  178. * @return $this
  179. *
  180. * @throws \Drupal\locale\StringStorageException
  181. * In case of failures, an exception is thrown.
  182. */
  183. public function save();
  184. /**
  185. * Deletes string object from storage.
  186. *
  187. * @return $this
  188. *
  189. * @throws \Drupal\locale\StringStorageException
  190. * In case of failures, an exception is thrown.
  191. */
  192. public function delete();
  193. }