EntityInterface.php 6.7 KB

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