public function testFacadeLoadAndDump()
 {
     Doctrine_Parser::dump(array('test' => 'good job', 'test2' => true, array('testing' => false)), 'yml', 'test.yml');
     $array = Doctrine_Parser::load('test.yml', 'yml');
     $this->assertEqual($array, array('test' => 'good job', 'test2' => true, array('testing' => false)));
     unlink('test.yml');
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->logSection('doctrine', 'generating model classes');
     $config = $this->getCliConfig();
     $this->_checkForPackageParameter($config['yaml_schema_path']);
     $tmpPath = sfConfig::get('sf_cache_dir') . DIRECTORY_SEPARATOR . 'tmp';
     if (!file_exists($tmpPath)) {
         Doctrine_Lib::makeDirectories($tmpPath);
     }
     $plugins = $this->configuration->getPlugins();
     foreach ($this->configuration->getAllPluginPaths() as $plugin => $path) {
         if (!in_array($plugin, $plugins)) {
             continue;
         }
         $schemas = sfFinder::type('file')->name('*.yml')->in($path . '/config/doctrine');
         foreach ($schemas as $schema) {
             $tmpSchemaPath = $tmpPath . DIRECTORY_SEPARATOR . $plugin . '-' . basename($schema);
             $models = Doctrine_Parser::load($schema, 'yml');
             if (!isset($models['package'])) {
                 $models['package'] = $plugin . '.lib.model.doctrine';
                 $models['package_custom_path'] = $path . '/lib/model/doctrine';
             }
             Doctrine_Parser::dump($models, 'yml', $tmpSchemaPath);
         }
     }
     $options = array('generateBaseClasses' => true, 'generateTableClasses' => true, 'packagesPath' => sfConfig::get('sf_plugins_dir'), 'packagesPrefix' => 'Plugin', 'suffix' => '.class.php', 'baseClassesDirectory' => 'base', 'baseClassName' => 'sfDoctrineRecord');
     $options = array_merge($options, sfConfig::get('doctrine_model_builder_options', array()));
     $import = new Doctrine_Import_Schema();
     $import->setOptions($options);
     $import->importSchema(array($tmpPath, $config['yaml_schema_path']), 'yml', $config['models_path']);
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $config = $this->getCliConfig();
     $pluginSchemaDirectories = glob(sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine');
     $pluginSchemas = sfFinder::type('file')->name('*.yml')->in($pluginSchemaDirectories);
     $tmpPath = sfConfig::get('sf_cache_dir') . DIRECTORY_SEPARATOR . 'tmp';
     if (!file_exists($tmpPath)) {
         Doctrine_Lib::makeDirectories($tmpPath);
     }
     foreach ($pluginSchemas as $schema) {
         $schema = str_replace('/', DIRECTORY_SEPARATOR, $schema);
         $plugin = str_replace(sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR, '', $schema);
         $e = explode(DIRECTORY_SEPARATOR, $plugin);
         $plugin = $e[0];
         $name = basename($schema);
         $tmpSchemaPath = $tmpPath . DIRECTORY_SEPARATOR . $plugin . '-' . $name;
         $models = Doctrine_Parser::load($schema, 'yml');
         if (!isset($models['package'])) {
             $models['package'] = $plugin . '.lib.model.doctrine';
         }
         Doctrine_Parser::dump($models, 'yml', $tmpSchemaPath);
     }
     $import = new Doctrine_Import_Schema();
     $import->setOption('generateBaseClasses', true);
     $import->setOption('generateTableClasses', true);
     $import->setOption('packagesPath', sfConfig::get('sf_plugins_dir'));
     $import->setOption('packagesPrefix', 'Plugin');
     $import->setOption('suffix', '.class.php');
     $import->setOption('baseClassesDirectory', 'generated');
     $import->setOption('baseClassName', 'sfDoctrineRecord');
     $import->importSchema(array($tmpPath, $config['yaml_schema_path']), 'yml', $config['models_path']);
     $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->formatSection('doctrine', 'Generated models successfully'))));
 }
