Esempio n. 1
0
 public function bake($name, $data = array())
 {
     if ($name instanceof Model) {
         $object = new Model(array('name' => $name->name));
         $fields = $object->schema();
         $data['fields'] = $fields;
     } else {
         //Changed By Dkmadmin
         $object = new Model(array('name' => $name));
         $fields = $object->schema();
         $data['fields'] = $fields;
     }
     return parent::bake($name, $data);
 }
 /**
  * Overrides ModelTask::bake()
  *
  * Calls ModelTask::bake() with no validation, which creates the baked model
  * file and then gets the contents, inserts the validation property, generated
  * by ModelFullValidateTask::bakeValidation() method after the name property
  * and writes the new contents back to the file.
  *
  * It's a filthy hack, but the alternative is copying the entire 170 line
  * ModelTask::bake() method into ModelFullValidateTask and replacing a small
  * portion of it with the new code.
  *
  * @param mixed $name Model name or object
  * @param mixed $associations if array and $name is not an object assume Model associations array otherwise boolean interactive
  * @param array $validate Validation rules
  * @param string $primaryKey Primary key to use
  * @param string $useTable Table to use
  * @param string $useDbConfig Database configuration setting to use
  * @access private
  */
 function bake($name, $associations = array(), $validate = array(), $primaryKey = 'id', $useTable = null, $useDbConfig = 'default')
 {
     // Call bake method on ModelTask but with no validation
     $result = parent::bake($name, $associations, array(), $primaryKey, $useTable, $useDbConfig);
     if (!$result) {
         return $result;
     }
     // Get the contents of the baked file
     $filename = $this->path . Inflector::underscore($name) . '.php';
     $contents = file_get_contents($filename);
     // The string after which we want to insert the validation property
     $addValidationAfterString = "var \$name = '{$name}';";
     // The position of the above string in the file contents
     $addValidationAfterPos = strpos($contents, $addValidationAfterString);
     // If the string was found
     if ($addValidationAfterPos !== false) {
         // Bake the new validation in full format
         $validation = "\n\n" . $this->bakeValidation($validate);
         // Add it into the contents
         $contents = substr_replace($contents, $validation, $addValidationAfterPos + strlen($addValidationAfterString), 0);
         // Write the contents back to the file
         file_put_contents($filename, $contents);
     }
     // Return the result of the parent::bake() method
     return $result;
 }