当前位置: 首页>>代码示例>>PHP>>正文


PHP Doctrine_Parser类代码示例

本文整理汇总了PHP中Doctrine_Parser的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Parser类的具体用法?PHP Doctrine_Parser怎么用?PHP Doctrine_Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Doctrine_Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doImport

 /**
  * doImport
  *
  * @return void
  */
 public function doImport()
 {
     $directory = $this->getDirectory();
     $array = array();
     if ($directory !== null) {
         foreach ((array) $directory as $dir) {
             $e = explode('.', $dir);
             // If they specified a specific yml file
             if (end($e) == 'yml') {
                 $array = array_merge($array, Doctrine_Parser::load($dir, $this->getFormat()));
                 // If they specified a directory
             } else {
                 if (is_dir($dir)) {
                     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY);
                     foreach ($it as $file) {
                         $e = explode('.', $file->getFileName());
                         if (in_array(end($e), $this->getFormats())) {
                             $array = array_merge($array, Doctrine_Parser::load($file->getPathName(), $this->getFormat()));
                         }
                     }
                 }
             }
         }
     }
     $this->_loadData($array);
 }
开发者ID:kirvin,项目名称:the-nerdery,代码行数:31,代码来源:Import.php

示例2: execute

 /**
  * @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']);
 }
开发者ID:yasirgit,项目名称:afids,代码行数:34,代码来源:sfDoctrineBuildModelTask.class.php

示例3: testI18nExport

 public function testI18nExport()
 {
     try {
         $i = new I18nTestExport();
         $i->Translation['en']->title = 'english test';
         $i->Translation['fr']->title = 'french test';
         $i->test_object = new stdClass();
         $i->save();
         $data = new Doctrine_Data();
         $data->exportData('test.yml', 'yml', array('I18nTestExport', 'I18nTestExportTranslation'));
         $array = Doctrine_Parser::load('test.yml', 'yml');
         $this->assertTrue(!empty($array));
         $this->assertTrue(isset($array['I18nTestExport']['I18nTestExport_1']));
         $this->assertTrue(isset($array['I18nTestExportTranslation']['I18nTestExportTranslation_1_en']));
         $this->assertTrue(isset($array['I18nTestExportTranslation']['I18nTestExportTranslation_1_fr']));
         $i->Translation->delete();
         $i->delete();
         Doctrine_Core::loadData('test.yml');
         $q = Doctrine_Query::create()->from('I18nTestExport e')->leftJoin('e.Translation t');
         $results = $q->execute();
         $this->assertEqual(get_class($results[0]->test_object), 'stdClass');
         $this->pass();
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
     if (file_exists('test.yml')) {
         unlink('test.yml');
     }
 }
开发者ID:kaakshay,项目名称:audience-insight-repository,代码行数:29,代码来源:ExportTestCase.php

示例4: doParsing

 /**
  * Do the parsing of the yaml files and return the final parsed array
  *
  * @return array $array
  */
 public function doParsing()
 {
     $recursiveMerge = Doctrine_Manager::getInstance()->getAttribute('recursive_merge_fixtures');
     $mergeFunction = $recursiveMerge === true ? 'array_merge_recursive' : 'array_merge';
     $directory = $this->getDirectory();
     $array = array();
     if ($directory !== null) {
         foreach ((array) $directory as $dir) {
             $e = explode('.', $dir);
             // If they specified a specific yml file
             if (end($e) == 'yml') {
                 $array = $mergeFunction($array, Doctrine_Parser::load($dir, $this->getFormat()));
                 // If they specified a directory
             } else {
                 if (is_dir($dir)) {
                     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY);
                     foreach ($it as $file) {
                         $e = explode('.', $file->getFileName());
                         if (in_array(end($e), $this->getFormats())) {
                             $array = $mergeFunction($array, Doctrine_Parser::load($file->getPathName(), $this->getFormat()));
                         }
                     }
                 }
             }
         }
     }
     return $array;
 }
开发者ID:Esleelkartea,项目名称:legedia-ESLE,代码行数:33,代码来源:Import.php