Esempio n. 4
0
 protected function _printResults($array)
 {
     $yaml = Doctrine_Parser::dump($array, 'yml');
     $lines = explode("\n", $yaml);
     unset($lines[0]);
     foreach ($lines as $yamlLine) {
         $line = trim($yamlLine);
         if ($line) {
             $this->notify($yamlLine);
         }
     }
 }
Esempio n. 5
0
 protected function printResults($data)
 {
     $array = $data->toArray(true);
     $yaml = Doctrine_Parser::dump($array, 'yml');
     $lines = explode("\n", $yaml);
     unset($lines[0]);
     $lines[1] = $data->getTable()->getOption('name') . ':';
     foreach ($lines as $yamlLine) {
         $line = trim($yamlLine);
         if ($line) {
             $this->notify($yamlLine);
         }
     }
 }
Esempio n. 6
0
 /**
  * exportSchema
  *
  * @param  string $schema 
  * @param  string $directory 
  * @return string $string of data in the specified format
  * @return void
  */
 public function exportSchema($schema, $format = 'yml', $directory = null, $models = array())
 {
     $array = $this->buildSchema($directory, $models);
     if (is_dir($schema)) {
         $schema = $schema . DIRECTORY_SEPARATOR . 'schema.' . $format;
     }
     return Doctrine_Parser::dump($array, $format, $schema);
 }
Esempio n. 7
0
 /**
  * Export a Doctrine_Collection to one of the supported Doctrine_Parser formats
  *
  * @param string $type 
  * @param string $deep 
  * @return void
  */
 public function exportTo($type, $deep = false)
 {
     if ($type == 'array') {
         return $this->toArray($deep);
     } else {
         return Doctrine_Parser::dump($this->toArray($deep, true), $type);
     }
 }
Esempio n. 8
0
 /**
  * dumpData
  *
  * Dump the prepared data to the fixtures files
  *
  * @param string $array 
  * @return void
  */
 public function dumpData(array $data)
 {
     $directory = $this->getDirectory();
     $format = $this->getFormat();
     if ($this->exportIndividualFiles()) {
         if (is_array($directory)) {
             throw new Doctrine_Data_Exception('You must specify a single path to a folder in order to export individual files.');
         } else {
             if (!is_dir($directory) && is_file($directory)) {
                 $directory = dirname($directory);
             }
         }
         foreach ($data as $className => $classData) {
             if (!empty($classData)) {
                 Doctrine_Parser::dump(array($className => $classData), $format, $directory . DIRECTORY_SEPARATOR . $className . '.' . $format);
             }
         }
     } else {
         if (is_dir($directory)) {
             $directory .= DIRECTORY_SEPARATOR . 'data.' . $format;
         }
         if (!empty($data)) {
             return Doctrine_Parser::dump($data, $format, $directory);
         }
     }
 }
 protected function generateYaml($schemaPath, $directory = null, $models = array(), $modelLoading = null)
 {
     $currentProjectModels = (array) sfYaml::load($schemaPath);
     $export = new Doctrine_Export_Schema();
     $newProjectModels = $export->buildSchema($directory, $models, $modelLoading);
     $projectModels = array_merge($currentProjectModels, $newProjectModels);
     if (is_dir($schemaPath)) {
         $schemaPath = $schemaPath . DIRECTORY_SEPARATOR . 'schema.yml';
     }
     return Doctrine_Parser::dump($projectModels, 'yml', $schemaPath);
 }
 public function getFormatData($format)
 {
     $method = 'get' . ucfirst($format) . 'FormatData';
     if (method_exists($this->getContentTypeClassName(), $method)) {
         return $this->getRecord()->{$method}();
     } else {
         if (method_exists($this, $method)) {
             $data = $this->{$method}();
         } else {
             $data = $this->getDefaultFormatData();
         }
     }
     return Doctrine_Parser::dump($this->{$method}(), $format);
 }