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


PHP sfLoader::getModelDirs方法代码示例

本文整理汇总了PHP中sfLoader::getModelDirs方法的典型用法代码示例。如果您正苦于以下问题:PHP sfLoader::getModelDirs方法的具体用法?PHP sfLoader::getModelDirs怎么用?PHP sfLoader::getModelDirs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfLoader的用法示例。


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

示例1: loadMapBuilderClasses

  /**
   * Loads map builder classes.
   *
   * This method is ORM dependant.
   *
   * @throws sfException
   */
  protected function loadMapBuilderClasses()
  {
    // we must load all map builder classes to be able to deal with foreign keys (cf. editSuccess.php template)
    $classes = sfFinder::type('file')->ignore_version_control()->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
    foreach ($classes as $class)
    {
      $class_map_builder = basename($class, '.php');
      $maps[$class_map_builder] = new $class_map_builder();
      if (!$maps[$class_map_builder]->isBuilt())
      {
        $maps[$class_map_builder]->doBuild();
      }

      if ($this->className == str_replace('MapBuilder', '', $class_map_builder))
      {
        $this->map = $maps[$class_map_builder];
      }
    }
    if (!$this->map)
    {
      throw new sfException('The model class "'.$this->className.'" does not exist.');
    }

    $this->tableMap = $this->map->getDatabaseMap()->getTable(constant($this->className.'Peer::TABLE_NAME'));
  }
开发者ID:jonphipps,项目名称:Metadata-Registry,代码行数:32,代码来源:sfPropelCrudGenerator.class.php