示例5: execute

 /**
  * @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'))));
 }
开发者ID:silky,项目名称:littlesis,代码行数:36,代码来源:sfDoctrineBuildModelTask.class.php

示例6: testI18nExport

    public function testI18nExport()
    {
        try {
            $i = new I18nTestExport();
            $i->Translation['en']->title = 'english test';
            $i->Translation['fr']->title = 'french test';
            $i->save();
            $i->free();

            $data = new Doctrine_Data();
            $data->exportData('test.yml', 'yml', array('I18nTestExport', 'I18nTestExportTranslation'));

            $array = Doctrine_Parser::load('test.yml', 'yml');

            $this->assertTrue( ! empty($array));
            $this->assertTrue(isset($array['I18nTestExport']['I18nTestExport_1']));
            $this->assertTrue(isset($array['I18nTestExportTranslation']['I18nTestExportTranslation_1_en']));
            $this->assertTrue(isset($array['I18nTestExportTranslation']['I18nTestExportTranslation_1_fr']));

            $this->pass();
        } catch (Exception $e) {
            $this->fail($e->getMessage());
        }

        if (file_exists('test.yml')) {
            unlink('test.yml');
        }
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:28,代码来源:ExportTestCase.php

示例7: _printResults

 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);
         }
     }
 }
开发者ID:arenatournament,项目名称:geek-land,代码行数:12,代码来源:Dql.php

示例8: printResults

 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);
         }
     }
 }
开发者ID:kirvin,项目名称:the-nerdery,代码行数:14,代码来源:Dql.php

示例9: loadModels

 protected function loadModels()
 {
     // todo : fix this part to load model from the plugins ...
     $basePath = $this->generatorManager->getConfiguration()->getRootDir();
     $schemas = sfFinder::type('file')->name('*.yml')->in($basePath . '/config/doctrine');
     foreach ($schemas as $schema) {
         $data = Doctrine_Parser::load($schema, 'yml');
         $models = array();
         foreach ($data as $model => $definition) {
             try {
                 Doctrine::getTable($model)->getTableName();
                 $models[] = $model;
             } catch (Exception $e) {
             }
         }
         $this->models = $models;
     }
 }
开发者ID:rande,项目名称:sfAmfPlugin,代码行数:18,代码来源:sfAmfPluginDoctrineGenerator.class.php

示例10: exportSchema

 /**
  * 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);
 }
开发者ID:JimmyVB,项目名称:Symfony-v1.2,代码行数:16,代码来源:Schema.php

示例11: importFrom

 /**
  * Import data to a Doctrine_Collection from one of the supported Doctrine_Parser formats
  *
  * @param string $type 
  * @param string $data 
  * @return void
  */
 public function importFrom($type, $data)
 {
     if ($type == 'array') {
         return $this->fromArray($data);
     } else {
         return $this->fromArray(Doctrine_Parser::load($data, $type));
     }
 }
开发者ID:stelaireri,项目名称:Hive,代码行数:15,代码来源:Collection.php

示例12: testLoadFromString

 public function testLoadFromString()
 {
     $yml = "---\ntest: good job\ntest2: true\ntesting: <?php echo 'false'.\"\n\"; ?>\nw00t: not now\n";
     $array = Doctrine_Parser::load($yml, 'yml');
     $this->assertEqual($array, array('test' => 'good job', 'test2' => true, 'testing' => false, 'w00t' => 'not now'));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:6,代码来源:ParserTestCase.php

示例13: doParsing

    /**
     * Do the parsing of the yaml files and return the final parsed array
     *
     * @return array $array
     */
    public function doParsing()
    {
        $recursiveMerge = Doctrine_Manager::getInstance()->getAttribute(Doctrine_Core::ATTR_RECURSIVE_MERGE_FIXTURES);
        $mergeFunction = $recursiveMerge === true ? 'array_merge_recursive':'array_merge';
        $directory = $this->getDirectory();

        $array = array();

        if ($directory !== null) {
            foreach ((array) $directory as $dir) {
                $e = explode('.', $dir);

                // If they specified a specific yml file
                if (end($e) == 'yml') {
                    $array = $mergeFunction($array, Doctrine_Parser::load($dir, $this->getFormat()));
                // If they specified a directory
                } else if (is_dir($dir)) {
                    $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
                                                            RecursiveIteratorIterator::LEAVES_ONLY);
                    $filesOrdered = array();
                    foreach ($it as $file) {
                        $filesOrdered[] = $file;
                    }
                    // force correct order
                    natcasesort($filesOrdered);
                    foreach ($filesOrdered as $file) {
                        $e = explode('.', $file->getFileName());
                        if (in_array(end($e), $this->getFormats())) {
                            $array = $mergeFunction($array, Doctrine_Parser::load($file->getPathName(), $this->getFormat()));
                        }
                    }
                }
            }
        }

        return $array;
    }
开发者ID:niieani,项目名称:nandu,代码行数:42,代码来源:Import.php

