EntityInterface.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Datasource;
  16. use ArrayAccess;
  17. use JsonSerializable;
  18. /**
  19. * Describes the methods that any class representing a data storage should
  20. * comply with.
  21. *
  22. * @property mixed $id Alias for commonly used primary key.
  23. */
  24. interface EntityInterface extends ArrayAccess, JsonSerializable
  25. {
  26. /**
  27. * Sets one or multiple properties to the specified value
  28. *
  29. * @param string|array $property the name of property to set or a list of
  30. * properties with their respective values
  31. * @param mixed $value The value to set to the property or an array if the
  32. * first argument is also an array, in which case will be treated as $options
  33. * @param array $options options to be used for setting the property. Allowed option
  34. * keys are `setter` and `guard`
  35. * @return \Cake\Datasource\EntityInterface
  36. */
  37. public function set($property, $value = null, array $options = []);
  38. /**
  39. * Returns the value of a property by name
  40. *
  41. * @param string $property the name of the property to retrieve
  42. * @return mixed
  43. */
  44. public function &get($property);
  45. /**
  46. * Returns whether this entity contains a property named $property
  47. * regardless of if it is empty.
  48. *
  49. * @param string $property The property to check.
  50. * @return bool
  51. */
  52. public function has($property);
  53. /**
  54. * Removes a property or list of properties from this entity
  55. *
  56. * @param string|array $property The property to unset.
  57. * @return \Cake\ORM\
  58. */
  59. public function unsetProperty($property);
  60. /**
  61. * Get/Set the hidden properties on this entity.
  62. *
  63. * If the properties argument is null, the currently hidden properties
  64. * will be returned. Otherwise the hidden properties will be set.
  65. *
  66. * @param null|array $properties Either an array of properties to hide or null to get properties
  67. * @return array|\Cake\Datasource\EntityInterface
  68. */
  69. public function hiddenProperties($properties = null);
  70. /**
  71. * Get/Set the virtual properties on this entity.
  72. *
  73. * If the properties argument is null, the currently virtual properties
  74. * will be returned. Otherwise the virtual properties will be set.
  75. *
  76. * @param null|array $properties Either an array of properties to treat as virtual or null to get properties
  77. * @return array|\Cake\Datasource\EntityInterface
  78. */
  79. public function virtualProperties($properties = null);
  80. /**
  81. * Get the list of visible properties.
  82. *
  83. * @return array A list of properties that are 'visible' in all representations.
  84. */
  85. public function visibleProperties();
  86. /**
  87. * Returns an array with all the visible properties set in this entity.
  88. *
  89. * *Note* hidden properties are not visible, and will not be output
  90. * by toArray().
  91. *
  92. * @return array
  93. */
  94. public function toArray();
  95. /**
  96. * Returns an array with the requested properties
  97. * stored in this entity, indexed by property name
  98. *
  99. * @param array $properties list of properties to be returned
  100. * @param bool $onlyDirty Return the requested property only if it is dirty
  101. * @return array
  102. */
  103. public function extract(array $properties, $onlyDirty = false);
  104. /**
  105. * Sets the dirty status of a single property. If called with no second
  106. * argument, it will return whether the property was modified or not
  107. * after the object creation.
  108. *
  109. * When called with no arguments it will return whether or not there are any
  110. * dirty property in the entity
  111. *
  112. * @param string|null $property the field to set or check status for
  113. * @param null|bool $isDirty true means the property was changed, false means
  114. * it was not changed and null will make the function return current state
  115. * for that property
  116. * @return bool whether the property was changed or not
  117. */
  118. public function dirty($property = null, $isDirty = null);
  119. /**
  120. * Sets the entire entity as clean, which means that it will appear as
  121. * no properties being modified or added at all. This is an useful call
  122. * for an initial object hydration
  123. *
  124. * @return void
  125. */
  126. public function clean();
  127. /**
  128. * Returns whether or not this entity has already been persisted.
  129. * This method can return null in the case there is no prior information on
  130. * the status of this entity.
  131. *
  132. * If called with a boolean, this method will set the status of this instance.
  133. * Using `true` means that the instance has not been persisted in the database, `false`
  134. * that it already is.
  135. *
  136. * @param bool|null $new Indicate whether or not this instance has been persisted.
  137. * @return bool If it is known whether the entity was already persisted
  138. * null otherwise
  139. */
  140. public function isNew($new = null);
  141. /**
  142. * Sets the error messages for a field or a list of fields. When called
  143. * without the second argument it returns the validation
  144. * errors for the specified fields. If called with no arguments it returns
  145. * all the validation error messages stored in this entity.
  146. *
  147. * When used as a setter, this method will return this entity instance for method
  148. * chaining.
  149. *
  150. * @param string|array|null $field The field to get errors for.
  151. * @param string|array|null $errors The errors to be set for $field
  152. * @param bool $overwrite Whether or not to overwrite pre-existing errors for $field
  153. * @return array|\Cake\Datasource\EntityInterface
  154. */
  155. public function errors($field = null, $errors = null, $overwrite = false);
  156. /**
  157. * Stores whether or not a property value can be changed or set in this entity.
  158. * The special property `*` can also be marked as accessible or protected, meaning
  159. * that any other property specified before will take its value. For example
  160. * `$entity->accessible('*', true)` means that any property not specified already
  161. * will be accessible by default.
  162. *
  163. * @param string|array $property Either a single or list of properties to change its accessibility.
  164. * @param bool|null $set true marks the property as accessible, false will
  165. * mark it as protected.
  166. * @return \Cake\Datasource\EntityInterface|bool
  167. */
  168. public function accessible($property, $set = null);
  169. }