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


PHP Column::getPhpDefaultValue方法代码示例

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


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

示例1: getDefaultValueString

 /**
  * Returns the type-casted and stringified default value for the specified Column.
  * This only works for scalar default values currently.
  * @return     string The default value or 'NULL' if there is none.
  */
 protected function getDefaultValueString(Column $col)
 {
     $defaultValue = var_export(null, true);
     $val = $col->getPhpDefaultValue();
     if ($val === null) {
         return $defaultValue;
     }
     if ($col->isTemporalType()) {
         $fmt = $this->getTemporalFormatter($col);
         try {
             if (!($this->getPlatform() instanceof MysqlPlatform && ($val === '0000-00-00 00:00:00' || $val === '0000-00-00'))) {
                 // while technically this is not a default value of NULL,
                 // this seems to be closest in meaning.
                 $defDt = new DateTime($val);
                 $defaultValue = var_export($defDt->format($fmt), true);
             }
         } catch (Exception $x) {
             // prevent endless loop when timezone is undefined
             date_default_timezone_set('America/Los_Angeles');
             throw new EngineException(sprintf('Unable to parse default temporal value "%s" for column "%s"', $col->getDefaultValueString(), $col->getFullyQualifiedName()), $x);
         }
     } elseif ($col->isEnumType()) {
         $valueSet = $col->getValueSet();
         if (!in_array($val, $valueSet)) {
             throw new EngineException(sprintf('Default Value "%s" is not among the enumerated values', $val));
         }
         $defaultValue = array_search($val, $valueSet);
     } else {
         if ($col->isPhpPrimitiveType()) {
             settype($val, $col->getPhpType());
             $defaultValue = var_export($val, true);
         } elseif ($col->isPhpObjectType()) {
             $defaultValue = 'new ' . $col->getPhpType() . '(' . var_export($val, true) . ')';
         } else {
             throw new EngineException("Cannot get default value string for " . $col->getFullyQualifiedName());
         }
     }
     return $defaultValue;
 }
开发者ID:halfer,项目名称:Meshing,代码行数:44,代码来源:PHP5ObjectBuilder.php

示例2: addDefaultMutator

 /**
  * Adds setter method for "normal" columns.
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        parent::addColumnMutators()
  */
 protected function addDefaultMutator(&$script, Column $col)
 {
     $clo = strtolower($col->getName());
     // FIXME: refactor this
     $defaultValue = null;
     if (($val = $col->getPhpDefaultValue()) !== null) {
         settype($val, $col->getPhpNative());
         $defaultValue = var_export($val, true);
     }
     $this->addMutatorOpen($script, $col);
     // Perform some smart checking here to handle possible type discrepancies
     // between the passed-in value and the value from the DB
     if ($col->getPhpNative() === "int") {
         $script .= "\n\t\t// Since the native PHP type for this column is integer,\n\t\t// we will cast the input value to an int (if it is not).\n\t\tif (\$v !== null && !is_int(\$v) && is_numeric(\$v)) {\n\t\t\t\$v = (int) \$v;\n\t\t}\n";
     } elseif ($col->getPhpNative() === "string") {
         $script .= "\n\t\t// Since the native PHP type for this column is string,\n\t\t// we will cast the input to a string (if it is not).\n\t\tif (\$v !== null && !is_string(\$v)) {\n\t\t\t\$v = (string) \$v;\n\t\t}\n";
     }
     $script .= "\n\t\tif (\$this->{$clo} !== \$v";
     if ($defaultValue !== null) {
         $script .= " || \$v === {$defaultValue}";
     }
     $script .= ") {\n\t\t\t\$this->{$clo} = \$v;\n\t\t\t\$this->modifiedColumns[] = " . $this->getColumnConstant($col) . ";\n\t\t}\n";
     $this->addMutatorClose($script, $col);
 }
开发者ID:taryono,项目名称:school,代码行数:30,代码来源:PHP5BasicObjectBuilder.php

示例3: getDefaultValueString

 /**
  * Returns the type-casted and stringified default value for the specified Column.
  * This only works for scalar default values currently.
  * @return     string The default value or 'NULL' if there is none.
  */
 protected function getDefaultValueString(Column $col)
 {
     $defaultValue = var_export(null, true);
     if (($val = $col->getPhpDefaultValue()) !== null) {
         if ($col->isTemporalType()) {
             $fmt = $this->getTemporalFormatter($col);
             try {
                 if (!($this->getPlatform() instanceof MysqlPlatform && ($val === '0000-00-00 00:00:00' || $val === '0000-00-00'))) {
                     // while technically this is not a default value of NULL,
                     // this seems to be closest in meaning.
                     $defDt = new DateTime($val);
                     $defaultValue = var_export($defDt->format($fmt), true);
                 }
             } catch (Exception $x) {
                 throw new EngineException("Unable to parse default temporal value for " . $col->getFullyQualifiedName() . ": " . $this->getDefaultValueString($col), $x);
             }
         } else {
             if ($col->isPhpPrimitiveType()) {
                 settype($val, $col->getPhpType());
                 $defaultValue = var_export($val, true);
             } elseif ($col->isPhpObjectType()) {
                 $defaultValue = 'new ' . $col->getPhpType() . '(' . var_export($val, true) . ')';
             } else {
                 throw new EngineException("Cannot get default value string for " . $col->getFullyQualifiedName());
             }
         }
     }
     return $defaultValue;
 }
开发者ID:nhemsley,项目名称:propel,代码行数:34,代码来源:PHP5ObjectBuilder.php

示例4: addDefaultMutator

 /**
  * Adds setter method for "normal" columns.
  * @param string &$script The script will be modified in this method.
  * @param Column $col The current column.
  * @see parent::addColumnMutators()
  */
 protected function addDefaultMutator(&$script, Column $col)
 {
     $clo = strtolower($col->getName());
     // FIXME: refactor this
     $defaultValue = null;
     if (($val = $col->getPhpDefaultValue()) !== null) {
         settype($val, $col->getPhpNative());
         $defaultValue = var_export($val, true);
     }
     $this->addMutatorOpen($script, $col);
     $script .= "\n\t\tif (\$this->{$clo} !== \$v";
     if ($defaultValue !== null) {
         $script .= " || \$v === {$defaultValue}";
     }
     $script .= ") {\n\t\t\t\$this->{$clo} = \$v;\n\t\t\t\$this->modifiedColumns[] = " . $this->getColumnConstant($col) . ";\n\t\t}\n";
     $this->addMutatorClose($script, $col);
 }
开发者ID:DBezemer,项目名称:server,代码行数:23,代码来源:PHP5BasicObjectBuilder.php


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