示例14: dumpData

 /**
  * 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);
         }
     }
 }
开发者ID:amitesh-singh,项目名称:Enlightenment,代码行数:34,代码来源:Export.php

示例15: parseSchema

 /**
  * parseSchema
  *
  * A method to parse a Schema and translate it into a property array.
  * The function returns that property array.
  *
  * @param  string $schema   Path to the file containing the schema
  * @param  string $type     Format type of the schema we are parsing
  * @return array  $build    Built array of schema information
  */
 public function parseSchema($schema, $type)
 {
     $defaults = array('abstract' => false, 'className' => null, 'tableName' => null, 'connection' => null, 'relations' => array(), 'indexes' => array(), 'attributes' => array(), 'templates' => array(), 'actAs' => array(), 'options' => array(), 'package' => null, 'inheritance' => array(), 'detect_relations' => false);
     $array = Doctrine_Parser::load($schema, $type);
     // Loop over and build up all the global values and remove them from the array
     $globals = array();
     foreach ($array as $key => $value) {
         if (in_array($key, self::$_globalDefinitionKeys)) {
             unset($array[$key]);
             $globals[$key] = $value;
         }
     }
     // Merge the globals that aren't specifically set to each class
     foreach ($array as $className => $table) {
         $array[$className] = Doctrine_Lib::arrayDeepMerge($globals, $array[$className]);
     }
     $build = array();
     foreach ($array as $className => $table) {
         $table = (array) $table;
         $this->_validateSchemaElement('root', array_keys($table), $className);
         $columns = array();
         $className = isset($table['className']) ? (string) $table['className'] : (string) $className;
         if (isset($table['inheritance']['keyField']) || isset($table['inheritance']['keyValue'])) {
             $table['inheritance']['type'] = 'column_aggregation';
         }
         if (isset($table['tableName']) && $table['tableName']) {
             $tableName = $table['tableName'];
         } else {
             if (isset($table['inheritance']['type']) && $table['inheritance']['type'] == 'column_aggregation') {
                 $tableName = null;
             } else {
                 $tableName = Doctrine_Inflector::tableize($className);
             }
         }
         $connection = isset($table['connection']) ? $table['connection'] : 'current';
         $columns = isset($table['columns']) ? $table['columns'] : array();
         if (!empty($columns)) {
             foreach ($columns as $columnName => $field) {
                 // Support short syntax: my_column: integer(4)
                 if (!is_array($field)) {
                     $original = $field;
                     $field = array();
                     $field['type'] = $original;
                 }
                 $colDesc = array();
                 if (isset($field['name'])) {
                     $colDesc['name'] = $field['name'];
                 } else {
                     $colDesc['name'] = $columnName;
                 }
                 $this->_validateSchemaElement('column', array_keys($field), $className . '->columns->' . $colDesc['name']);
                 // Support short type(length) syntax: my_column: { type: integer(4) }
                 $e = explode('(', $field['type']);
                 if (isset($e[0]) && isset($e[1])) {
                     $colDesc['type'] = $e[0];
                     $value = substr($e[1], 0, strlen($e[1]) - 1);
                     $e = explode(',', $value);
                     $colDesc['length'] = $e[0];
                     if (isset($e[1]) && $e[1]) {
                         $colDesc['scale'] = $e[1];
                     }
                 } else {
                     $colDesc['type'] = isset($field['type']) ? (string) $field['type'] : null;
                     $colDesc['length'] = isset($field['length']) ? (int) $field['length'] : null;
                     $colDesc['length'] = isset($field['size']) ? (int) $field['size'] : $colDesc['length'];
                 }
                 $colDesc['fixed'] = isset($field['fixed']) ? (int) $field['fixed'] : null;
                 $colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']) : null;
                 $colDesc['default'] = isset($field['default']) ? $field['default'] : null;
                 $colDesc['autoincrement'] = isset($field['autoincrement']) ? (bool) (isset($field['autoincrement']) && $field['autoincrement']) : null;
                 if (isset($field['sequence'])) {
                     if (true === $field['sequence']) {
                         $colDesc['sequence'] = $tableName;
                     } else {
                         $colDesc['sequence'] = (string) $field['sequence'];
                     }
                 } else {
                     $colDesc['sequence'] = null;
                 }
                 $colDesc['values'] = isset($field['values']) ? (array) $field['values'] : null;
                 // Include all the specified and valid validators in the colDesc
                 $validators = Doctrine_Manager::getInstance()->getValidators();
                 foreach ($validators as $validator) {
                     if (isset($field[$validator])) {
                         $colDesc[$validator] = $field[$validator];
                     }
                 }
                 $columns[(string) $columnName] = $colDesc;
             }
         }
//.........这里部分代码省略.........
开发者ID:sensorsix,项目名称:app,代码行数:101,代码来源:Schema.php


注:本文中的Doctrine_Parser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。