# Source for file DataDict.php

Documentation is available at DataDict.php

1. <?php
2. /*
3. * $Id: DataDict.php 1098 2007-02-15 11:36:43Z zYne $
4. *
5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16. *
17. * This software consists of voluntary contributions made by many individuals
18. * and is licensed under the LGPL. For more information, see
19. * <http://www.phpdoctrine.com>.
20. */
21. /**
22. * Doctrine_DataDict
23. *
24. * @package Doctrine
25. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
26. * @category Object Relational Mapping
27. * @link www.phpdoctrine.com
28. * @since 1.0
29. * @version $Revision: 1098 $
30. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
31. * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
32. */
33. class Doctrine_DataDict extends Doctrine_Connection_Module
34. {
35. /**
36. * Obtain an array of changes that may need to applied
37. *
38. * @param array $current new definition
39. * @param array $previous old definition
40. * @return array containing all changes that will need to be applied
41. */
42. public function compareDefinition($current, $previous)
43. {
44. $type = !empty($current['type']) ? $current['type'] : null;
46. if (!method_exists($this, "_compare{$type}Definition")) {
47. throw new Doctrine_DataDict_Exception('type "'.$current['type'].'" is not yet supported');
48. }
50. if (empty($previous['type']) || $previous['type'] != $type) {
51. return $current;
52. }
54. $change = $this->{"_compare{$type}Definition"}($current, $previous);
56. if ($previous['type'] != $type) {
57. $change['type'] = true;
58. }
60. $previous_notnull = !empty($previous['notnull']) ? $previous['notnull'] : false;
61. $notnull = !empty($current['notnull']) ? $current['notnull'] : false;
62. if ($previous_notnull != $notnull) {
63. $change['notnull'] = true;
64. }
66. $previous_default = array_key_exists('default', $previous) ? $previous['default'] :
67. ($previous_notnull ? '' : null);
68. $default = array_key_exists('default', $current) ? $current['default'] :
69. ($notnull ? '' : null);
70. if ($previous_default !== $default) {
71. $change['default'] = true;
72. }
74. return $change;
75. }
76. /**
77. * parseBoolean
78. * parses a literal boolean value and returns
79. * proper sql equivalent
80. *
81. * @param string $value boolean value to be parsed
82. * @return string parsed boolean value
83. */
84. public function parseBoolean($value)
85. {
86. // parse booleans
87. if ($value == 'true') {
88. $value = 1;
89. } elseif ($value == 'false') {
90. $value = 0;
91. }
92. return $value;
93. }
94. }