TypeInterface.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.2.14
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Database;
  16. /**
  17. * Encapsulates all conversion functions for values coming from a database into PHP and
  18. * going from PHP into a database.
  19. */
  20. interface TypeInterface
  21. {
  22. /**
  23. * Casts given value from a PHP type to one acceptable by a database.
  24. *
  25. * @param mixed $value Value to be converted to a database equivalent.
  26. * @param \Cake\Database\Driver $driver Object from which database preferences and configuration will be extracted.
  27. * @return mixed Given PHP type casted to one acceptable by a database.
  28. */
  29. public function toDatabase($value, Driver $driver);
  30. /**
  31. * Casts given value from a database type to a PHP equivalent.
  32. *
  33. * @param mixed $value Value to be converted to PHP equivalent
  34. * @param \Cake\Database\Driver $driver Object from which database preferences and configuration will be extracted
  35. * @return mixed Given value casted from a database to a PHP equivalent.
  36. */
  37. public function toPHP($value, Driver $driver);
  38. /**
  39. * Casts given value to its Statement equivalent.
  40. *
  41. * @param mixed $value Value to be converted to PDO statement.
  42. * @param \Cake\Database\Driver $driver Object from which database preferences and configuration will be extracted.
  43. * @return mixed Given value casted to its Statement equivalent.
  44. */
  45. public function toStatement($value, Driver $driver);
  46. /**
  47. * Marshalls flat data into PHP objects.
  48. *
  49. * Most useful for converting request data into PHP objects,
  50. * that make sense for the rest of the ORM/Database layers.
  51. *
  52. * @param mixed $value The value to convert.
  53. * @return mixed Converted value.
  54. */
  55. public function marshal($value);
  56. /**
  57. * Returns the base type name that this class is inheriting.
  58. *
  59. * This is useful when extending base type for adding extra functionality,
  60. * but still want the rest of the framework to use the same assumptions it would
  61. * do about the base type it inherits from.
  62. *
  63. * @return string The base type name that this class is inheriting.
  64. */
  65. public function getBaseType();
  66. /**
  67. * Returns type identifier name for this object.
  68. *
  69. * @return string The type identifier name for this object.
  70. */
  71. public function getName();
  72. /**
  73. * Generate a new primary key value for a given type.
  74. *
  75. * This method can be used by types to create new primary key values
  76. * when entities are inserted.
  77. *
  78. * @return mixed A new primary key value.
  79. * @see \Cake\Database\Type\UuidType
  80. */
  81. public function newId();
  82. }