EntityInterface.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. interface EntityInterface extends ArrayAccess, JsonSerializable
  23. {
  24. /**
  25. * Sets one or multiple properties to the specified value
  26. *
  27. * @param string|array $property the name of property to set or a list of
  28. * properties with their respective values
  29. * @param mixed $value The value to set to the property or an array if the
  30. * first argument is also an array, in which case will be treated as $options
  31. * @param array $options options to be used for setting the property. Allowed option
  32. * keys are `setter` and `guard`
  33. * @return \Cake\Datasource\EntityInterface
  34. */
  35. public function set($property, $value = null, array $options = []);
  36. /**
  37. * Returns the value of a property by name
  38. *
  39. * @param string $property the name of the property to retrieve
  40. * @return mixed
  41. */
  42. public function &get($property);
  43. /**
  44. * Returns whether this entity contains a property named $property
  45. * regardless of if it is empty.
  46. *
  47. * @param string $property The property to check.
  48. * @return bool
  49. */
  50. public function has($property);
  51. /**
  52. * Removes a property or list of properties from this entity
  53. *
  54. * @param string|array $property The property to unset.
  55. * @return \Cake\ORM\
  56. */
  57. public function unsetProperty($property);
  58. /**
  59. * Get/Set the hidden properties on this entity.
  60. *
  61. * If the properties argument is null, the currently hidden properties
  62. * will be returned. Otherwise the hidden properties will be set.
  63. *
  64. * @param null|array $properties Either an array of properties to hide or null to get properties
  65. * @return array|\Cake\DataSource\EntityInterface
  66. */
  67. public function hiddenProperties($properties = null);
  68. /**
  69. * Get/Set the virtual properties on this entity.
  70. *
  71. * If the properties argument is null, the currently virtual properties
  72. * will be returned. Otherwise the virtual properties will be set.
  73. *
  74. * @param null|array $properties Either an array of properties to treat as virtual or null to get properties
  75. * @return array|\Cake\DataSource\EntityInterface
  76. */
  77. public function virtualProperties($properties = null);
  78. /**
  79. * Get the list of visible properties.
  80. *
  81. * @return array A list of properties that are 'visible' in all representations.
  82. */
  83. public function visibleProperties();
  84. /**
  85. * Returns an array with all the properties that have been set
  86. * to this entity
  87. *
  88. * @return array
  89. */
  90. public function toArray();
  91. /**
  92. * Returns an array with the requested properties
  93. * stored in this entity, indexed by property name
  94. *
  95. * @param array $properties list of properties to be returned
  96. * @param bool $onlyDirty Return the requested property only if it is dirty
  97. * @return array
  98. */
  99. public function extract(array $properties, $onlyDirty = false);
  100. /**
  101. * Sets the dirty status of a single property. If called with no second
  102. * argument, it will return whether the property was modified or not
  103. * after the object creation.
  104. *
  105. * When called with no arguments it will return whether or not there are any
  106. * dirty property in the entity
  107. *
  108. * @param string $property the field to set or check status for
  109. * @param null|bool $isDirty true means the property was changed, false means
  110. * it was not changed and null will make the function return current state
  111. * for that property
  112. * @return bool whether the property was changed or not
  113. */
  114. public function dirty($property = null, $isDirty = null);
  115. /**
  116. * Sets the entire entity as clean, which means that it will appear as
  117. * no properties being modified or added at all. This is an useful call
  118. * for an initial object hydration
  119. *
  120. * @return void
  121. */
  122. public function clean();
  123. /**
  124. * Returns whether or not this entity has already been persisted.
  125. * This method can return null in the case there is no prior information on
  126. * the status of this entity.
  127. *
  128. * If called with a boolean it will set the known status of this instance,
  129. * true means that the instance is not yet persisted in the database, false
  130. * that it already is.
  131. *
  132. * @param bool $new true if it is known this instance was persisted
  133. * @return bool if it is known whether the entity was already persisted
  134. * null otherwise
  135. */
  136. public function isNew($new = null);
  137. /**
  138. * Sets the error messages for a field or a list of fields. When called
  139. * without the second argument it returns the validation
  140. * errors for the specified fields. If called with no arguments it returns
  141. * all the validation error messages stored in this entity.
  142. *
  143. * When used as a setter, this method will return this entity instance for method
  144. * chaining.
  145. *
  146. * @param string|array $field The field to get errors for.
  147. * @param string|array|null $errors The errors to be set for $field
  148. * @param bool $overwrite Whether or not to overwrite pre-existing errors for $field
  149. * @return array|\Cake\Datasource\EntityInterface
  150. */
  151. public function errors($field = null, $errors = null, $overwrite = false);
  152. /**
  153. * Stores whether or not a property value can be changed or set in this entity.
  154. * The special property '*' can also be marked as accessible or protected, meaning
  155. * that any other property specified before will take its value. For example
  156. * `$entity->accessible('*', true)` means that any property not specified already
  157. * will be accessible by default.
  158. *
  159. * @param string|array $property Either a single or list of properties to change its accessibility.
  160. * @param bool|null $set true marks the property as accessible, false will
  161. * mark it as protected.
  162. * @return \Cake\Datasource\EntityInterface|bool
  163. */
  164. public function accessible($property, $set = null);
  165. }