# Source for file Yml.php

Documentation is available at Yml.php

1. <?php
2. /*
3. * $Id: Yml.php 1838 2007-06-26 00:58:21Z nicobn $
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. */
22. /**
23. * class Doctrine_Import_Schema_Yml
24. *
25. * Different methods to import a YML schema. The logic behind using two different
26. * methods is simple. Some people will like the idea of producing Doctrine_Record
27. * objects directly, which is totally fine. But in fast and growing application,
28. * table definitions tend to be a little bit more volatile. importArr() can be used
29. * to output a table definition in a PHP file. This file can then be stored
30. * independantly from the object itself.
31. *
32. * @package Doctrine
33. * @category Object Relational Mapping
34. * @link www.phpdoctrine.com
35. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
36. * @version $Revision: 1838 $
37. * @author Nicolas Bérard-Nault <nicobn@gmail.com>
38. * @author Jonathan H. Wage <jonwage@gmail.com>
39. */
40. class Doctrine_Import_Schema_Yml extends Doctrine_Import_Schema
41. {
42. /**
43. * parse
44. *
45. * @param string $schema
46. * @return void
47. */
48. public function parse($schema)
49. {
50. if (!is_readable($schema)) {
51. throw new Doctrine_Import_Exception('Could not read schema file '. $schema);
52. }
54. return array();
55. }
57. /**
58. * parseSchema
59. *
60. * A method to parse a Yml Schema and translate it into a property array.
61. * The function returns that property array.
62. *
63. * @param string $schema Path to the file containing the XML schema
64. * @return array
65. */
66. public function parseSchema($schema)
67. {
68. $array = $this->parse($schema);
70. $tables = array();
72. // Not working yet
73. /*
74. // Go through all tables...
75. foreach ($array['table'] as $table) {
76. // Go through all columns...
77. foreach ($table['declaration']['field'] as $field) {
78. $colDesc = array(
79. 'name' => (string) $field['name'],
80. 'type' => (string) $field['type'],
81. 'ptype' => (string) $field['type'],
82. 'length' => (int) $field['length'],
83. 'fixed' => (int) $field['fixed'],
84. 'unsigned' => (bool) $field['unsigned'],
85. 'primary' => (bool) (isset($field['primary']) && $field['primary']),
86. 'default' => (string) $field['default'],
87. 'notnull' => (bool) (isset($field['notnull']) && $field['notnull']),
88. 'autoinc' => (bool) (isset($field['autoincrement']) && $field['autoincrement']),
89. );
91. $columns[(string) $field['name']] = $colDesc;
92. }
94. $tables[(string) $table['name']] = $columns;
95. }
96. */
98. return $tables;
99. }
100. }