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


PHP OMBuilder类代码示例

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


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

示例1: build

 /**
  * Uses a builder class to create the output class.
  * This method assumes that the DataModelBuilder class has been initialized with the build properties.
  *
  * @param OMBuilder $builder
  * @param boolean   $overwrite Whether to overwrite existing files with te new ones (default is YES).
  *
  * @todo       -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).
  * @return int
  */
 protected function build(OMBuilder $builder, $overwrite = true)
 {
     $path = $builder->getClassFilePath();
     $this->ensureDirExists(dirname($path));
     $_f = new PhingFile($this->getOutputDirectory(), $path);
     // skip files already created once
     if ($_f->exists() && !$overwrite) {
         $this->log("\t-> (exists) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
         return 0;
     }
     $script = $builder->build();
     foreach ($builder->getWarnings() as $warning) {
         $this->log($warning, Project::MSG_WARN);
     }
     // skip unchanged files
     if ($_f->exists() && $script == $_f->contents()) {
         $this->log("\t-> (unchanged) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
         return 0;
     }
     // write / overwrite new / changed files
     $action = $_f->exists() ? 'Updating' : 'Creating';
     $this->log(sprintf("\t-> %s %s (table: %s, builder: %s)", $action, $builder->getClassFilePath(), $builder->getTable()->getName(), get_class($builder)));
     file_put_contents($_f->getAbsolutePath(), $script);
     return 1;
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:35,代码来源:PropelOMTask.php

示例2: inject

 /**
  * Returns file to inject, or false if none specified.
  *
  * @param OMBuilder $builder
  * @param string $type
  * @return string|bool
  */
 public function inject($builder, $type)
 {
     if ($file = $this->getParameter($type)) {
         $path = $builder->getBuildProperty('projectDir') . DIRECTORY_SEPARATOR . $file;
         if (!file_exists($path)) {
             throw new Exception('Inject-file doesnt exist: ' . $path);
         }
         return file_get_contents($path);
     }
     return false;
 }
开发者ID:varvanin,项目名称:currycms,代码行数:18,代码来源:InjectFile.php

示例3: build

 /**
  * Uses a builder class to create the output class.
  * This method assumes that the DataModelBuilder class has been initialized with the build properties.
  * @param      OMBuilder $builder
  * @param      boolean $overwrite Whether to overwrite existing files with te new ones (default is YES).
  * @todo       -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).
  */
 protected function build(OMBuilder $builder, $overwrite = true)
 {
     $path = $builder->getClassFilePath();
     $this->ensureDirExists(dirname($path));
     $_f = new PhingFile($this->getOutputDirectory(), $path);
     if ($overwrite || !$_f->exists()) {
         $this->log("\t\t-> " . $builder->getClassname() . " [builder: " . get_class($builder) . "]");
         $script = $builder->build();
         file_put_contents($_f->getAbsolutePath(), $script);
         foreach ($builder->getWarnings() as $warning) {
             $this->log($warning, Project::MSG_WARN);
         }
     } else {
         $this->log("\t\t-> (exists) " . $builder->getClassname());
     }
 }
开发者ID:nhemsley,项目名称:propel,代码行数:23,代码来源:PropelOMTask.php

示例4: addDoSelectWithI18n

 protected function addDoSelectWithI18n(&$script)
 {
     $table = $this->getTable();
     $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table);
     $className = $table->getPhpName();
     $pks = $table->getPrimaryKey();
     $pk = PeerBuilder::getColumnName($pks[0], $className);
     // get i18n table name and culture column name
     foreach ($table->getReferrers() as $fk) {
         $tblFK = $fk->getTable();
         if ($tblFK->getName() == $table->getAttribute('i18nTable')) {
             $i18nClassName = $tblFK->getPhpName();
             // FIXME
             $i18nPeerClassName = $i18nClassName . 'Peer';
             $i18nTable = $table->getDatabase()->getTable($tblFK->getName());
             $i18nTableObjectBuilder = OMBuilder::getNewObjectBuilder($i18nTable);
             $i18nTablePeerBuilder = OMBuilder::getNewPeerBuilder($i18nTable);
             $i18nPks = $i18nTable->getPrimaryKey();
             $i18nPk = PeerBuilder::getColumnName($i18nPks[0], $i18nClassName);
             $culturePhpName = '';
             $cultureColumnName = '';
             foreach ($tblFK->getColumns() as $col) {
                 if ("true" === strtolower($col->getAttribute('isCulture'))) {
                     $culturePhpName = $col->getPhpName();
                     $cultureColumnName = PeerBuilder::getColumnName($col, $i18nClassName);
                 }
             }
         }
     }
     $script .= "\n\n  /**\n   * Selects a collection of {$className} objects pre-filled with their i18n objects.\n   *\n   * @return array Array of {$className} objects.\n   * @throws PropelException Any exceptions caught during processing will be\n   *     rethrown wrapped into a PropelException.\n   */\n  public static function doSelectWithI18n(Criteria \$c, \$culture = null, \$con = null)\n  {\n    if (\$culture === null)\n    {\n      \$culture = sfPropel::getDefaultCulture();\n    }\n";
     if (DataModelBuilder::getBuildProperty('builderAddBehaviors')) {
         $script .= "\n\n    foreach (sfMixer::getCallables('{$this->getClassname()}:doSelectJoin:doSelectJoin') as \$callable)\n    {\n      call_user_func(\$callable, '{$this->getClassname()}', \$c, \$con);\n    }\n\n";
     }
     $script .= "\n    // Set the correct dbName if it has not been overridden\n    if (\$c->getDbName() == Propel::getDefaultDB())\n    {\n      \$c->setDbName(self::DATABASE_NAME);\n    }\n\n    " . $this->getPeerClassname() . "::addSelectColumns(\$c);\n    \$startcol = (" . $this->getPeerClassname() . "::NUM_COLUMNS - " . $this->getPeerClassname() . "::NUM_LAZY_LOAD_COLUMNS) + 1;\n\n    " . $i18nPeerClassName . "::addSelectColumns(\$c);\n\n    \$c->addJoin(" . $pk . ", " . $i18nPk . ");\n    \$c->add(" . $cultureColumnName . ", \$culture);\n\n    \$rs = " . $this->basePeerClassname . "::doSelect(\$c, \$con);\n    \$results = array();\n\n    while(\$rs->next()) {\n";
     if ($table->getChildrenColumn()) {
         $script .= "\n      \$omClass = " . $this->getPeerClassname() . "::getOMClass(\$rs, 1);\n";
     } else {
         $script .= "\n      \$omClass = " . $this->getPeerClassname() . "::getOMClass();\n";
     }
     $script .= "\n      \$cls = Propel::import(\$omClass);\n      \$obj1 = new \$cls();\n      \$obj1->hydrate(\$rs);\n      \$obj1->setCulture(\$culture);\n";
     //            if ($i18nTable->getChildrenColumn()) {
     $script .= "\n      \$omClass = " . $i18nTablePeerBuilder->getPeerClassname() . "::getOMClass(\$rs, \$startcol);\n";
     //            } else {
     //              $script .= "
     //      \$omClass = ".$i18nTablePeerBuilder->getPeerClassname()."::getOMClass();
     //";
     //            }
     $script .= "\n      \$cls = Propel::import(\$omClass);\n      \$obj2 = new \$cls();\n      \$obj2->hydrate(\$rs, \$startcol);\n\n      \$obj1->set" . $i18nClassName . "ForCulture(\$obj2, \$culture);\n      \$obj2->set" . $className . "(\$obj1);\n\n      \$results[] = \$obj1;\n    }\n    return \$results;\n  }\n";
 }
开发者ID:sgrove,项目名称:cothinker,代码行数:49,代码来源:SfPeerBuilder.php

示例5: addDoOnDeleteSetNull

 /**
  * Adds the doOnDeleteSetNull() method, which provides ON DELETE SET NULL emulation.
  * @param      string &$script The script will be modified in this method.
  */
 protected function addDoOnDeleteSetNull(&$script)
 {
     $table = $this->getTable();
     $script .= "\n    /**\n     * This is a method for emulating ON DELETE SET NULL DBs that don't support this\n     * feature (like MySQL or SQLite).\n     *\n     * This method is not very speedy because it must perform a query first to get\n     * the implicated records and then perform the deletes by calling those Peer classes.\n     *\n     * This method should be used within a transaction if possible.\n     *\n     * @param      Criteria \$criteria\n     * @param      Connection \$con\n     * @return     void\n     */\n    protected static function doOnDeleteSetNull(Criteria \$criteria, Connection \$con)\n    {\n\n        // first find the objects that are implicated by the \$criteria\n        \$objects = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);\n        foreach(\$objects as \$obj) {\n";
     // This logic is almost exactly the same as that in doOnDeleteCascade()
     // it may make sense to refactor this, provided that thigns don't
     // get too complicated.
     foreach ($table->getReferrers() as $fk) {
         // $fk is the foreign key in the other table, so localTableName will
         // actually be the table name of other table
         $tblFK = $fk->getTable();
         $refTablePeerBuilder = OMBuilder::getNewPeerBuilder($tblFK);
         if (!$tblFK->isForReferenceOnly()) {
             // we can't perform operations on tables that are
             // not within the schema (i.e. that we have no map for, etc.)
             $fkClassName = $tblFK->getPhpName();
             // i'm not sure whether we can allow delete setnull for foreign keys
             // within the same table?  perhaps we can?
             if ($fk->getOnDelete() == ForeignKey::SETNULL && $fk->getTable()->getName() != $table->getName()) {
                 // backwards on purpose
                 $columnNamesF = $fk->getLocalColumns();
                 $columnNamesL = $fk->getForeignColumns();
                 // should be same num as foreign
                 $script .= "\n            // set fkey col in related {$fkClassName} rows to NULL\n            \$selectCriteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);\n            \$updateValues = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
                 for ($x = 0, $xlen = count($columnNamesF); $x < $xlen; $x++) {
                     $columnFK = $tblFK->getColumn($columnNamesF[$x]);
                     $columnL = $table->getColumn($columnNamesL[$x]);
                     $script .= "\n            \$selectCriteria->add(" . $refTablePeerBuilder->getColumnConstant($columnFK) . ", \$obj->get" . $columnL->getPhpName() . "());\n            \$updateValues->add(" . $refTablePeerBuilder->getColumnConstant($columnFK) . ", null);\n";
                 }
                 $script .= "\n            {$this->basePeerClassname}::doUpdate(\$selectCriteria, \$updateValues, \$con); // use BasePeer because generated Peer doUpdate() methods only update using pkey\n";
             }
             // if setnull && fkey table name != curr table name
         }
         // if not for ref only
     }
     // foreach foreign keys
     $script .= "\n        }\n    }\n";
 }
开发者ID:bqevin,项目名称:processmaker,代码行数:42,代码来源:PHP5BasicPeerBuilder.php

示例6: getColumnConstant

 /**
  * Return the constant for a given column.
  *
  * @param string    $columnName
  * @param OMBuilder $builder
  *
  * @return string
  */
 protected function getColumnConstant($columnName, OMBuilder $builder)
 {
     return $builder->getColumnConstant($this->getColumnForParameter($columnName));
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:12,代码来源:TimestampableBehavior.php

示例7: addDoSelectWithI18n

  protected function addDoSelectWithI18n(&$script)
  {
    $table = $this->getTable();
    $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table);
    $className = $table->getPhpName();
    $pks = $table->getPrimaryKey();
    $pk = PeerBuilder::getColumnName($pks[0], $className);

    // get i18n table name and culture column name
    foreach ($table->getReferrers() as $fk)
    {
      $tblFK = $fk->getTable();
      if ($tblFK->getName() == $table->getAttribute('i18nTable'))
      {
        $i18nClassName = $tblFK->getPhpName();

        // FIXME
        $i18nPeerClassName = $i18nClassName.'Peer';

        $i18nTable = $table->getDatabase()->getTable($tblFK->getName());
        $i18nTableObjectBuilder = OMBuilder::getNewObjectBuilder($i18nTable);
        $i18nTablePeerBuilder = OMBuilder::getNewPeerBuilder($i18nTable);
        $i18nPks = $i18nTable->getPrimaryKey();
        $i18nPk = PeerBuilder::getColumnName($i18nPks[0], $i18nClassName);

        $culturePhpName = '';
        $cultureColumnName = '';
        foreach ($tblFK->getColumns() as $col)
        {
          if (('true' == trim(strtolower($col->getAttribute('isCulture')))))
          {
            $culturePhpName = $col->getPhpName();
            $cultureColumnName = PeerBuilder::getColumnName($col, $i18nClassName);
          }
        }
      }
    }

    $script .= "

  /**
   * Selects a collection of $className objects pre-filled with their i18n objects.
   *
   * @return array Array of $className objects.
   * @throws PropelException Any exceptions caught during processing will be
   *     rethrown wrapped into a PropelException.
   */
  public static function doSelectWithI18n(Criteria \$c, \$culture = null, PropelPDO \$con = null)
  {
    // we're going to modify criteria, so copy it first
    \$c = clone \$c;
    if (\$culture === null)
    {
      \$culture = sfPropel::getDefaultCulture();
    }
";

    if ($this->getBuildProperty('builderAddBehaviors'))
    {
      $script .= "

    foreach (sfMixer::getCallables('{$this->getClassname()}:doSelectJoin:doSelectJoin') as \$callable)
    {
      call_user_func(\$callable, '{$this->getClassname()}', \$c, \$con);
    }

";
    }

    $script .= "
    // Set the correct dbName if it has not been overridden
    if (\$c->getDbName() == Propel::getDefaultDB())
    {
      \$c->setDbName(self::DATABASE_NAME);
    }

    ".$this->getPeerClassname()."::addSelectColumns(\$c);
    \$startcol = (".$this->getPeerClassname()."::NUM_COLUMNS - ".$this->getPeerClassname()."::NUM_LAZY_LOAD_COLUMNS);

    ".$i18nPeerClassName."::addSelectColumns(\$c);

    \$c->addJoin(".$pk.", ".$i18nPk.");
    \$c->add(".$cultureColumnName.", \$culture);

    \$stmt = ".$this->basePeerClassname."::doSelect(\$c, \$con);
    \$results = array();

    while(\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
";
            if ($table->getChildrenColumn()) {
              $script .= "
      \$omClass = ".$this->getPeerClassname()."::getOMClass(\$row, \$startcol);
";
            } else {
              $script .= "
      \$omClass = ".$this->getPeerClassname()."::getOMClass();
";
            }
            $script .= "
      \$cls = Propel::importClass(\$omClass);
//.........这里部分代码省略.........
开发者ID:nationalfield,项目名称:symfony,代码行数:101,代码来源:SfPeerBuilder.php

示例8: addReorder

 protected function addReorder(&$script)
 {
     $this->builder->declareClasses('Propel');
     $peerClassname = $this->peerClassname;
     $columnGetter = 'get' . $this->behavior->getColumnForParameter('rank_column')->getPhpName();
     $columnSetter = 'set' . $this->behavior->getColumnForParameter('rank_column')->getPhpName();
     $script .= "\n/**\n * Reorder a set of sortable objects based on a list of id/position\n * Beware that there is no check made on the positions passed\n * So incoherent positions will result in an incoherent list\n *\n * @param     array     \$order id => rank pairs\n * @param     PropelPDO \$con   optional connection\n * @return    boolean true if the reordering took place, false if a database problem prevented it\n * @throws Exception\n */\npublic function reorder(array \$order, PropelPDO \$con = null)\n{\n    if (\$con === null) {\n        \$con = Propel::getConnection({$peerClassname}::DATABASE_NAME);\n    }\n\n    \$con->beginTransaction();\n    try {\n        \$ids = array_keys(\$order);\n        \$objects = \$this->findPks(\$ids, \$con);\n        foreach (\$objects as \$object) {\n            \$pk = \$object->getPrimaryKey();\n            if (\$object->{$columnGetter}() != \$order[\$pk]) {\n                \$object->{$columnSetter}(\$order[\$pk]);\n                \$object->save(\$con);\n            }\n        }\n        \$con->commit();\n\n        return true;\n    } catch (Exception \$e) {\n        \$con->rollback();\n        throw \$e;\n    }\n}\n";
 }
开发者ID:Bonscho,项目名称:Propel,代码行数:8,代码来源:SortableBehaviorQueryBuilderModifier.php

示例9: __construct

 /**
  * Constructs a new PeerBuilder subclass.
  */
 public function __construct(Table $table)
 {
     parent::__construct($table);
     $this->basePeerClassname = $this->basePeerClass = $this->getBasePeer($table);
     $pos = strrpos($this->basePeerClassname, '.');
     if ($pos !== false) {
         $this->basePeerClassname = substr($this->basePeerClassname, $pos + 1);
     }
 }
开发者ID:nhemsley,项目名称:propel,代码行数:12,代码来源:PeerBuilder.php

示例10: getNamespace

 public function getNamespace()
 {
     if ($namespace = parent::getNamespace()) {
         if ($this->getGeneratorConfig() && ($omns = $this->getGeneratorConfig()->getBuildProperty('namespaceOm'))) {
             return $namespace . '\\' . $omns;
         } else {
             return $namespace;
         }
     }
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:10,代码来源:QueryInheritanceBuilder.php

示例11: addDeleteFromCache

    /**
     * @param string $script
     */
    protected function addDeleteFromCache(&$script)
    {
        $peerClassName = $this->builder->getStubPeerBuilder()->getClassname();
        $script .= '
/**
 * @return boolean            success or failure
 */
public function deleteFromCache()
{
    return ' . $peerClassName . '::cacheDelete($this->getCacheKey());
}
        ';
    }
开发者ID:stevleibelt,项目名称:PropelDataCacheBehavior,代码行数:16,代码来源:DataCacheBehaviorQueryBuilderModifier.php

示例12: addShiftRank

 protected function addShiftRank(&$script)
 {
     $useScope = $this->behavior->useScope();
     $peerClassname = $this->peerClassname;
     $script .= "\n/**\n * Adds \$delta to all Rank values that are >= \$first and <= \$last.\n * '\$delta' can also be negative.\n *\n * @param      int \$delta Value to be shifted by, can be negative\n * @param      int \$first First node to be shifted\n * @param      int \$last  Last node to be shifted";
     if ($useScope) {
         $script .= "\n * @param      mixed \$scope Scope to use for the shift. Scalar value (single scope) or array";
     }
     $script .= "\n * @param      PropelPDO \$con Connection to use.\n */\npublic static function shiftRank(\$delta, \$first = null, \$last = null, " . ($useScope ? "\$scope = null, " : "") . "PropelPDO \$con = null)\n{\n    if (\$con === null) {\n        \$con = Propel::getConnection({$peerClassname}::DATABASE_NAME, Propel::CONNECTION_WRITE);\n    }\n\n    \$whereCriteria = {$this->queryClassname}::create();\n    if (null !== \$first) {\n        \$whereCriteria->add({$peerClassname}::RANK_COL, \$first, Criteria::GREATER_EQUAL);\n    }\n    if (null !== \$last) {\n        \$whereCriteria->addAnd({$peerClassname}::RANK_COL, \$last, Criteria::LESS_EQUAL);\n    }";
     if ($useScope) {
         $script .= "\n    {$this->peerClassname}::sortableApplyScopeCriteria(\$whereCriteria, \$scope);";
     }
     $script .= "\n\n    \$valuesCriteria = new Criteria({$peerClassname}::DATABASE_NAME);\n    \$valuesCriteria->add({$peerClassname}::RANK_COL, array('raw' => {$peerClassname}::RANK_COL . ' + ?', 'value' => \$delta), Criteria::CUSTOM_EQUAL);\n\n    {$this->builder->getPeerBuilder()->getBasePeerClassname()}::doUpdate(\$whereCriteria, \$valuesCriteria, \$con);\n    {$peerClassname}::clearInstancePool();\n}\n";
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:14,代码来源:SortableBehaviorPeerBuilderModifier.php

示例13: build

 public function build()
 {
     $phpDir = $this->getBuildProperty('phpDir');
     $fassadePath = $phpDir . DIRECTORY_SEPARATOR . $this->getClassFilePath();
     if (in_array($this->getBuildProperty('behaviorProviderCachefile'), array('true', 'on', 'yes', '1'))) {
         $outputDir = $this->getBuildProperty('outputDir');
         $cacheFile = $outputDir . DIRECTORY_SEPARATOR . 'providerCache.json';
         $className = $this->getClassname();
         $package = $this->getPackage();
         $nameSpace = $this->getNamespace();
         //            Check if a special constant has been defined - if not, this is the first run of
         //            and Provider build, so we need to clear the cache.
         if (!defined('BEHAVIOR_PROVIDER_FASSADE_CACHE_CLEARED') || true != BEHAVIOR_PROVIDER_FASSADE_CACHE_CLEARED) {
             if (!file_exists($outputDir)) {
                 mkdir($outputDir);
             }
             if (file_exists($cacheFile)) {
                 unlink($cacheFile);
             }
             touch($cacheFile);
             define('BEHAVIOR_PROVIDER_FASSADE_CACHE_CLEARED', true);
         }
         $cache = (array) json_decode(file_get_contents($cacheFile), true);
         if (JSON_ERROR_NONE == json_last_error()) {
             $cache[] = array('package' => $package, 'namespace' => $nameSpace, 'modelName' => str_replace('Provider', '', $className), 'providerName' => $className);
             file_put_contents($cacheFile, json_encode($cache));
         }
     }
     if (file_exists($fassadePath)) {
         // Fassade already exists.
         // It is not possible to just stop the process here and continue with the next file,
         // so we return the source string just as it is in the current file, so it does not get overwritten
         $sourceString = file_get_contents($fassadePath);
     } else {
         // Fassade does not exist yet, so we build it
         $sourceString = parent::build();
     }
     return $sourceString;
 }
开发者ID:emiliomg,项目名称:PropelProviderBehavior,代码行数:39,代码来源:ProviderFassadeBehaviorBuilder.php

示例14: getRefRelatedBySuffix

 public static function getRefRelatedBySuffix(ForeignKey $fk)
 {
     return parent::getRefRelatedBySuffix($fk);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:4,代码来源:OMBuilderRelatedByTest.php

示例15: getPackage

 public function getPackage()
 {
     return parent::getPackage();
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:4,代码来源:AddClassBehaviorBuilder.php


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