# Source for file Schema.php

Documentation is available at Schema.php

1. <?php
2. /*
3. * $Id: Schema.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
24. *
25. * Different methods to import a XML 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. abstract class Doctrine_Import_Schema
41. {
42. /**
43. * parse
44. *
45. * Function to do the actual parsing of the file
46. *
47. * @param string $schema
48. * @return void
49. * @author Jonathan H. Wage
50. */
52. abstract function parse($schema);
54. /**
55. * Parse the schema and return it in an array
56. *
57. * @param string $schema
58. * @access public
59. */
60. abstract function parseSchema($schema);
62. /**
63. * importSchema
64. *
65. * A method to import a Schema and translate it into a Doctrine_Record object
66. *
67. * @param string $schema The file containing the XML schema
68. * @param string $directory The directory where the Doctrine_Record class will
69. * be written
70. * @access public
71. */
72. public function importSchema($schema, $directory)
73. {
74. $builder = new Doctrine_Import_Builder();
75. $builder->setTargetPath($directory);
77. $array = $this->parseSchema($schema);
79. foreach ($array as $name => $properties) {
80. $options['className'] = $properties['class'];
81. $options['fileName'] = $directory.DIRECTORY_SEPARATOR.$properties['class'].'.class.php';
83. $columns = $properties['columns'];
85. $builder->buildRecord($options, $columns, array());
86. }
87. }
88. }