Skip to content

Commit

Permalink
Require PHP7.2 and add simple method with generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Heng committed May 7, 2019
1 parent 69f2a45 commit fee08d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.2",
"amphp/mysql": "^1.1",
"fzaninotto/faker": "^1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Anonymizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected function getSelectData($table, $blueprint)
}
}

if($columns ?? false) {
if(!($columns ?? false)) {
$columns = implode(',', array_merge($blueprint->primary, array_column($blueprint->columns, 'name')));
}
$sql = "SELECT {$columns} FROM {$table}";
Expand Down
23 changes: 23 additions & 0 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,29 @@ public function replaceWith($callback)
return $this;
}

/**
* A simple method to set data with generator
*
* @param string $data_type
* @param boolean $is_unique
*
* @return void
*/
public function replaceWithGenerator($data_type, $is_unique = false)
{
if($is_unique) {
$closure = function ($generator) use($data_type) {
return $generator->unique()->$data_type;
};
} else {
$closure = function ($generator) use($data_type) {
return $generator->$data_type;
};
}

return $this->replaceWith($closure);
}

/**
* Save all columns that need to be synchronized..
*
Expand Down

0 comments on commit fee08d6

Please sign in to comment.