Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * 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);
 }