示例2: getRelatedClass

 public static function getRelatedClass($class, $middleClass)
 {
     $column = self::getRelatedColumn($class, $middleClass);
     // we must load all map builder classes
     $classes = sfFinder::type('file')->ignore_version_control()->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
     foreach ($classes as $class) {
         $class_map_builder = basename($class, '.php');
         $map = new $class_map_builder();
         $map->doBuild();
     }
     $tableMap = call_user_func(array($middleClass . 'Peer', 'getTableMap'));
     return $tableMap->getDatabaseMap()->getTable($column->getRelatedTableName())->getPhpName();
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:13,代码来源:sfPropelManyToMany.class.php

示例3: dumpData

 /**
  * Dumps data to fixture from one or more tables.
  *
  * @param string directory or file to dump to
  * @param mixed  name or names of tables to dump (or all to dump all tables)
  * @param string connection name
  */
 public function dumpData($directory_or_file = null, $tables = 'all', $connectionName = 'propel')
 {
     $sameFile = true;
     if (is_dir($directory_or_file)) {
         // multi files
         $sameFile = false;
     } else {
         // same file
         // delete file
     }
     $this->con = Propel::getConnection($connectionName);
     // get tables
     if ('all' === $tables || is_null($tables)) {
         // load all map builder classes
         $files = sfFinder::type('file')->ignore_version_control()->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
         foreach ($files as $file) {
             $mapBuilderClass = basename($file, '.php');
             $map = new $mapBuilderClass();
             $map->doBuild();
         }
         $dbMap = Propel::getDatabaseMap($connectionName);
         $tables = array();
         foreach ($dbMap->getTables() as $table) {
             $tables[] = $table->getPhpName();
         }
     } else {
         if (!is_array($tables)) {
             $tables = array($tables);
         }
     }
     $dumpData = array();
     // load map classes
     array_walk($tables, array($this, 'loadMapBuilder'));
     //$tables = $this->fixOrderingOfForeignKeyData($tables);
     foreach ($tables as $tableName) {
         $tableMap = $this->maps[$tableName]->getDatabaseMap()->getTable(constant($tableName . 'Peer::TABLE_NAME'));
         $hasParent = false;
         $haveParents = false;
         $fixColumn = null;
         foreach ($tableMap->getColumns() as $column) {
             $col = strtolower($column->getColumnName());
             if ($column->isForeignKey()) {
                 $relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName());
                 if ($tableName === $relatedTable->getPhpName()) {
                     if ($hasParent) {
                         $haveParents = true;
                     } else {
                         $fixColumn = $column;
                         $hasParent = true;
                     }
                 }
             }
         }
         if ($haveParents) {
             // unable to dump tables having multi-recursive references
             continue;
         }
         // get db info
         $resultsSets = array();
         if ($hasParent) {
             $resultsSets = $this->fixOrderingOfForeignKeyDataInSameTable($resultsSets, $tableName, $fixColumn);
         } else {
             $resultsSets[] = $this->con->executeQuery('SELECT * FROM ' . constant($tableName . 'Peer::TABLE_NAME'));
         }
         foreach ($resultsSets as $rs) {
             if ($rs->getRecordCount() > 0 && !isset($dumpData[$tableName])) {
                 $dumpData[$tableName] = array();
             }
             while ($rs->next()) {
                 $pk = $tableName;
                 $values = array();
                 $primaryKeys = array();
                 $foreignKeys = array();
                 foreach ($tableMap->getColumns() as $column) {
                     $col = strtolower($column->getColumnName());
                     $isPrimaryKey = $column->isPrimaryKey();
                     if (is_null($rs->get($col))) {
                         continue;
                     }
                     if ($isPrimaryKey) {
                         $value = $rs->get($col);
                         $pk .= '_' . $value;
                         $primaryKeys[$col] = $value;
                     }
                     if ($column->isForeignKey()) {
                         $relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName());
                         if ($isPrimaryKey) {
                             $foreignKeys[$col] = $rs->get($col);
                             $primaryKeys[$col] = $relatedTable->getPhpName() . '_' . $rs->get($col);
                         } else {
                             $values[$col] = $relatedTable->getPhpName() . '_' . $rs->get($col);
                         }
                     } elseif (!$isPrimaryKey || $isPrimaryKey && !$tableMap->isUseIdGenerator()) {
//.........这里部分代码省略.........
开发者ID:jonphipps,项目名称:Metadata-Registry,代码行数:101,代码来源:sfPropelData.class.php

示例4: dumpData

 /**
  * Dumps data to fixture from one or more tables.
  *
  * @param string directory or file to dump to
  * @param mixed  name or names of tables to dump (or all to dump all tables)
  * @param string connection name
  */
 public function dumpData($directory_or_file = null, $tables = 'all', $connectionName = 'propel')
 {
     $sameFile = true;
     if (is_dir($directory_or_file)) {
         // multi files
         $sameFile = false;
     } else {
         // same file
         // delete file
     }
     $this->con = Propel::getConnection($connectionName);
     // get tables
     if ('all' === $tables || is_null($tables)) {
         // load all map builder classes
         $files = sfFinder::type('file')->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
         foreach ($files as $file) {
             $mapBuilderClass = basename($file, '.php');
             $map = new $mapBuilderClass();
             $map->doBuild();
         }
         $dbMap = Propel::getDatabaseMap($connectionName);
         $tables = array();
         foreach ($dbMap->getTables() as $table) {
             $tables[] = $table->getPhpName();
         }
     } else {
         if (!is_array($tables)) {
             $tables = array($tables);
         }
     }
     $dumpData = array();
     // load map classes
     array_walk($tables, array($this, 'loadMapBuilder'));
     $tables = $this->fixOrderingOfForeignKeyData($tables);
     foreach ($tables as $tableName) {
         $tableMap = $this->maps[$tableName]->getDatabaseMap()->getTable(constant($tableName . 'Peer::TABLE_NAME'));
         // get db info
         $rs = $this->con->executeQuery('SELECT * FROM ' . constant($tableName . 'Peer::TABLE_NAME'));
         while ($rs->next()) {
             $pk = $tableName;
             $values = array();
             foreach ($tableMap->getColumns() as $column) {
                 $col = strtolower($column->getColumnName());
                 if ($column->isPrimaryKey()) {
                     $pk .= '_' . $rs->get($col);
                 } else {
                     if ($column->isForeignKey()) {
                         $relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName());
                         $values[$col] = $relatedTable->getPhpName() . '_' . $rs->get($col);
                     } else {
                         $values[$col] = $rs->get($col);
                     }
                 }
             }
             if (!isset($dumpData[$tableName])) {
                 $dumpData[$tableName] = array();
             }
             $dumpData[$tableName][$pk] = $values;
         }
     }
     // save to file(s)
     if ($sameFile) {
         file_put_contents($directory_or_file, Spyc::YAMLDump($dumpData));
     } else {
         $i = 0;
         foreach ($tables as $tableName) {
             if (!isset($dumpData[$tableName])) {
                 continue;
             }
             file_put_contents(sprintf("%s/%03d-%s.yml", $directory_or_file, ++$i, $tableName), Spyc::YAMLDump(array($tableName => $dumpData[$tableName])));
         }
     }
 }
开发者ID:taryono,项目名称:school,代码行数:80,代码来源:sfPropelData.class.php


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