Trac

Show
Ignore:
Timestamp:
06/13/08 07:30:02 (5 months ago)
Author:
jasoneisen
Message:

Changes for tickets #1128, #1129, #1135, #1136, #1137

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jason/lib/Doctrine.php

    r4496 r4515  
    776776 
    777777    /** 
     778     * generateArrayFromSchema 
     779     * 
     780     * Generates array from schema files 
     781     * 
     782     * @param string $schema Directory or schema file 
     783     * @param string $format Format of schema 
     784     * @return array 
     785     */ 
     786    public static function generateArrayFromSchema($schema, $format) 
     787    { 
     788        $array = array(); 
     789        $parser = Doctrine_Parser::getParser($format); 
     790 
     791        foreach ((array) $schema AS $s) { 
     792            if (is_file($s)) { 
     793                $array = array_merge($array, $parser->loadData($s)); 
     794            } else if (is_dir($s)) { 
     795                $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($s), 
     796                                                      RecursiveIteratorIterator::LEAVES_ONLY); 
     797 
     798                foreach ($it as $file) { 
     799                    $e = explode('.', $file->getFileName()); 
     800                    if (end($e) === $format) { 
     801                        $array = array_merge($array, $parser->loadData($file->getPathName())); 
     802                    } 
     803                } 
     804            } else { 
     805              $array = array_merge($array, $parser->loadData($s)); 
     806            } 
     807        } 
     808 
     809        return $array; 
     810    } 
     811 
     812    /** 
     813     * generateYamlFromXml 
     814     * 
     815     * Generates yaml schema to specified directory from xml schema files 
     816     * 
     817     * @param string $yamlPath Directory or yaml file 
     818     * @param string $xmlPath Directory or xml file 
     819     * @return void 
     820     */ 
     821    public static function generateYamlFromXml($yamlPath, $xmlPath, $options = array()) 
     822    { 
     823        $array = Doctrine::generateArrayFromSchema($xmlPath, 'xml'); 
     824 
     825        if (is_dir($yamlPath)) { 
     826            $yamlPath = $yamlPath . DIRECTORY_SEPARATOR . 'schema.yml'; 
     827        } 
     828 
     829        return Doctrine_Parser::dump($array, 'yml', $yamlPath); 
     830    } 
     831 
     832    /** 
     833     * generateXmlFromYaml 
     834     * 
     835     * Generates xml schema to specified directory from xml schema files 
     836     * 
     837     * @param string $xmlPath Directory or xml file 
     838     * @param string $yamlPath Directory or yaml file 
     839     * @return void 
     840     */ 
     841    public static function generateXmlFromYaml($xmlPath, $yamlPath, $options = array()) 
     842    { 
     843        $array = Doctrine::generateArrayFromSchema($yamlPath, 'yml'); 
     844 
     845        if (is_dir($xmlPath)) { 
     846            $xmlPath = $xmlPath . DIRECTORY_SEPARATOR . 'schema.xml'; 
     847        }     
     848 
     849        return Doctrine_Parser::dump($array, 'xml', $xmlPath); 
     850    } 
     851 
     852    /** 
     853         * generateModelsFromXml 
     854         * 
     855         * Generates models to specified directory from xml schema files 
     856         * 
     857         * @param string $xmlPath Path to your xml schema files 
     858         * @param string $directory Directory to generate your models in 
     859         * @param array  $options Array of options to pass to the schema importer 
     860         * @return void 
     861         */ 
     862    public static function generateModelsFromXml($xmlPath, $directory, $options = array()) 
     863    { 
     864        $import = new Doctrine_Import_Schema(); 
     865        $import->setOptions($options); 
     866 
     867        return $import->importSchema($xmlPath, 'xml', $directory); 
     868    } 
     869 
     870    /** 
    778871     * Creates database tables for the models in the specified directory 
    779872     * 
  • branches/experimental/jason/lib/Doctrine/Parser/Xml.php

    r3884 r4515  
    7070 
    7171                $this->arrayToXml($value, $rootNodeName, $node); 
     72            } elseif (is_int($key)) { 
     73 
     74                $xml->addChild($value, 'true'); 
    7275            } else { 
    7376                $value = htmlentities($value);