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