Skip to content

Commit

Permalink
Fix #97, #98, 101, 102
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Mar 3, 2019
1 parent bf85e7f commit ab59405
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ Checkout our channel on <a href="https://www.youtube.com/channel/UCkEd0nOoRf3o0a
## Contribution
Do you like this project and want to contribute?
- Please start by *Staring* this package on GitHub.
- **HELP WANTED** Version `v2.3` needs to be documented before it can be released. If you are able to contribute, please read the <a href="https://github.com/CrestApps/laravel-code-generator/blob/v2.3/CHANGELOG.md">change-log</a> in <a href="https://github.com/CrestApps/laravel-code-generator/tree/v2.3">v2.3 branch</a> and document it in the <a href="https://github.com/CrestApps/crestapps-site">CrestApps-site</a> repository. For any help, my email can be found in the `composer.json` file, feel free to send me an email.
- Please start by ***Staring*** this package on GitHub.
- Sharing this projects with others is your way of saying keep improvements and new awesome feature coming.
- Report any bugs or send us any comments, idea, thought that you may have about this project as an issue on GitHub.

Expand Down
1 change: 0 additions & 1 deletion src/Support/FieldOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ protected function optimizeBoolean()
protected function optimizePrimaryKey()
{
if ($this->field->isPrimary()) {

$this->field->isNullable = false;

if ($this->meta == null) {
Expand Down
11 changes: 9 additions & 2 deletions src/Support/FieldTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,24 @@ public static function fromString($str, $localeGroup = 'generic', array $languag
if (str_contains($fieldName, ':')) {
// Handle the following format
// name:a;html-type:select;options:first|second|third|fourth
if (!str_is('*name*:*', $fieldName)) {
if (!Str::is('*name*:*', $fieldName)) {
throw new Exception('The "name" property was not provided and is required!');
}

$parts = Arr::fromString($fieldName, ';');

foreach ($parts as $part) {
if (!str_is('*:*', $part) || count($properties = Arr::fromString($part, ':')) < 2) {
if (!Str::is('*:*', $part) || count($properties = Arr::fromString($part, ':')) < 2) {
throw new Exception('Each provided property should use the following format "key:value"');
}
list($key, $value) = $properties;

if(Str::startsWith($key, 'is-')){
$field[$key] = Str::stringToBool($value);
} else {
$field[$key] = $value;
}

$field[$key] = $value;
if ($key == 'options') {
$options = Arr::fromString($value, '|');
Expand Down
17 changes: 16 additions & 1 deletion src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,22 @@ public static function trimStart($subject, $search)

return $subject;
}


/**
* Check a string for a positive keyword
*
* @param string $str
*
* @return array
*/
public static function stringToBool($str)
{
if (is_bool($str)) {
return $str;
}
return in_array(strtolower($str), ['true', 'yes', '1', 'valid', 'correct']);
}

/**
* Checks if a string matches at least one given pattern
*
Expand Down

0 comments on commit ab59405

Please sign in to comment.